?? creoletojspwikitranslatortest.java
字號:
/* JSPWiki - a JSP-based WikiWiki clone. Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package com.ecyrd.jspwiki.parser;import java.io.FileInputStream;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Properties;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;public class CreoleToJSPWikiTranslatorTest extends TestCase{ public static final String TEST_PROPERTIES = "tests/com/ecyrd/jspwiki/parser/creole.properties"; public static void main(String[] args) { junit.textui.TestRunner.run(CreoleToJSPWikiTranslatorTest.class); } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } public void testBold() throws Exception { String src = "This is **bold**."; assertEquals("This is __bold__.", translate(src)); } public void testBoldVersusList() throws Exception { String src = "**This is all bold.**"; assertEquals("__This is all bold.__", translate(src)); } public void testBoldAcrossLineBreaks() throws Exception { String src = "This is **bold\nand still bold**."; assertEquals("This is __bold" + System.getProperty("line.separator") + "and still bold__.", translate(src)); } public void testBoldAcrossLineParagraphs() throws Exception { String src = "This is **bold\r\n\r\nand no more bold."; assertEquals("This is __bold__\r\n\r\nand no more bold.", translate(src)); } public void testItalicAcrossLineBreaks() throws Exception { String src = "This is //italic\r\nand still italic//."; assertEquals("This is ''italic\r\nand still italic''.", translate(src)); } public void testItalicAcrossLineParagraphs() throws Exception { String src = "This is //italic\r\n\r\nnand no more italic."; assertEquals("This is ''italic''\r\n\r\nnand no more italic.", translate(src)); } public void testItalic() throws Exception { String src = "This is //italic//."; assertEquals("This is ''italic''.", translate(src)); } public void testImage() throws Exception { String src = "This is {{Image}}."; assertEquals("This is [{Image src='Image'}].", translate(src)); } public void testImageLink() throws Exception { String src = "This is [[http://www.wikicreole.org|{{Image}}]] with a link."; assertEquals("This is [{Image src='Image' link='http://www.wikicreole.org'}] with a link.", translate(src)); } public void testImageDescription() throws Exception { String src = "This is {{Image|Description}}."; assertEquals("This is [{Image src='Image' caption='Description'}].", translate(src)); } public void testImageLinkDescription() throws Exception { String src = "This is [[http://www.wikicreole.org|{{Image|Description}}]]."; assertEquals("This is [{Image src='Image' link='http://www.wikicreole.org' caption='Description'}].", translate(src)); } public void testHyperlinks2() throws Exception { String src = "This should be a [[hyperlink]]"; assertEquals("This should be a [hyperlink]", translate(src)); } public void testHyperlinks3() throws Exception { String src = "This should be a [[hyperlink too]]"; assertEquals("This should be a [hyperlink too]", translate(src)); } public void testHyperlinks4() throws Exception { String src = "This should be a [[HyperLink]]"; assertEquals("This should be a [HyperLink]", translate(src)); } public void testHyperlinks5() throws Exception { String src = "This should be a [[HyperLink|here]]"; assertEquals("This should be a [here|HyperLink]", translate(src)); } public void testHyperlinksNamed1() throws Exception { String src = "This should be a [[HyperLink#heading|here]]"; assertEquals("This should be a [here|HyperLink#heading]", translate(src)); } public void testHyperlinksNamed2() throws Exception { String src = "This should be a [[HyperLink#heading]]"; assertEquals("This should be a [HyperLink#heading]", translate(src)); } // // Testing CamelCase hyperlinks // public void testHyperLinks6() throws Exception { String src = "[[DiscussionAboutWiki]] [[WikiMarkupDevelopment]]."; assertEquals("[DiscussionAboutWiki] [WikiMarkupDevelopment].", translate(src)); } /** ******* Stuff not in JSPWikiMarkupParserTest ************************* */ /* these are test where errors occured in the Creole Wiki */ public void testHeadingsCreole1() throws Exception { String src = "=====Level 4 heading"; assertEquals("__Level 4 heading__", translate(src)); } public void testHyperLinksCreole1() throws Exception { String src = "Sponsored by the [Wiki Symposium|http://www.wikisym.org/] and [i3G Institute|http://www.i3g.hs-heilbronn.de]."; assertEquals( "Sponsored by the [Wiki Symposium|http://www.wikisym.org/] and [i3G Institute|http://www.i3g.hs-heilbronn.de].", translate(src)); } public void testHyperLinksJSPWiki() throws Exception { String src = "* [http://www.wikisym.org/cgi-bin/mailman/listinfo/wiki-research|Wiki research mailing list]"; assertEquals(src, translate(src)); } public void testHyperLinksCreole2() throws Exception { String src = "Sponsored by the [[http://www.wikisym.org/|Wiki Symposium]] and [[http://www.i3g.hs-heilbronn.de|i3G Institute]]."; assertEquals( "Sponsored by the [Wiki Symposium|http://www.wikisym.org/] and [i3G Institute|http://www.i3g.hs-heilbronn.de].", translate(src)); } public void testPreformattedCreole() throws Exception { String src = "{{{$$...$$}}}"; assertEquals(src, translate(src)); } public void testPreformattedCreole2() throws Exception { String src = "{{{\r\n" + "\r\n" + "[[http://en.wikipedia.org|wikipedia]]\r\n" + "}}}"; assertEquals(src, translate(src)); } public void testPreformattedCreole3() throws Exception { String src = "{{{\r\n" + "Guitar Chord C:\r\n" + "\r\n" + "||---|---|---|\r\n" + "||-0-|---|---|\r\n" + "||---|-0-|---|\r\n" + "||---|---|-0-|\r\n" + "||---|---|---|\\n" + "}}}"; assertEquals(src, translate(src)); } public void testPreformattedCreole4() throws Exception { // don't interpret plugins String src = "{{{<<Test>>}}}"; assertEquals(src, translate(src)); } public void testPreformattedCreole5() throws Exception { String src = "{{{<<<Test>>>}}}"; assertEquals(src, translate(src)); } public void testPreformattedPlusLinks1() throws Exception { String preformatted = "{{{\r\n" + "Guitar Chord C:\r\n" + "\r\n" + "||---|---|---|\r\n" + "||-0-|---|---|\r\n" + "||---|-0-|---|\r\n" + "||---|---|-0-|\r\n" + "||---|---|---|\r\n" + "}}}"; String src = "[[http://www.wikicreole.org|external Links]]\r\n" + preformatted; String target = "[external Links|http://www.wikicreole.org]\r\n" + preformatted; assertEquals(target, translate(src)); } public void testPreformattedPlusLinks2() throws Exception { String preformatted = "{{{\r\n" + "[[http://www.wikicreole.org]]\r\n" + "}}}"; String src = "[[http://www.wikicreole.org]]\r\n" + preformatted; String target = "[http://www.wikicreole.org]\r\n" + preformatted; assertEquals(target, translate(src)); } public void testListCreole() throws Exception { String src = "- 1\r\n" + "-- 2\r\n" + "--- 3\r\n" + "---- 4\r\n" + "----- 5"; String target = "* 1\r\n" + "** 2\r\n" + "*** 3\r\n" + "**** 4\r\n" + "***** 5"; assertEquals(target, translate(src)); } public void testLineAmbiguity() throws Exception { String src = "Some text\r\n\r\n----\r\n\r\nMore text"; assertEquals(src, translate(src)); } public void testSignartureAmbiguity() throws Exception { String src = "Some **text**\r\n\r\n--Steff"; String target = "Some __text__\r\n\r\n--Steff"; assertEquals(target, translate(src)); } public void disabledTestLinebreakCreole() throws Exception { String src = "My contact dates:\n" + "Pone: xyz\r\n" + "Fax: +45\n" + "Mobile: abc"; String target = "My contact dates:\\\\\n" + "Pone: xyz\\\\\r\n" + "Fax: +45\\\\\n" + "Mobile: abc"; assertEquals(target, translate(src)); } public void disabledTestLinebreakCreoleShort() throws Exception { String src = "a\n" + "b\n" + "c\n"; String target = "a\\\\\n" + "b\\\\\n" + "c\n"; assertEquals(target, translate(src)); } public void disabledTestLinebreakCreoleWithLists() throws Exception { String src = "*This\n" + "*Is\n" + "*a\n" + "*list"; assertEquals(src, translate(src)); } public void testCSS() throws Exception { String src = "Some test\r\n" + "\r\n" + "%%commentbox\r\n" + "Aloha World!\r\n" + "%%\r\n" + "\r\n" + "Does the pagefilter mess up special jspwiki css markup?"; assertEquals(src, translate(src)); } public void testSeparatorAfterHypenList() throws Exception { String src = "- 1\r\n" + "-- 1.1\r\n" + "-- 1.2\r\n" + "- 2\r\n" + "---------\r\n" + "test\r\n" + "Test"; String target = "* 1\r\n" + "** 1.1\r\n" + "** 1.2\r\n" + "* 2\r\n" + "---------\r\n" + "test\r\n" + "Test"; assertEquals(target, translate(src)); } /** * This might not work, users will have to resolve this ambiguity by hand... * * @throws Exception */ public void testBulletListBoldAmbiguity() throws Exception { String src = "* 1\r\n" + "** 1.1\r\n" + "** 1.2\r\n" + "* 2\r\n" + "---------\r\n" + "test"; assertEquals(src, translate(src)); } public void testEscapeHypens() throws Exception { String src = " 1\\\\\r\n" + "~- 3\\\\\r\n" + "~===\\\\\r\n" + "~- 2\\\\"; String target = " 1\\\\\r\n" + "~- 3\\\\\r\n" + "~===\\\\\r\n" + "~- 2\\\\"; assertEquals(target, translate(src)); } public void testEscapeNowiki() throws Exception { String src = "{{{\r\n" + "{{{\r\n" + "{{Image}}\r\n" + "~}}}\r\n" + "}}}\r\n" + "Test"; String target = "{{{\r\n" + "{{{\r\n" + "{{Image}}\r\n" + "~}}}\r\n" + "}}}\r\n" + "Test"; assertEquals(target, translate(src)); } public void testTables1() throws Exception { String src = "|a|b\r\n" + "|c|d"; assertEquals(src, translate(src)); } public void testTables2() throws Exception { String src = "|a|b|\r\n" + "|c|d|"; String target = "|a|b\r\n" + "|c|d"; assertEquals(target, translate(src)); } public void testTables3() throws Exception { String src = "before\r\n" + "|a|b| \r\n" + "|c|d|\r\n" + "after"; String target = "before\r\n" + "|a|b\r\n" + "|c|d\r\n" + "after"; assertEquals(target, translate(src)); } public void testTables4() throws Exception { String src = "before\r\n" + "|a\\\\b|b|\r\n" + "|c|d|\r\n" + "after"; String target = "before\r\n" + "|a\\\\b|b\r\n" + "|c|d\r\n" + "after"; assertEquals(target, translate(src)); } public void testTables5() throws Exception { // does a empty line between two tables get lost? String src = "|a|b|\r\n" + "\r\n" + "|x|y|\r\nTest"; String target = "|a|b\r\n" + "\r\n" + "|x|y\r\nTest"; assertEquals(target, translate(src)); } public void testTableHeaders1() throws Exception
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -