/hg/rhino-tests: Added new tests into CompiledScriptTest.

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Thu Apr 10 09:05:05 UTC 2014


changeset 9b40969f01e3 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=9b40969f01e3
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Apr 10 11:05:49 2014 +0200

	Added new tests into CompiledScriptTest.


diffstat:

 ChangeLog                                  |   6 +
 src/org/RhinoTests/CompiledScriptTest.java |  96 ++++++++++++++++++++++++++++++
 src/org/RhinoTests/JavaScriptSnippets.java |  20 ++++++
 3 files changed, 122 insertions(+), 0 deletions(-)

diffs (149 lines):

diff -r 48afda73ee6e -r 9b40969f01e3 ChangeLog
--- a/ChangeLog	Wed Apr 09 13:30:07 2014 +0200
+++ b/ChangeLog	Thu Apr 10 11:05:49 2014 +0200
@@ -1,3 +1,9 @@
+2014-04-10  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/CompiledScriptTest.java:
+	* src/org/RhinoTests/JavaScriptSnippets.java:
+	Added new tests into CompiledScriptTest.
+
 2014-04-09  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/JavaScriptSnippets.java:
diff -r 48afda73ee6e -r 9b40969f01e3 src/org/RhinoTests/CompiledScriptTest.java
--- a/src/org/RhinoTests/CompiledScriptTest.java	Wed Apr 09 13:30:07 2014 +0200
+++ b/src/org/RhinoTests/CompiledScriptTest.java	Thu Apr 10 11:05:49 2014 +0200
@@ -317,6 +317,102 @@
      * @throws ScriptException
      *             this exception is thrown when this test case failed.
      */
+    protected void testEvalNumericExpression7() throws ScriptException {
+    	final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_7;
+    	CompiledScript script = getCompiledScript(expression);
+    	Object result = script.eval();
+    	assertNotNull(result, "result should not be null");
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+		if (getJavaVersion() >= 7) {
+			assertTrue(result instanceof Double, "result is not an instance of Double");
+			double doubleResult = ((Double) result).doubleValue();
+			assertEquals(doubleResult, 42, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
+		}
+		else {
+			assertTrue(result instanceof Integer, "result is not an instance of Integer");
+			int integerResult = ((Integer) result).intValue();
+			assertEquals(integerResult, 42, "wrong result " + integerResult + " for the expression: '" + expression + "'");
+		}
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalNumericExpression8() throws ScriptException {
+    	final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_8;
+    	CompiledScript script = getCompiledScript(expression);
+    	Object result = script.eval();
+    	assertNotNull(result, "result should not be null");
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+		if (getJavaVersion() >= 7) {
+			assertTrue(result instanceof Double, "result is not an instance of Double");
+			double doubleResult = ((Double) result).doubleValue();
+			assertEquals(doubleResult, 42, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
+		}
+		else {
+			assertTrue(result instanceof Integer, "result is not an instance of Integer");
+			int integerResult = ((Integer) result).intValue();
+			assertEquals(integerResult, 42, "wrong result " + integerResult + " for the expression: '" + expression + "'");
+		}
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalNumericExpression9() throws ScriptException {
+    	final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_9;
+    	CompiledScript script = getCompiledScript(expression);
+    	Object result = script.eval();
+    	assertNotNull(result, "result should not be null");
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+		if (getJavaVersion() >= 7) {
+			assertTrue(result instanceof Double, "result is not an instance of Double");
+			double doubleResult = ((Double) result).doubleValue();
+			assertEquals(doubleResult, 3, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
+		}
+		else {
+			assertTrue(result instanceof Integer, "result is not an instance of Integer");
+			int integerResult = ((Integer) result).intValue();
+			assertEquals(integerResult, 3, "wrong result " + integerResult + " for the expression: '" + expression + "'");
+		}
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalNumericExpression10() throws ScriptException {
+    	final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_10;
+    	CompiledScript script = getCompiledScript(expression);
+    	Object result = script.eval();
+    	assertNotNull(result, "result should not be null");
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+		if (getJavaVersion() >= 7) {
+			assertTrue(result instanceof Double, "result is not an instance of Double");
+			double doubleResult = ((Double) result).doubleValue();
+			assertEquals(doubleResult, 6, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
+		}
+		else {
+			assertTrue(result instanceof Integer, "result is not an instance of Integer");
+			int integerResult = ((Integer) result).intValue();
+			assertEquals(integerResult, 6, "wrong result " + integerResult + " for the expression: '" + expression + "'");
+		}
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
     protected void testEvalDoubleExpression1() throws ScriptException {
     	final String expression = JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_1;
     	CompiledScript script = getCompiledScript(expression);
diff -r 48afda73ee6e -r 9b40969f01e3 src/org/RhinoTests/JavaScriptSnippets.java
--- a/src/org/RhinoTests/JavaScriptSnippets.java	Wed Apr 09 13:30:07 2014 +0200
+++ b/src/org/RhinoTests/JavaScriptSnippets.java	Thu Apr 10 11:05:49 2014 +0200
@@ -153,6 +153,26 @@
     protected static final String NUMERIC_EXPRESSION_6 = "(1+2)*3";
 
     /**
+     * Numeric expression.
+     */
+    protected static final String NUMERIC_EXPRESSION_7 = "(42)";
+
+    /**
+     * Numeric expression.
+     */
+    protected static final String NUMERIC_EXPRESSION_8 = "((42))";
+
+    /**
+     * Numeric expression.
+     */
+    protected static final String NUMERIC_EXPRESSION_9 = "((1+2))";
+
+    /**
+     * Numeric expression.
+     */
+    protected static final String NUMERIC_EXPRESSION_10 = "((1+2+3))";
+
+    /**
      * Numeric expression containing floating point value.
      */
     protected static final String DOUBLE_NUMERIC_EXPRESSION_1 = "1./2";


More information about the distro-pkg-dev mailing list