Apache Lucene open-source search software
TestXMLEscaping.java: SOLR-33
Yonik Seeleyf2b565624536
diff --git a/src/test/org/apache/solr/util/TestXMLEscaping.java b/src/test/org/apache/solr/util/TestXMLEscaping.javanew file mode 100644index 00000000000..ad6e9e109ca--- /dev/null+++ b/src/test/org/apache/solr/util/TestXMLEscaping.java@@ -0,0 +1,51 @@+package org.apache.solr.util;++import junit.framework.TestCase;++import java.io.IOException;+import java.io.StringWriter;+import java.util.Random;+import java.util.BitSet;++/** Test (some of the) character escaping functions of the XML class+ * $Id$+ */++public class TestXMLEscaping extends TestCase {+ private void doSimpleTest(String input,String expectedOutput) throws IOException {+ final StringWriter sw = new StringWriter();+ XML.escapeCharData(input, sw);+ final String result = sw.toString();+ assertEquals("Escaped output matches '" + expectedOutput + "'",result,expectedOutput);+ }++ public void testNoEscape() throws IOException {+ doSimpleTest("Bonnie","Bonnie");+ }++ public void testAmpAscii() throws IOException {+ doSimpleTest("Bonnie & Clyde","Bonnie & Clyde");+ }++ public void testAmpAndTagAscii() throws IOException {+ doSimpleTest("Bonnie & Cl<em>y</em>de","Bonnie & Cl<em>y</em>de");+ }++ public void testAmpWithAccents() throws IOException {+ // 00e9 is unicode eacute+ doSimpleTest("Les \u00e9v\u00e9nements chez Bonnie & Clyde","Les \u00e9v\u00e9nements chez Bonnie & Clyde");+ }++ public void testAmpDotWithAccents() throws IOException {+ // 00e9 is unicode eacute+ doSimpleTest("Les \u00e9v\u00e9nements chez Bonnie & Clyde.","Les \u00e9v\u00e9nements chez Bonnie & Clyde.");+ }++ public void testAmpAndTagWithAccents() throws IOException {+ // 00e9 is unicode eacute+ doSimpleTest("Les \u00e9v\u00e9nements <chez/> Bonnie & Clyde","Les \u00e9v\u00e9nements <chez/> Bonnie & Clyde");+ }+}+++