Removed some dead code and updated exception unit tests to lastest spec
This commit is contained in:
parent
856073cc5b
commit
275c4aa161
|
@ -261,10 +261,6 @@ public final class SAX3XMLConstants {
|
|||
return true;
|
||||
}
|
||||
|
||||
//static public boolean isCharRef(String c) {
|
||||
// &#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
|
||||
//}
|
||||
|
||||
static private boolean escapeXMLValueAppend(int codePoint, StringBuilder result) {
|
||||
if (codePoint == '<') {
|
||||
result.append("<");
|
||||
|
@ -300,18 +296,8 @@ public final class SAX3XMLConstants {
|
|||
if (escapeXMLValueAppend(c,result)) {
|
||||
continue;
|
||||
}
|
||||
if (/*isNameChar(c)*/true==false) {// TODO: add correct
|
||||
// 4.1 Character and Entity References;
|
||||
// If the character reference begins with " &#x ", the digits and letters up to the terminating ; provide a hexadecimal representation of the character's code point in ISO/IEC 10646.
|
||||
// If it begins just with " &# ", the digits up to the terminating ; provide a decimal representation of the character's code point.
|
||||
result.append("&#x");
|
||||
result.append(Integer.toHexString(c));
|
||||
result.append(";");
|
||||
continue;
|
||||
} else {
|
||||
result.appendCodePoint(c);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
@ -320,8 +306,6 @@ public final class SAX3XMLConstants {
|
|||
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
int c = iterator.nextInt();
|
||||
//for (int i=0;i<length;i++) {
|
||||
// char c = value.charAt(i);
|
||||
if (c == '&') {
|
||||
StringBuilder entity = new StringBuilder(16);
|
||||
entity.appendCodePoint(c);
|
||||
|
|
|
@ -83,9 +83,8 @@ public class SAX3WriterXmlAttributeTest {
|
|||
@Test
|
||||
public void testAttributeWhiteSpace() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
writer.startDocument();
|
||||
|
||||
Assertions.assertThrows(SAXException.class, () -> {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "", "", "", "junit");
|
||||
|
@ -106,12 +105,11 @@ public class SAX3WriterXmlAttributeTest {
|
|||
atts.addAttribute ("", "foobar", "", "", "junit");
|
||||
writer.startElementEnd("", "test junit", "", atts);
|
||||
});
|
||||
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
atts.addAttribute ("", "abc", "", "", " junit ");
|
||||
writer.startElementEnd("", "root", "", atts);
|
||||
writer.endDocument();
|
||||
|
||||
}
|
||||
String output = outputWriter.toString();
|
||||
Assertions.assertNotNull(output);
|
||||
Assertions.assertTrue(output.length()>0);
|
||||
|
|
|
@ -103,65 +103,49 @@ public class SAX3WriterXmlTest {
|
|||
@Test
|
||||
public void testXmlInvalid() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.startElement("", "foobar", "", atts);
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
});
|
||||
Assertions.assertTrue(e.getMessage().contains("tag"));
|
||||
Assertions.assertTrue(e.getMessage().contains("foobar"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlInvalidEnd() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.startElement("", "foobar", "", atts);
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
});
|
||||
Assertions.assertTrue(e.getMessage().contains("Invalid"));
|
||||
Assertions.assertTrue(e.getMessage().contains("2"));
|
||||
Assertions.assertTrue(e.getMessage().contains("open"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessingInstruction() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("target", "data");
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
String output = outputWriter.toString();
|
||||
Assertions.assertNull(e);
|
||||
Assertions.assertNotNull(output);
|
||||
Assertions.assertTrue(output.length()>0);
|
||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test/>"), output);
|
||||
|
@ -170,22 +154,16 @@ public class SAX3WriterXmlTest {
|
|||
@Test
|
||||
public void testProcessingInstructionInline() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
AttributesImpl atts = new AttributesImpl();
|
||||
|
||||
Exception e = null;
|
||||
try {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("target", "data");
|
||||
writer.startElement("", "test", "", atts);
|
||||
writer.processingInstruction("target-doc", "data-doc");
|
||||
writer.endElement("", "test", "");
|
||||
writer.endDocument();
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
String output = outputWriter.toString();
|
||||
Assertions.assertNull(e);
|
||||
Assertions.assertNotNull(output);
|
||||
Assertions.assertTrue(output.length()>0);
|
||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test>\n\t<?target-doc data-doc?>\n</test>\n"), output);
|
||||
|
@ -194,53 +172,41 @@ public class SAX3WriterXmlTest {
|
|||
@Test
|
||||
public void testProcessingInstructionTargetXmlPrefix() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
Exception e = null;
|
||||
try {
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("xmlPrefix", "isInvalid");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
});
|
||||
Assertions.assertTrue(e.getMessage().contains("instruction"));
|
||||
Assertions.assertTrue(e.getMessage().contains("start with xml"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessingInstructionTargetNoneNameChar() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
Exception e = null;
|
||||
try {
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("4Prefix", "isInvalid");
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
});
|
||||
Assertions.assertTrue(e.getMessage().contains("instruction"));
|
||||
Assertions.assertTrue(e.getMessage().contains("invalid name"));
|
||||
Assertions.assertTrue(e.getMessage().contains("4Prefix"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessingInstructionDataNoneChar() throws Exception {
|
||||
StringWriter outputWriter = new StringWriter();
|
||||
SAX3WriterXml writer = new SAX3WriterXml(outputWriter);
|
||||
Exception e = null;
|
||||
try {
|
||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
||||
writer.startDocument();
|
||||
writer.processingInstruction("target", "isInvalidChar="+0xD800);
|
||||
} catch (Exception catchE) {
|
||||
e = catchE;
|
||||
}
|
||||
Assertions.assertNotNull(e);
|
||||
Assertions.assertEquals(SAXException.class, e.getClass());
|
||||
});
|
||||
Assertions.assertTrue(e.getMessage().contains("instruction"));
|
||||
Assertions.assertTrue(e.getMessage().contains("invalid char"));
|
||||
Assertions.assertTrue(e.getMessage().contains("isInvalidChar=55296"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue