LUCENE-5207: more parser tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5207@1523351 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-09-14 23:13:25 +00:00
parent 46d3371997
commit bafedad9c9
2 changed files with 63 additions and 0 deletions

View File

@ -25,6 +25,7 @@ public class TestJavascriptCompiler extends LuceneTestCase {
public void testValidCompiles() throws Exception {
assertNotNull(JavascriptCompiler.compile("100"));
assertNotNull(JavascriptCompiler.compile("valid0+100"));
assertNotNull(JavascriptCompiler.compile("valid0+\n100"));
assertNotNull(JavascriptCompiler.compile("logn(2, 20+10-5.0)"));
}
@ -42,6 +43,59 @@ public class TestJavascriptCompiler extends LuceneTestCase {
} catch (ParseException expected) {
// expected exception
}
try {
JavascriptCompiler.compile("0y1234");
fail();
} catch (ParseException expected) {
// expected exception
}
try {
JavascriptCompiler.compile("500EE");
fail();
} catch (ParseException expected) {
// expected exception
}
try {
JavascriptCompiler.compile("500.5EE");
fail();
} catch (ParseException expected) {
// expected exception
}
}
public void testEmpty() {
try {
JavascriptCompiler.compile("");
fail();
} catch (ParseException expected) {
// expected exception
}
try {
JavascriptCompiler.compile("()");
fail();
} catch (ParseException expected) {
// expected exception
}
try {
JavascriptCompiler.compile(" \r\n \n \t");
fail();
} catch (ParseException expected) {
// expected exception
}
}
public void testNull() throws Exception {
try {
JavascriptCompiler.compile(null);
fail();
} catch (NullPointerException expected) {
// expected exception
}
}
public void testWrongArity() throws Exception {

View File

@ -295,6 +295,8 @@ public class TestJavascriptOperations extends LuceneTestCase {
assertEvaluatesTo("1", 1);
assertEvaluatesTo("123456789", 123456789);
assertEvaluatesTo("5.6E2", 560);
assertEvaluatesTo("5.6E+2", 560);
assertEvaluatesTo("500E-2", 5);
}
public void testHexConst() throws Exception {
@ -304,6 +306,13 @@ public class TestJavascriptOperations extends LuceneTestCase {
assertEvaluatesTo("0x1234ABCDEF", 78193085935L);
}
public void testHexConst2() throws Exception {
assertEvaluatesTo("0X0", 0);
assertEvaluatesTo("0X1", 1);
assertEvaluatesTo("0XF", 15);
assertEvaluatesTo("0X1234ABCDEF", 78193085935L);
}
public void testOctalConst() throws Exception {
assertEvaluatesTo("00", 0);
assertEvaluatesTo("01", 1);