Mercurial > hg > rhino-tests
changeset 65:94369d709381 draft
Added new class JavaScriptSnippets which contains short JavaScript snippets.
Updated CompilableTest to use JavaScriptSnippets class.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Tue, 20 Nov 2012 10:23:57 +0100 |
parents | bba804edaeab |
children | cfb582c14406 |
files | ChangeLog src/org/RhinoTests/CompilableTest.java src/org/RhinoTests/JavaScriptSnippets.java |
diffstat | 3 files changed, 125 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Nov 19 11:15:37 2012 +0100 +++ b/ChangeLog Tue Nov 20 10:23:57 2012 +0100 @@ -1,3 +1,11 @@ +2012-11-20 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/JavaScriptSnippets.java: + Added new class which contains short JavaScript snippets. + + * src/org/RhinoTests/CompilableTest.java: + Updated to use JavaScriptSnippets class. + 2012-11-19 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/SimpleBindingsTest.java:
--- a/src/org/RhinoTests/CompilableTest.java Mon Nov 19 11:15:37 2012 +0100 +++ b/src/org/RhinoTests/CompilableTest.java Tue Nov 20 10:23:57 2012 +0100 @@ -1,7 +1,7 @@ /* Rhino test framework - Copyright (C) 2011 Red Hat + Copyright (C) 2011, 2012 Red Hat This file is part of IcedTea. @@ -47,28 +47,23 @@ import javax.script.ScriptException; /** - * This test case check the behaviour of CompiledScript abstract class and it's - * descendents. + * This test case check the behavior of CompiledScript abstract class and it's + * descendants. * * @author Pavel Tisnovsky * */ public class CompilableTest extends BaseRhinoTest { - /** - * Empty, but still valid script. - */ - private static final String EMPTY_SCRIPT = ""; - - /** - * Instance of ScriptEngineManager which is used by all tests in this test - * case. - */ + /** + * Instance of ScriptEngineManager which is used by all tests in this test + * case. + */ ScriptEngineManager engineManager; - /** - * Instance of ScriptEngine which is used by all tests in this test case. - */ + /** + * Instance of ScriptEngine which is used by all tests in this test case. + */ ScriptEngine scriptEngine; @Override @@ -84,43 +79,43 @@ return; } - /** - * Helper method which tries to retrieve an instance of class which - * implements CompiledScript interface for a given script. - * - * @param scriptText - * script source code - * @return instance of CompiledScript class - * @throws AssertionError - * when CompilingEngine cannot be retrieved - * @throws ScriptException - * thrown when script cannot be compiled - */ - private CompiledScript getCompiledScript(String scriptText) throws AssertionError, ScriptException { - // check if retyping could be done - assertTrue(this.scriptEngine instanceof Compilable, "ScriptEngine does not implement Compilable"); - // scriptEngine should be also retyped to Compilable, at least in case of JavaScript. - Compilable compilingEngine = (Compilable) this.scriptEngine; - // should not happen, but... - assertNotNull(compilingEngine, "cannot get compiling engine"); - // try to compile given script - return compileScript(scriptText, compilingEngine); - } + /** + * Helper method which tries to retrieve an instance of class which + * implements CompiledScript interface for a given script. + * + * @param scriptText + * script source code + * @return instance of CompiledScript class + * @throws AssertionError + * when CompilingEngine cannot be retrieved + * @throws ScriptException + * thrown when script cannot be compiled + */ + private CompiledScript getCompiledScript(String scriptText) throws AssertionError, ScriptException { + // check if retyping could be done + assertTrue(this.scriptEngine instanceof Compilable, "ScriptEngine does not implement Compilable"); + // scriptEngine should be also retyped to Compilable, at least in case of JavaScript. + Compilable compilingEngine = (Compilable) this.scriptEngine; + // should not happen, but... + assertNotNull(compilingEngine, "cannot get compiling engine"); + // try to compile given script + return compileScript(scriptText, compilingEngine); + } - /** - * Helper method which tries to compile given JavaScript. - * - * @param scriptText script source code - * @param compilingEngine instance of class which implements Compilable interface - * @return compiled script - * @throws ScriptException - * @throws AssertionError - */ - private CompiledScript compileScript(String scriptText, Compilable compilingEngine) throws ScriptException, AssertionError { - CompiledScript script = compilingEngine.compile(scriptText); - assertNotNull(script, "cannot compile script"); - return script; - } + /** + * Helper method which tries to compile given JavaScript. + * + * @param scriptText script source code + * @param compilingEngine instance of class which implements Compilable interface + * @return compiled script + * @throws ScriptException + * @throws AssertionError + */ + private CompiledScript compileScript(String scriptText, Compilable compilingEngine) throws ScriptException, AssertionError { + CompiledScript script = compilingEngine.compile(scriptText); + assertNotNull(script, "cannot compile script"); + return script; + } /** * Test if it is possible to compile script from a string. @@ -128,13 +123,13 @@ * @throws ScriptException * this exception is thrown when this test case failed. */ - protected void testCompileScriptStoredInString() throws ScriptException { - Compilable compilingEngine = (Compilable)this.scriptEngine; - assertNotNull(compilingEngine, "cannot get compiling engine"); - if (compilingEngine != null) { - CompiledScript script = compilingEngine.compile(EMPTY_SCRIPT); - assertNotNull(script, "cannot compile script"); - } + protected void testCompileScriptStoredInString1() throws ScriptException { + Compilable compilingEngine = (Compilable)this.scriptEngine; + assertNotNull(compilingEngine, "cannot get compiling engine"); + if (compilingEngine != null) { + CompiledScript script = compilingEngine.compile(JavaScriptSnippets.EMPTY_SCRIPT_1); + assertNotNull(script, "cannot compile script"); + } } /** @@ -143,10 +138,10 @@ * @throws ScriptException * this exception is thrown when this test case failed. */ - protected void testCompileAndRunSimpleScriptStoredInString() throws ScriptException { - CompiledScript script = getCompiledScript(EMPTY_SCRIPT); - Object result = script.eval(); - assertNull(result, "result should be null"); + protected void testCompileAndRunSimpleScriptStoredInString1() throws ScriptException { + CompiledScript script = getCompiledScript(JavaScriptSnippets.EMPTY_SCRIPT_1); + Object result = script.eval(); + assertNull(result, "result should be null"); } /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/RhinoTests/JavaScriptSnippets.java Tue Nov 20 10:23:57 2012 +0100 @@ -0,0 +1,60 @@ +/* + Rhino test framework + + Copyright (C) 2012 Red Hat + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package org.RhinoTests; + +/** + * Short JavaScript snippets stored in strings. + * + * @author Pavel Tisnovsky + */ +public class JavaScriptSnippets { + + /** + * Empty, but still valid script. + */ + protected static final String EMPTY_SCRIPT_1 = ""; + + /** + * Numeric expression. + */ + protected static final String NUMERIC_EXPRESSION_1 = "1+2*3"; + +}