TestXMLEscaping.java: SOLR-33

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@422772 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-07-17 17:57:38 +00:00
parent 1451c6ca7c
commit f2b5656245
1 changed files with 51 additions and 0 deletions

View File

@ -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 &amp; Cl&lt;em>y&lt;/em>de");
}
public void testAmpWithAccents() throws IOException {
// 00e9 is unicode eacute
doSimpleTest("Les \u00e9v\u00e9nements chez Bonnie & Clyde","Les \u00e9v\u00e9nements chez Bonnie &amp; Clyde");
}
public void testAmpDotWithAccents() throws IOException {
// 00e9 is unicode eacute
doSimpleTest("Les \u00e9v\u00e9nements chez Bonnie & Clyde.","Les \u00e9v\u00e9nements chez Bonnie &amp; Clyde.");
}
public void testAmpAndTagWithAccents() throws IOException {
// 00e9 is unicode eacute
doSimpleTest("Les \u00e9v\u00e9nements <chez/> Bonnie & Clyde","Les \u00e9v\u00e9nements &lt;chez/> Bonnie &amp; Clyde");
}
}