1 17 18 package org.apache.tools.ant.util; 19 20 import junit.framework.Test; 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 28 public class DOMElementWriterTest extends TestCase { 29 30 private DOMElementWriter w = new DOMElementWriter(); 31 32 public DOMElementWriterTest(String name) { 33 super(name); 34 } 35 36 public void testIsReference() { 37 assertTrue("", w.isReference("")); 38 assertTrue(" ", w.isReference(" ")); 39 assertTrue(" ", w.isReference(" ")); 40 assertTrue("&#A0;", !w.isReference("&#A0;")); 41 assertTrue("20;", !w.isReference("20;")); 42 assertTrue("", !w.isReference("")); 43 assertTrue(""", w.isReference(""")); 44 assertTrue("'", w.isReference("'")); 45 assertTrue(">", w.isReference(">")); 46 assertTrue("<", w.isReference("<")); 47 assertTrue("&", w.isReference("&")); 48 } 49 50 public void testEncode() { 51 assertEquals("", w.encode("")); 52 assertEquals(" ", w.encode(" ")); 53 assertEquals(" ", w.encode(" ")); 54 assertEquals("&#A0;", w.encode("&#A0;")); 55 assertEquals("20;", w.encode("20;")); 56 assertEquals("&#20", w.encode("")); 57 assertEquals(""", w.encode(""")); 58 assertEquals("'", w.encode("'")); 59 assertEquals(">", w.encode(">")); 60 assertEquals("<", w.encode("<")); 61 assertEquals("&", w.encode("&")); 62 assertEquals(""", w.encode("\"")); 63 assertEquals("<", w.encode("<")); 64 assertEquals("&", w.encode("&")); 65 assertEquals("", w.encode("\u0017")); 66 assertEquals("\"20;&", w.encodedata("\"20;&")); 67 assertEquals("", w.encodedata("\u0017")); 68 } 69 70 public void testIsLegalCharacter() { 71 assertTrue("0x00", !w.isLegalCharacter('\u0000')); 72 assertTrue("0x09", w.isLegalCharacter('\t')); 73 assertTrue("0x0A", w.isLegalCharacter('\n')); 74 assertTrue("0x0C", w.isLegalCharacter('\r')); 75 assertTrue("0x1F", !w.isLegalCharacter('\u001F')); 76 assertTrue("0x20", w.isLegalCharacter('\u0020')); 77 assertTrue("0xD7FF", w.isLegalCharacter('\uD7FF')); 78 assertTrue("0xD800", !w.isLegalCharacter('\uD800')); 79 assertTrue("0xDFFF", !w.isLegalCharacter('\uDFFF')); 80 assertTrue("0xE000", w.isLegalCharacter('\uE000')); 81 assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD')); 82 assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE')); 83 } 84 85 public void testCDATAEndEncoding() { 86 assertEquals("]>", w.encodedata("]>")); 87 assertEquals("]]", w.encodedata("]]")); 88 assertEquals("]]>", w.encodedata("]]>")); 89 assertEquals("]]>A", w.encodedata("]]>A")); 90 assertEquals("A]]>", w.encodedata("A]]>")); 91 assertEquals("A]]>A", w.encodedata("A]]>A")); 92 assertEquals("A]]>B]]>C", 93 w.encodedata("A]]>B]]>C")); 94 } 95 } 96 | Popular Tags |