01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.text.tests;
11:
12: import java.io.IOException;
13: import java.io.Reader;
14: import java.io.StringReader;
15:
16: import org.eclipse.jface.internal.text.html.HTML2TextReader;
17:
18: import junit.framework.Test;
19: import junit.framework.TestCase;
20: import junit.framework.TestSuite;
21:
22: public class HTML2TextReaderTester extends TestCase {
23:
24: private static final boolean DEBUG = false;
25:
26: private static final String LD = System.getProperty(
27: "line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
28:
29: public HTML2TextReaderTester(String name) {
30: super (name);
31: }
32:
33: public static Test suite() {
34: return new TestSuite(HTML2TextReaderTester.class);
35: }
36:
37: private void verify(String input, String expectedOutput)
38: throws IOException {
39: Reader reader = new StringReader(input);
40: HTML2TextReader htmlReader = new HTML2TextReader(reader, null);
41: String result = htmlReader.getString();
42: if (DEBUG)
43: System.out.println("<" + result + "/>");
44: assertEquals(expectedOutput, result);
45: }
46:
47: public void test0() throws IOException {
48: String string = "<code>3<5<code>";
49: String expected = "3<5";
50: verify(string, expected);
51: }
52:
53: public void test1() throws IOException {
54: String string = "<dl><dt>@author</dt><dd>Foo Bar</dd></dl>";
55: String expected = LD + "@author" + LD + "\tFoo Bar" + LD;
56: verify(string, expected);
57: }
58:
59: public void test2() throws IOException {
60: String string = "<code>3>5<code>";
61: String expected = "3>5";
62: verify(string, expected);
63: }
64:
65: public void test3() throws IOException {
66: String string = "<a href= \"<p>this is only a string - not a tag<p>\">text</a>";
67: String expected = "text";
68: verify(string, expected);
69: }
70:
71: public void test4() throws IOException {
72: String string = "<html><body text=\"#000000\" bgcolor=\"#FFFF88\"><font size=-1><h5>void p.Bb.fes()</h5><p><dl><dt>Parameters:</dt><dd><b>i</b> fred or <code>null</code></dd></dl></font></body></html>";
73: String expected = "void p.Bb.fes()" + LD + LD + LD
74: + "Parameters:" + LD + "\ti fred or null" + LD;
75: verify(string, expected);
76: }
77:
78: public void test5() throws IOException {
79: String string = "<code>1<2<3<4</code>";
80: String expected = "1<2<3<4";
81: verify(string, expected);
82: }
83:
84: public void test6() throws IOException {
85: //test for bug 19070
86: String string = "<p>Something.<p>Something more.";
87: String expected = LD + "Something." + LD + "Something more.";
88: verify(string, expected);
89: }
90:
91: public void testComments() throws Exception {
92: String string = "<!-- begin-user-doc -->no comment<!-- end-user-doc -->";
93: String expected = "no comment";
94: verify(string, expected);
95: }
96:
97: }
|