]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/parser/WikiLineReaderTest.java
f5bb4fda5be72c00f6ba2bd1e64b73436196ea79
[DictionaryPC.git] / src / com / hughes / android / dictionary / parser / WikiLineReaderTest.java
1 package com.hughes.android.dictionary.parser;
2
3 import junit.framework.TestCase;
4
5 public class WikiLineReaderTest extends TestCase {
6   
7   public void testSimple() {
8     final String wikiText =
9       "Hi" + "\n" +
10       "Hello thad you're <!-- not --> '''pretty''' cool '''''over''''' there." + "\n" +
11       "hi <!--" + "\n" +
12       "multi-line" + "\n" +
13       "# comment -->" + "\n" +
14       "" + "\n" +
15       "asdf\n" + 
16       "# {{template_in_list}}" + "\n" +
17       "[[wikitext]]:[[wikitext]]" + "\n" +  // don't want this to trigger a list
18       "here's [[some blah|some]] wikitext." + "\n" +
19       "here's a {{template|this has an = sign|blah=2|blah2=3|" + "\n" +
20       "blah3=3,[[asdf]|[asdf asdf]|[asdf asdf asdf]],blah4=4}} and some more text." + "\n" +
21       "== Header 2 ==" + "\n" +
22       "{{some-func|blah={{nested-func|n2}}|blah2=asdf}}" + "\n" +
23       "{{unterminated}" + "\n" +
24       "[[unterminated]" + "\n" +
25       "=== {{header-template}} ===" + "\n";
26     
27     final String[] expected = new String[] {
28         "Hi",
29         "Hello thad you're '''pretty''' cool '''''over''''' there.",
30         "hi",
31         "",
32         "asdf",
33         "# {{template_in_list}}",
34         "[[wikitext]]:[[wikitext]]",
35         "here's [[some blah|some]] wikitext.",
36         "here's a {{template|this has an = sign|blah=2|blah2=3| blah3=3,[[asdf]|[asdf asdf]|[asdf asdf asdf]],blah4=4}} and some more text.",
37         "== Header 2 ==",
38         "{{some-func|blah={{nested-func|n2}}|blah2=asdf}}",
39         "{{unterminated}",
40         "[[unterminated]",
41         "=== {{header-template}} ===",
42     };
43     
44     final WikiLineReader wikiLineReader = new WikiLineReader(wikiText);
45     for (int i = 0; i < expected.length; ++i) {
46       assertEquals(expected[i], WikiLineReader.cleanUpLine(wikiLineReader.readLine()));
47     }
48     final String end = wikiLineReader.readLine();
49     if (end != null) {
50       System.out.println(WikiLineReader.cleanUpLine(end));
51     }
52     assertNull(end);
53   }
54   
55   
56
57 }