incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r585115 - in /incubator/sling/whiteboard/microsling/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/sling/ java/org/apache/sling/microsling/ java/org/apache/sling/microsling/etc/
Date Tue, 16 Oct 2007 11:13:45 GMT
Author: fmeschbe
Date: Tue Oct 16 04:13:43 2007
New Revision: 585115

URL: http://svn.apache.org/viewvc?rev=585115&view=rev
Log:
Add simple unit tests for the EspReader

Added:
    incubator/sling/whiteboard/microsling/src/test/
    incubator/sling/whiteboard/microsling/src/test/java/
    incubator/sling/whiteboard/microsling/src/test/java/org/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java?rev=585115&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/etc/EspReaderTest.java
Tue Oct 16 04:13:43 2007
@@ -0,0 +1,65 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.microsling.etc;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+/**
+ * The <code>EspReaderTest</code> contains some simple test cases for the
+ * <code>EspReader</code> class which processes ESP (ECMA Server Page) templated
+ * JavaScript and produces plain JavaScript.
+ */
+public class EspReaderTest extends TestCase {
+
+    /** Test standard template text */
+    public void testTemplate() throws IOException {
+        assertEquals("out.write(\"test\");", parse("test"));
+        assertEquals("out.write(\"test\\n\");\nout.write(\"test2\");", parse("test\ntest2"));
+    }
+
+    /** Test plain JavaScript code */
+    public void testCode() throws IOException {
+        assertEquals(" test(); ", parse("<% test(); %>"));
+        assertEquals(" \ntest();\ntest2(); ", parse("<% \ntest();\ntest2(); %>"));
+    }
+
+    /** Test JavaScript expressions */
+    public void testExpr() throws IOException {
+        assertEquals("out.write( x + 1 );", parse("<%= x + 1 %>"));
+        assertEquals("out.write(\"<!-- \");out.write( x + 1 );out.write(\" -->\");",
parse("<!-- <%= x + 1 %> -->"));
+    }
+
+    /** Test JavaScript comment */
+    public void testComment() throws IOException {
+        assertEquals("", parse("<%-- test(); --%>"));
+    }
+
+    /** Helper to pass an ESP text through the EspReader and return the result */
+    private String parse(String text) throws IOException {
+        StringBuffer buf = new StringBuffer();
+
+        Reader r = new EspReader(new StringReader(text));
+        int c;
+        while ( (c=r.read()) >= 0) {
+            buf.append( (char) c);
+        }
+
+        return buf.toString();
+    }
+}



Mime
View raw message