Author: dmorozov
Date: 2008-11-17 13:04:31 -0500 (Mon, 17 Nov 2008)
New Revision: 11194
Added:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/seamparser/
trunk/sandbox/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java
Log:
initial commit, test for the html seam text converter
Added:
trunk/sandbox/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java
===================================================================
---
trunk/sandbox/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java
(rev 0)
+++
trunk/sandbox/ui/editor/src/test/java/org/richfaces/seamparser/HtmlSeamParserTest.java 2008-11-17
18:04:31 UTC (rev 11194)
@@ -0,0 +1,146 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.seamparser;
+
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+import org.jboss.seam.text.SeamTextLexer;
+import org.jboss.seam.text.SeamTextParser;
+import org.richfaces.HtmlSeamTextLexer;
+import org.richfaces.HtmlSeamTextParser;
+
+/**
+ * HtmlSeamParser Junit Test
+ * @author Denis Morozov
+ *
+ */
+public class HtmlSeamParserTest extends TestCase {
+
+
+ private final static String SEAM_TEXT_EXPRESSION_1 = "It's easy to make
*emphasis*, |monospace|, "
+ + "~deleted text~, super^scripts^ or_underlines_.";
+
+ private final static String SEAM_TEXT_EXPRESSION_2 = "+This is a big
heading\n"
+ + "You /must/ have some text following a heading!\n\n"
+ + "++This is a smaller heading\n"
+ + "This is the first paragraph. We can split it across multiple"
+ + "lines, but we must end it with a blank line.\n\n"
+ + "This is the second paragraph.";
+
+ private final static String SEAM_TEXT_EXPRESSION_3 = "An ordered list:\n\n"
+ + "#first item\n" + "#second item\n"
+ + "#and even the /third/ item\n\n" + "An unordered list:\n\n"
+ + "=an item\n" + "=another item";
+
+ private final static String SEAM_TEXT_EXPRESSION_4 = "The other guy said: "+
"\"Nyeah nyeah-nee\"";
+
+ private final static String SEAM_TEXT_EXPRESSION_5 = "You can write down equations
like 2\\*3\\=6 and HTML tagslike \\<body\\> using the escape character:
\\\\.";
+
+ private final static String SEAM_TEXT_EXPRESSION_6 = "My code doesn't
work:"
+ + "`for (int i=0; i<100; i--)\n"
+ + "{\n"
+ + "doSomething(); doSomething();\n"
+ + "doSomething() " +
+ "}`" + " Any ideas?";
+
+ private final static String SEAM_TEXT_EXPRESSION_7 = "+test
value<h1>test1<h2>test2</h2>test4</h1>\ntest";
+
+ private final static String SEAM_TEXT_EXPRESSION_8 = "+test
value<div>test5</div><h1>test1<div>test2</div>test4</h1>\ntest";
+
+ private final static String SEAM_TEXT_EXPRESSION_9 = "[test
link=>http://test.com]";
+
+ private final static String SEAM_TEXT_EXPRESSION_10 = "This is a |<tag
attribute=\"value\"/>| example.";
+
+ private final static String SEAM_TEXT_EXPRESSION_11 = "= <div></div>
<h1> test value </h1>";
+
+
+
+ public HtmlSeamParserTest(String name) {
+ super(name);
+ }
+ public void testSeamTextConverting1() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_1);
+ }
+
+ public void testSeamTextConverting2() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_2);
+ }
+
+ public void testSeamTextConverting3() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_3);
+ }
+
+ public void testSeamTextConverting4() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_4);
+ }
+
+ public void testSeamTextConverting5() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_5);
+ }
+
+ public void testSeamTextConverting6() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_6);
+ }
+
+ public void testSeamTextConverting7() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_7);
+ }
+
+ public void testSeamTextConverting8() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_8);
+ }
+
+ public void testSeamTextConverting9() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_9);
+ }
+
+ public void testSeamTextConverting10() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_10);
+ }
+
+ public void testSeamTextConverting11() throws Exception {
+ assertSeamConverting(SEAM_TEXT_EXPRESSION_11);
+ }
+
+
+
+
+ /**
+ * Method to assert converting from Seam Text to html and back
+ * @param seamTextExpression
+ * @throws Exception
+ */
+ private void assertSeamConverting(String seamTextExpression)
+ throws Exception {
+
+ SeamTextParser seamParser = new SeamTextParser(new SeamTextLexer(new
StringReader(seamTextExpression)));
+ seamParser.startRule();
+ String html = seamParser.toString();
+
+ HtmlSeamTextParser htmlParser = new HtmlSeamTextParser(new HtmlSeamTextLexer(new
StringReader(html)));
+ htmlParser.startRule();
+ String seamtext = htmlParser.toString();
+
+ assertEquals(seamTextExpression,seamtext.trim());
+ }
+}
Show replies by date