You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/02/16 14:32:44 UTC
svn commit: r628292 -
/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
Author: fmeschbe
Date: Sat Feb 16 05:32:44 2008
New Revision: 628292
URL: http://svn.apache.org/viewvc?rev=628292&view=rev
Log:
SLING-157 Unit Tests for output of numeric expressions
Modified:
incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
Modified: incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java?rev=628292&r1=628291&r2=628292&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/helper/EspReaderTest.java Sat Feb 16 05:32:44 2008
@@ -22,8 +22,12 @@
import java.io.Reader;
import java.io.StringReader;
+import javax.script.ScriptException;
+
import junit.framework.TestCase;
+import org.apache.sling.scripting.ScriptEngineHelper;
+
/**
* The <code>EspReaderTest</code> contains some simple test cases for the
* <code>EspReader</code> class which processes ESP (ECMA Server Page) templated
@@ -192,6 +196,44 @@
assertEquals(flatten(expected), flatten(actual));
}
+ /** Test a complete template, using all features */
+ public void testNumericExpression() throws IOException {
+ String input = "<%= 1 %>";
+ String expected = "out=response.writer;out.write( 1 );";
+ String actual = parse(input);
+ assertEquals(expected, actual);
+
+ input = "<%= \"1\" %>";
+ expected = "out=response.writer;out.write( \"1\" );";
+ actual = parse(input);
+ assertEquals(expected, actual);
+
+ input = "<%= '1' %>";
+ expected = "out=response.writer;out.write( '1' );";
+ actual = parse(input);
+ assertEquals(expected, actual);
+ }
+
+ /** Test a complete template, using all features */
+ public void testNumericExpressionOutput() throws ScriptException {
+ ScriptEngineHelper script = new ScriptEngineHelper();
+
+ String input = "out.write( 1 );";
+ String actual = script.evalToString(input);
+ String expected = "1";
+ assertEquals(expected, actual);
+
+ input = "out.write( \"1\" );";
+ actual = script.evalToString(input);
+ expected = "1";
+ assertEquals(expected, actual);
+
+ input = "out.write( '1' );";
+ actual = script.evalToString(input);
+ expected = "1";
+ assertEquals(expected, actual);
+ }
+
/** Helper to pass an ESP text through the EspReader and return the result */
private String parse(String text) throws IOException {
StringBuffer buf = new StringBuffer();