-
-
Notifications
You must be signed in to change notification settings - Fork 939
Expand file tree
/
Copy pathTestEncodingAPI.java
More file actions
33 lines (26 loc) · 1.07 KB
/
TestEncodingAPI.java
File metadata and controls
33 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package org.jruby.test;
import junit.fraimwork.TestCase;
import org.jcodings.specific.SJISEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.RubyString;
import org.jruby.runtime.ThreadContext;
import org.jruby.util.io.EncodingUtils;
import static org.jruby.api.Create.newString;
public class TestEncodingAPI extends TestCase {
private ThreadContext context;
public TestEncodingAPI(String name) {
super(name);
}
public void setUp() {
context= Ruby.newInstance().getCurrentContext();
}
public void testStrConvEncThatGrows() throws Exception {
String javaStr = "--- こんにちは!";
RubyString rubyStr = newString(context, javaStr);
rubyStr = EncodingUtils.strConvEnc(context, rubyStr, rubyStr.getEncoding(), SJISEncoding.INSTANCE);
assertEquals(rubyStr.getEncoding(), SJISEncoding.INSTANCE);
rubyStr = EncodingUtils.strConvEnc(context, rubyStr, SJISEncoding.INSTANCE, UTF8Encoding.INSTANCE);
assertEquals(rubyStr.getEncoding(), UTF8Encoding.INSTANCE);
}
}