001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: */package org.jamwiki.parser;
017:
018: import junit.framework.TestCase;
019:
020: /**
021: *
022: */
023: public class TableOfContentsTest extends TestCase {
024:
025: /**
026: *
027: */
028: public TableOfContentsTest(String name) {
029: super (name);
030: }
031:
032: /**
033: *
034: */
035: public void testDuplicateHeadings1() {
036: String input = "";
037: input = "==test==\n" + "==test==\n" + "==test==\n" + "==test==";
038: String output = "";
039: output = "<div class=\"toc-container\"><div class=\"toc-content\"><ol>"
040: + "<li><a href=\"#test\">test</a></li>"
041: + "<li><a href=\"#test_1\">test</a></li>"
042: + "<li><a href=\"#test_2\">test</a></li>"
043: + "<li><a href=\"#test_3\">test</a></li>"
044: + "</ol></div><div class=\"clear\"></div></div>";
045: TableOfContents toc = new TableOfContents();
046: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
047: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
048: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
049: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
050: assertEquals(output, toc.toHTML());
051: }
052:
053: /**
054: *
055: */
056: public void testDuplicateHeadings2() {
057: String input = "";
058: input = "==test==\n" + "==test_2==\n" + "==test==\n"
059: + "==test==";
060: String output = "";
061: output = "<div class=\"toc-container\"><div class=\"toc-content\"><ol>"
062: + "<li><a href=\"#test\">test</a></li>"
063: + "<li><a href=\"#test_2\">test_2</a></li>"
064: + "<li><a href=\"#test_1\">test</a></li>"
065: + "<li><a href=\"#test_3\">test</a></li>"
066: + "</ol></div><div class=\"clear\"></div></div>";
067: TableOfContents toc = new TableOfContents();
068: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
069: toc.addEntry(toc.checkForUniqueName("test_2"), "test_2", 2);
070: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
071: toc.addEntry(toc.checkForUniqueName("test"), "test", 2);
072: assertEquals(output, toc.toHTML());
073: }
074:
075: /**
076: *
077: */
078: public void testMultiLevelHeadings1() {
079: String input = "";
080: input = "==1==\n" + "===1.1===\n" + "==2==\n" + "==3==";
081: String output = "";
082: output = "<div class=\"toc-container\"><div class=\"toc-content\"><ol>"
083: + "<li><a href=\"#1\">1</a><ol>"
084: + "<li><a href=\"#1.1\">1.1</a></li>"
085: + "</ol></li>"
086: + "<li><a href=\"#2\">2</a></li>"
087: + "<li><a href=\"#3\">3</a></li>"
088: + "</ol></div><div class=\"clear\"></div></div>";
089: TableOfContents toc = new TableOfContents();
090: toc.addEntry(toc.checkForUniqueName("1"), "1", 2);
091: toc.addEntry(toc.checkForUniqueName("1.1"), "1.1", 3);
092: toc.addEntry(toc.checkForUniqueName("2"), "2", 2);
093: toc.addEntry(toc.checkForUniqueName("3"), "3", 2);
094: assertEquals(output, toc.toHTML());
095: }
096:
097: /**
098: *
099: */
100: public void testMultiLevelHeadings2() {
101: // cannot increase TOC indentation by more than one level
102: String input = "";
103: input = "====1.1.1====\n" + "==2==\n" + "==3==\n" + "==4==";
104: String output = "";
105: output = "<div class=\"toc-container\"><div class=\"toc-content\"><ol>"
106: + "<li><a href=\"#1.1.1\">1.1.1</a></li>"
107: + "<li><a href=\"#2\">2</a></li>"
108: + "<li><a href=\"#3\">3</a></li>"
109: + "<li><a href=\"#4\">4</a></li>"
110: + "</ol></div><div class=\"clear\"></div></div>";
111: TableOfContents toc = new TableOfContents();
112: toc.addEntry(toc.checkForUniqueName("1.1.1"), "1.1.1", 4);
113: toc.addEntry(toc.checkForUniqueName("2"), "2", 2);
114: toc.addEntry(toc.checkForUniqueName("3"), "3", 2);
115: toc.addEntry(toc.checkForUniqueName("4"), "4", 2);
116: assertEquals(output, toc.toHTML());
117: }
118: }
|