mirror of https://github.com/apache/lucene.git
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:
parent
1451c6ca7c
commit
f2b5656245
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue