@Test publicvoid testParserLiteralExpression() { // Inspired by work on bug 45451, comments from kkolinko on the dev // list and looking at the spec to find some edge cases
// '\' is only an escape character inside a StringLiteral Assert.assertEquals("\\\\", evaluateExpression("\\\\"));
// '\' is only an escape for '${' and '#{'. Assert.assertEquals("\\$", evaluateExpression("\\$")); Assert.assertEquals("${", evaluateExpression("\\${")); Assert.assertEquals("\\$a", evaluateExpression("\\$a")); Assert.assertEquals("\\a", evaluateExpression("\\a")); Assert.assertEquals("\\\\", evaluateExpression("\\\\"));
}
@Test publicvoid testParserStringLiteral() { // Inspired by work on bug 45451, comments from kkolinko on the dev // list and looking at the spec to find some edge cases
// The only characters that can be escaped inside a String literal // are \ " and '. # and $ are not escaped inside a String literal. Assert.assertEquals("\\", evaluateExpression("${'\\\\'}")); Assert.assertEquals("\\", evaluateExpression("${\"\\\\\"}")); Assert.assertEquals("\\\"'$#", evaluateExpression("${'\\\\\\\"\\'$#'}")); Assert.assertEquals("\\\"'$#", evaluateExpression("${\"\\\\\\\"\\'$#\"}"));
// Trying to quote # or $ should throw an error
Exception e = null; try {
evaluateExpression("${'\\$'}");
} catch (ELException el) {
e = el;
} Assert.assertNotNull(e);
privatevoid compareBoth(String msg, int expected, Object o1, Object o2) { int i1 = ELSupport.compare(null, o1, o2); int i2 = ELSupport.compare(null, o2, o1); Assert.assertEquals(msg, expected, i1); Assert.assertEquals(msg, expected, -i2);
}
@Test publicvoid testElSupportCompare() {
compareBoth("Nulls should compare equal", 0, null, null);
compareBoth("Null should compare equal to \"\"", 0, "", null);
compareBoth("Null should be less than File()", -1, null, new File(""));
compareBoth("Null should be less than Date()", -1, null, new Date());
compareBoth("Date(0) should be less than Date(1)", -1, new Date(0), new Date(1)); try {
compareBoth("Should not compare", 0, new Date(), new File("")); Assert.fail("Expecting ClassCastException");
} catch (ClassCastException expected) { // Expected
} Assert.assertTrue(null == null);
}
/** *Testmixing${...}and#{...}inthesameexpression.
*/
@Test publicvoid testMixedTypes() { // Mixing types should throw an error
Exception e = null; try {
evaluateExpression("${1+1}#{1+1}");
} catch (ELException el) {
e = el;
} Assert.assertNotNull(e);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.