From bafedad9c92de70b5aa347a6b56ff0a9bdd7748f Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 14 Sep 2013 23:13:25 +0000 Subject: [PATCH] LUCENE-5207: more parser tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5207@1523351 13f79535-47bb-0310-9956-ffa450edef68 --- .../js/TestJavascriptCompiler.java | 54 +++++++++++++++++++ .../js/TestJavascriptOperations.java | 9 ++++ 2 files changed, 63 insertions(+) diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java index d02cc79361f..b8944a0309a 100644 --- a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java +++ b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptCompiler.java @@ -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 { diff --git a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptOperations.java b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptOperations.java index a5432a3b6a2..6ade936401e 100644 --- a/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptOperations.java +++ b/lucene/expressions/src/test/org/apache/lucene/expressions/js/TestJavascriptOperations.java @@ -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);