/hg/rhino-tests: Refactoring of CompiledScriptTest, added new te...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Tue Dec 4 01:04:03 PST 2012
changeset d2384fcf357a in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=d2384fcf357a
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Tue Dec 04 10:07:05 2012 +0100
Refactoring of CompiledScriptTest, added new tests, improved error messages.
Added new code snippets.
diffstat:
ChangeLog | 7 +++
src/org/RhinoTests/CompiledScriptTest.java | 63 ++++++++++++++++++++---------
src/org/RhinoTests/JavaScriptSnippets.java | 10 ++++
3 files changed, 60 insertions(+), 20 deletions(-)
diffs (219 lines):
diff -r 9561522de605 -r d2384fcf357a ChangeLog
--- a/ChangeLog Mon Dec 03 10:02:31 2012 +0100
+++ b/ChangeLog Tue Dec 04 10:07:05 2012 +0100
@@ -1,3 +1,10 @@
+2012-12-04 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/CompiledScriptTest.java:
+ Refactoring, added new tests, improved error messages.
+ * src/org/RhinoTests/JavaScriptSnippets.java:
+ Added new code snippets.
+
2012-12-03 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/AbstractScriptEngineClassTest.java:
diff -r 9561522de605 -r d2384fcf357a src/org/RhinoTests/CompiledScriptTest.java
--- a/src/org/RhinoTests/CompiledScriptTest.java Mon Dec 03 10:02:31 2012 +0100
+++ b/src/org/RhinoTests/CompiledScriptTest.java Tue Dec 04 10:07:05 2012 +0100
@@ -122,11 +122,11 @@
* @throws ScriptException
* this exception is thrown when this test case failed.
*/
- protected void testCompileScriptStoredInString() throws ScriptException {
+ protected void testCompileEmptyScript1StoredInString() throws ScriptException {
Compilable compilingEngine = (Compilable)this.scriptEngine;
assertNotNull(compilingEngine, "cannot get compiling engine");
if (compilingEngine != null) {
- CompiledScript script = compilingEngine.compile("");
+ CompiledScript script = compilingEngine.compile(JavaScriptSnippets.EMPTY_SCRIPT_1);
assertNotNull(script, "cannot compile script");
}
}
@@ -138,7 +138,7 @@
* this exception is thrown when this test case failed.
*/
protected void testCompileAndRunSimpleScriptStoredInString() throws ScriptException {
- CompiledScript script = getCompiledScript("");
+ CompiledScript script = getCompiledScript(JavaScriptSnippets.EMPTY_SCRIPT_1);
Object result = script.eval();
assertNull(result, "result should be null");
}
@@ -150,19 +150,20 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalNumericExpression1() throws ScriptException {
- CompiledScript script = getCompiledScript(JavaScriptSnippets.NUMERIC_EXPRESSION_1);
+ final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_1;
+ 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);
+ 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);
+ assertEquals(integerResult, 3, "wrong result " + integerResult + " for the expression: '" + expression + "'");
}
}
@@ -173,19 +174,20 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalNumericExpression2() throws ScriptException {
- CompiledScript script = getCompiledScript(JavaScriptSnippets.NUMERIC_EXPRESSION_2);
+ final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_2;
+ 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);
+ 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);
+ assertEquals(integerResult, 6, "wrong result " + integerResult + " for the expression: '" + expression + "'");
}
}
@@ -196,19 +198,20 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalNumericExpression3() throws ScriptException {
- CompiledScript script = getCompiledScript(JavaScriptSnippets.NUMERIC_EXPRESSION_3);
+ final String expression = JavaScriptSnippets.NUMERIC_EXPRESSION_3;
+ 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, 7, "wrong result " + doubleResult);
+ assertEquals(doubleResult, 7, "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, 7, "wrong result " + integerResult);
+ assertEquals(integerResult, 7, "wrong result " + integerResult + " for the expression: '" + expression + "'");
}
}
@@ -219,12 +222,13 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalDoubleExpression1() throws ScriptException {
- CompiledScript script = getCompiledScript(JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_1);
+ final String expression = JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_1;
+ CompiledScript script = getCompiledScript(expression);
Object result = script.eval();
assertTrue(result instanceof Number, "result is not an instance of Number");
assertTrue(result instanceof Double, "result is not an instance of Integer");
double doubleResult = ((Double) result).doubleValue();
- assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult);
+ assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
}
/**
@@ -234,12 +238,13 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalDoubleExpression2() throws ScriptException {
- CompiledScript script = getCompiledScript(JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_2);
+ final String expression = JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_2;
+ CompiledScript script = getCompiledScript(expression);
Object result = script.eval();
assertTrue(result instanceof Number, "result is not an instance of Number");
assertTrue(result instanceof Double, "result is not an instance of Integer");
double doubleResult = ((Double) result).doubleValue();
- assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult);
+ assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
}
/**
@@ -249,12 +254,13 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalDoubleExpression3() throws ScriptException {
- CompiledScript script = getCompiledScript(JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_3);
+ final String expression = JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_3;
+ CompiledScript script = getCompiledScript(expression);
Object result = script.eval();
assertTrue(result instanceof Number, "result is not an instance of Number");
assertTrue(result instanceof Double, "result is not an instance of Integer");
double doubleResult = ((Double) result).doubleValue();
- assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult);
+ assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult + " for the expression: '" + expression + "'");
}
/**
@@ -264,12 +270,13 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalStringExpression1() throws ScriptException {
- CompiledScript script = getCompiledScript("'Hello' + ' ' + 'world'");
+ final String expression = JavaScriptSnippets.STRING_EXPRESSION_1;
+ CompiledScript script = getCompiledScript(expression);
Object result = script.eval();
assertNotNull(result, "result should not be null");
assertTrue(result instanceof String, "result is not an instance of String");
String stringResult = (String)result;
- assertEquals(stringResult, "Hello world", "wrong result " + stringResult);
+ assertEquals(stringResult, "Hello", "wrong result " + stringResult + " for the expression: '" + expression + "'");
}
/**
@@ -279,6 +286,22 @@
* this exception is thrown when this test case failed.
*/
protected void testEvalStringExpression2() throws ScriptException {
+ final String expression = JavaScriptSnippets.STRING_EXPRESSION_2;
+ CompiledScript script = getCompiledScript(expression);
+ Object result = script.eval();
+ assertNotNull(result, "result should not be null");
+ assertTrue(result instanceof String, "result is not an instance of String");
+ String stringResult = (String)result;
+ assertEquals(stringResult, "Hello world", "wrong result " + stringResult + " 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 testEvalStringExpression3() throws ScriptException {
CompiledScript script = getCompiledScript("'Hello world!'.substring(4, 7)");
Object result = script.eval();
assertNotNull(result, "result should not be null");
diff -r 9561522de605 -r d2384fcf357a src/org/RhinoTests/JavaScriptSnippets.java
--- a/src/org/RhinoTests/JavaScriptSnippets.java Mon Dec 03 10:02:31 2012 +0100
+++ b/src/org/RhinoTests/JavaScriptSnippets.java Tue Dec 04 10:07:05 2012 +0100
@@ -148,6 +148,16 @@
protected static final String DOUBLE_NUMERIC_EXPRESSION_3 = "1./2.";
/**
+ * String expression (containing only string literal).
+ */
+ protected static final String STRING_EXPRESSION_1 = "'Hello'";
+
+ /**
+ * String expression.
+ */
+ protected static final String STRING_EXPRESSION_2 = "'Hello' + ' ' + 'world'";
+
+ /**
* Classical hello world program.
*/
protected static final String HELLO_WORLD_1 = "println('\tHello world!')";
More information about the distro-pkg-dev
mailing list