01: package test.net.sourceforge.pmd.ast;
02:
03: import static org.junit.Assert.assertEquals;
04: import net.sourceforge.pmd.PMD;
05: import net.sourceforge.pmd.TargetJDK1_4;
06: import net.sourceforge.pmd.ast.ASTCompilationUnit;
07: import net.sourceforge.pmd.ast.ASTMethodDeclarator;
08:
09: import org.junit.Ignore;
10: import org.junit.Test;
11:
12: import java.io.ByteArrayInputStream;
13: import java.io.InputStreamReader;
14:
15: public class EncodingTest {
16:
17: @Ignore("FIXME")
18: @Test
19: public void testDecodingOfUTF8() throws Throwable {
20: //String platformEncoding = System.getProperty("file.encoding");
21: //String encoding = "ISO-8859-1";
22: String encoding = "UTF-8";
23:
24: String code = new String(TEST_UTF8.getBytes(), encoding);
25: InputStreamReader isr = new InputStreamReader(
26: new ByteArrayInputStream(code.getBytes()));
27: ASTCompilationUnit acu = new TargetJDK1_4().createParser(isr)
28: .CompilationUnit();
29: String methodName = acu.findChildrenOfType(
30: ASTMethodDeclarator.class).get(0).getImage();
31: assertEquals(new String("é".getBytes(), encoding), methodName);
32: }
33:
34: private static final String TEST_UTF8 = "class Foo {" + PMD.EOL
35: + " void é() {}" + PMD.EOL + " void fiddle() {}" + PMD.EOL
36: + "}";
37:
38: public static junit.framework.Test suite() {
39: return new junit.framework.JUnit4TestAdapter(EncodingTest.class);
40: }
41: }
|