1 4 5 9 10 package org.openlaszlo.compiler; 11 import java.io.*; 12 import java.util.*; 13 import junit.framework.*; 14 import org.openlaszlo.utils.ChainedException; 15 import org.jdom.Element; 16 import org.jdom.Document; 17 import org.jdom.input.SAXBuilder; 18 import org.xml.sax.InputSource ; 19 20 26 27 public class TextCompiler_Test extends TestCase { 28 public TextCompiler_Test (String name) { 29 super(name); 30 } 31 32 public void setUp () { 33 } 34 35 36 public void testHTMLContent () { 37 String [] tests = { 38 40 "A foo <i></i>", "A foo<i></i>", "B foo <i>bar</i>", "B foo <i>bar</i>", "C foo <i> bar</i>", "C foo <i>bar</i>", "D <i>foo</i> bar", "D <i>foo</i> bar", "E <i>foo </i>bar", "E <i>foo </i>bar", "F <i>foo </i> bar", "F <i>foo </i>bar", "G <i>foo</i> <b>bar</b>", "G <i>foo</i> <b>bar</b>", "H <i>foo</i> <b> bar</b>", "H <i>foo</i> <b>bar</b>", "I <i>foo </i> <b> bar</b>", "I <i>foo </i><b>bar</b>", 50 "J <i>foo </i><b> bar</b>", "J <i>foo </i><b>bar</b>", 51 "K <b>foo </b> <i> bar </i>", "K <b>foo </b><i>bar</i>", 53 "0 <i>foo </i><b> bar </b>", "0 <i>foo </i><b>bar</b>", 54 "1 foo <i>bar</i>", "1 foo <i>bar</i>", 55 "2 foo <i> bar</i> ", "2 foo <i>bar</i>", 56 "3 <i>foo</i> bar ", "3 <i>foo</i> bar", 57 "4 <i>foo </i>bar", "4 <i>foo </i>bar", 58 "5 <i>foo </i> bar ", "5 <i>foo </i>bar", 59 "6 <i>foo</i> <b>bar</b>", "6 <i>foo</i> <b>bar</b>", 60 "7 <i>foo</i> <b> bar </b>", "7 <i>foo</i> <b>bar</b>", 61 "8 <i>foo </i> <b> bar</b>", "8 <i>foo </i><b>bar</b>", 62 "9 <i>foo </i><b> bar</b>.", "9 <i>foo </i><b>bar</b>.", 63 "10 <i> foo </i> <b> bar </b> ", "10 <i>foo </i><b>bar</b>", 64 "11 <i> foo </i><b> bar </b> ", "11 <i>foo </i><b>bar</b>", 65 "12 <i> foo</i><b> bar </b> ", "12 <i>foo</i><b> bar</b>", 66 67 "<b><i>BoldItalic</i>Bold</b><i>Italic</i><u>Underline<b>Bold Underline</b></u>", "<b><i>BoldItalic</i>Bold</b><i>Italic</i><u>Underline<b>Bold Underline</b></u>", 70 71 "<font color=\"#FF0000\">C</font><font color=\"#FFFF00\">O</font><font color=\"#00FFCC\">L</font><font color=\"#CC00CC\">O</font><font color=\"#AABB00\">R</font><font color=\"#DDA00A\">S</font> ", "<font color=\"#FF0000\">C</font><font color=\"#FFFF00\">O</font><font color=\"#00FFCC\">L</font><font color=\"#CC00CC\">O</font><font color=\"#AABB00\">R</font><font color=\"#DDA00A\">S</font>", 73 "1 <font color=\"#ff0000\">foo <i>bar</i></font>", "1 <font color=\"#ff0000\">foo <i>bar</i></font>", 74 "2 <font color=\"#ff0000\">foo</font><font color=\"#00ffff\"> <i> bar</i></font>", "2 <font color=\"#ff0000\">foo</font><font color=\"#00ffff\"> <i>bar</i></font>", 75 "3 <font size=\"20\" color=\"#00ff00\"><i>foo</i></font><font color=\"#ff00aa\"> bar</font>", "3 <font size=\"20\" color=\"#00ff00\"><i>foo</i></font><font color=\"#ff00aa\"> bar</font>", 76 77 78 "<b>this text shouldn't be bold</b>", "<b>this text shouldn't be bold</b>", 81 82 "<b>x </b><![CDATA[y]]> z", "<b>x </b>y z", 84 "<b>x</b> <![CDATA[y]]> z", "<b>x</b> y z", 85 86 "<b>x </b><![CDATA[a & b < c & d > e + f]]> z", "<b>x </b>a & b < c & d > e + f z", 87 "<![CDATA[<b>this text shouldn't be bold</b>]]>", "<b>this text shouldn't be bold</b>", 88 89 " text" , "text", 90 "text " , "text", 91 " <b>x</b>" , "<b>x</b>", 92 "<b>x</b> " , "<b>x</b>", 93 94 "<![CDATA[ text]]>" , "text", 95 96 "<![CDATA[text ]]>" , "text", 97 " <b>x</b>" , "<b>x</b>", 98 "<b>x</b> " , "<b>x</b>", 99 100 "<![CDATA[ ]]><b>x</b>" , "<b>x</b>", 101 "<b>x</b><![CDATA[ ]]>" , "<b>x</b>", 102 103 "<![CDATA[a]]>b" , "ab", 105 "<![CDATA[a ]]>b" , "a b", 106 "<![CDATA[a]]> b" , "a b", 107 "<![CDATA[a ]]> b" , "a b", 108 "a<![CDATA[b]]>" , "ab", 109 "a<![CDATA[ b]]>" , "a b", 110 "a <![CDATA[b]]>" , "a b", 111 "a <![CDATA[ b]]>" , "a b", 112 113 "a<![CDATA[]]>b", "ab", 115 " a<![CDATA[]]>b", "ab", 116 117 "some <attribute name=\"x\" value=\"10\"/> text", "some text", 119 "some <method name=\"f\" args=\"x\">return</method> text", "some text", 120 "some <state name=\"s\">state</state> text", "some text", 121 122 "<a HREF=\"foo\">b</a>", null, 124 "<font face=\"face\" size=\"123\" color=\"red\">color</font>", null, 125 126 128 130 "<b><i>BoldItalic</i>Bold<&></b><i>Italic</i><u>Underline<b>Bold Underline</b></u>", "<b><i>BoldItalic</i>Bold<&></b><i>Italic</i><u>Underline<b>Bold Underline</b></u>", 132 133 }; 134 int num = 1; 135 for (Iterator iter = Arrays.asList(tests).iterator(); iter.hasNext(); num++) { 136 String source = (String ) iter.next(); 137 String result = (String ) iter.next(); 138 if (result == null) { 139 result = source; 140 } 141 142 try { 143 org.jdom.input.SAXHandler handler = new org.jdom.input.SAXHandler(); 144 org.xml.sax.XMLReader reader = 145 org.xml.sax.helpers.XMLReaderFactory.createXMLReader( 146 "org.apache.xerces.parsers.SAXParser"); 147 reader.setContentHandler(handler); 148 reader.parse(new org.xml.sax.InputSource (new StringReader("<text>" + source + "</text>"))); 149 Document doc = handler.getDocument(); 150 Element xml = doc.getRootElement(); 151 152 assertEquals("getHTMLContent(\"" + source + "\")", 153 result, 154 TextCompiler.getHTMLContent(xml)); 155 } catch (IOException e) { 156 throw new ChainedException(e); 157 } catch (org.xml.sax.SAXParseException e) { 158 fail(e.getMessage()); 159 } catch (org.xml.sax.SAXException e) { 160 fail(e.getMessage()); 161 } 162 } 163 } 164 165 199 } 200 201 | Popular Tags |