incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r599358 - /incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java
Date Thu, 29 Nov 2007 09:56:56 GMT
Author: bdelacretaz
Date: Thu Nov 29 01:56:56 2007
New Revision: 599358

URL: http://svn.apache.org/viewvc?rev=599358&view=rev
Log:
SLING-114 - automated test of a complete template added

Modified:
    incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java

Modified: incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java?rev=599358&r1=599357&r2=599358&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java
(original)
+++ incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java
Thu Nov 29 01:56:56 2007
@@ -105,6 +105,47 @@
     public void testComment() throws IOException {
         assertEquals("", parse("<%-- test(); --%>"));
     }
+    
+    /** Test a complete template, using all features */
+    public void testCompleteTemplate() throws IOException {
+        final String input =
+            "<html>\n"
+            + "<head><title><%= someExpr %></title></head>\n"
+            + "<!-- some HTML comment -->\n"
+            + "<-- some ESP comment -->\n"
+            + "// some javascript comment\n"
+            + "/* another javascript comment /*\n"
+            + "<%\n"
+            + "expr on\n"
+            + "two lines\n"
+            + "%>\n"
+            + "<verbatim stuff=\"quoted\">xyz</verbatim>\n"
+            + "<moreverbatim stuff=\'single\'>xx</moreverbatim>\n"
+            + "<!-- HTML comment with <% expr.here; %> and EOL\n-->\n"
+            + "</html>"
+        ;
+        
+        final String expected = 
+            "out=response.writer;out.write(\"<html>\\n\");\n"
+            + "out.write(\"<head><title>\");out.write( someExpr );out.write(\"</title></head>\\n\");\n"
+            + "out.write(\"<!-- some HTML comment -->\\n\");\n"
+            + "out.write(\"<-- some ESP comment -->\\n\");\n"
+            + "out.write(\"// some javascript comment\\n\");\n"
+            + "out.write(\"/* another javascript comment /*\\n\");\n"
+            + "\n"
+            + "expr on\n"
+            + "two lines\n"
+            + "out.write(\"\\n\");\n"
+            + "out.write(\"<verbatim stuff=\\\"quoted\\\">xyz</verbatim>\\n\");\n"
+            + "out.write(\"<moreverbatim stuff='single'>xx</moreverbatim>\\n\");\n"
+            + "out.write(\"<!-- HTML comment with \"); expr.here; out.write(\" and EOL\\n\");\n"
+            + "out.write(\"-->\\n\");\n"
+            + "out.write(\"</html>\");"
+        ;
+        
+        final String actual = parse(input);
+        assertEquals(flatten(expected), flatten(actual));
+    }
 
     /** Helper to pass an ESP text through the EspReader and return the result */
     private String parse(String text) throws IOException {
@@ -117,5 +158,10 @@
         }
 
         return buf.toString();
+    }
+    
+    /** Replace \n with . in strings to make it easier to compare visually for testing */
+    private static String flatten(String str) {
+        return str.replace('\n', '.');
     }
 }



Mime
View raw message