Author: sdumitriu Date: 2008-02-11 12:09:32 +0100 (Mon, 11 Feb 2008) New Revision: 7484
Added: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/BoldTest.java xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/ItalicsTest.java Modified: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/StrikethroughTest.java xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/UnderlineTest.java Log: XWIKI-1245: Italics XWiki syntax XWIKI-1248: Strong XWiki syntax Added unit tests to prove the syntax works as expected Added: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/BoldTest.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/BoldTest.java (rev 0) +++ xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/BoldTest.java 2008-02-11 11:09:32 UTC (rev 7484) @@ -0,0 +1,148 @@ +package com.xpn.xwiki.render.markup; + +import java.util.ArrayList; + +public class BoldTest extends SyntaxTestsParent +{ + protected void setUp() + { + super.setUp(); + } + + public void testNotTriggeredWithWhitespace() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is not * bold *"); + expects.add("This is not * bold *"); + tests.add("This is not *bold *"); + expects.add("This is not *bold *"); + tests.add("This is not * bold*"); + expects.add("This is not * bold*"); + test(tests, expects); + } + + public void testSimple() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is *bold*"); + expects.add("This is <strong>bold</strong>"); + tests.add("This is *a* bold letter"); + expects.add("This is <strong>a</strong> bold letter"); + tests.add("*a*"); + expects.add("<strong>a</strong>"); + test(tests, expects); + } + + public void testThree() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is *a* short bold*"); + expects.add("This is <strong>a</strong> short bold*"); + tests.add("This is *all * bold*"); + expects.add("This is <strong>all * bold</strong>"); + tests.add("This is *all *bold*"); + expects.add("This is <strong>all *bold</strong>"); + tests.add("This is *one*bold*"); + expects.add("This is <strong>one</strong>bold*"); + test(tests, expects); + } + + public void testMultiple() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("More *bolds* on a *line*"); + expects + .add("More <strong>bolds</strong> on a <strong>line</strong>"); + test(tests, expects); + } + + public void testExtraStarsAreInside() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("The extra stars are **inside**"); + expects.add("The extra stars are <strong>*inside*</strong>"); + tests.add("The extra stars are ** inside **"); + expects.add("The extra stars are <strong>* inside *</strong>"); + test(tests, expects); + } + + public void testWithoutWhitespace() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This*is*bold"); + expects.add("This<strong>is</strong>bold"); + test(tests, expects); + } + + public void testSequence() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("*Eeny*meeny*miny*moe*"); + expects + .add("<strong>Eeny</strong>meeny<strong>miny</strong>moe*"); + tests.add("* Eeny*meeny*miny*moe*"); + expects + .add("...<li>Eeny<strong>meeny</strong>miny<strong>moe</strong></li>..."); + test(tests, expects); + } + + public void testWithLists() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("* this is a list item*"); + expects.add("...<li>this is a list item*</li>..."); + tests.add("* this is a list *item*"); + expects.add("...<li>this is a list <strong>item</strong></li>..."); + test(tests, expects); + } + + public void testSeveralInARow() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("this is not bold: ** "); + expects.add("this is not bold: ** "); + tests.add("this is a bold star: *** "); + expects.add("this is a bold star: <strong>*</strong> "); + tests.add("this is two bold stars: **** "); + expects.add("this is two bold stars: <strong>**</strong> "); + test(tests, expects); + } + + public void testMultiline() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is not *not\nbold*"); + expects.add("This is not *not\nbold*"); + test(tests, expects); + } + + public void testTimeComplexity() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + // Something like this should be (negatively) matched in linear time, thus it should take no + // time. If the build takes a lot, then the regular expression is not in linear time, thus + // wrong. + String text = "*"; + for (int i = 0; i < 1000; ++i) { + text += "abc *"; + } + tests.add(text); + expects.add(text); + long startTime = System.currentTimeMillis(); + test(tests, expects); + // Even on very slow systems this should not take more than one second. Putting 10 seconds, + // just to be sure we don't get false test errors. + assertTrue(System.currentTimeMillis() - startTime < 10000); + } +} Property changes on: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/BoldTest.java ___________________________________________________________________ Name: svn:eol-style + native Added: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/ItalicsTest.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/ItalicsTest.java (rev 0) +++ xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/ItalicsTest.java 2008-02-11 11:09:32 UTC (rev 7484) @@ -0,0 +1,137 @@ +package com.xpn.xwiki.render.markup; + +import java.util.ArrayList; + +public class ItalicsTest extends SyntaxTestsParent +{ + protected void setUp() + { + super.setUp(); + } + + public void testNotTriggeredWithWhitespace() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is not ~~ italics ~~"); + expects.add("This is not ~~ italics ~~"); + tests.add("This is not ~~italics ~~"); + expects.add("This is not ~~italics ~~"); + tests.add("This is not ~~ italics~~"); + expects.add("This is not ~~ italics~~"); + test(tests, expects); + } + + public void testSimple() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is in ~~italics~~"); + expects.add("This is in <em>italics</em>"); + tests.add("This is ~~a~~ letter in italics"); + expects.add("This is <em>a</em> letter in italics"); + tests.add("~~a~~"); + expects.add("<em>a</em>"); + test(tests, expects); + } + + public void testThree() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is ~~a~~ short italics~~"); + expects.add("This is <em>a</em> short italics~~"); + tests.add("This is ~~all ~~ italics~~"); + expects.add("This is <em>all ~~ italics</em>"); + tests.add("This is ~~all ~~italics~~"); + expects.add("This is <em>all ~~italics</em>"); + tests.add("This is ~~one~~italics~~"); + expects.add("This is <em>one</em>italics~~"); + test(tests, expects); + } + + public void testMultiple() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("More ~~italics~~ on a ~~line~~"); + expects + .add("More <em>italics</em> on a <em>line</em>"); + test(tests, expects); + } + + public void testExtraTildeAreInside() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("The extra tilde are ~~~inside~~~"); + expects.add("The extra tilde are <em>~inside~</em>"); + tests.add("The extra tilde are ~~~ inside ~~~"); + expects.add("The extra tilde are <em>~ inside ~</em>"); + test(tests, expects); + } + + public void testWithoutWhitespace() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This~~is~~italics"); + expects.add("This<em>is</em>italics"); + test(tests, expects); + } + + public void testSequence() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("~~Eeny~~meeny~~miny~~moe~~"); + expects + .add("<em>Eeny</em>meeny<em>miny</em>moe~~"); + tests.add("~~ Eeny~~meeny~~miny~~moe~~"); + expects + .add("~~ Eeny<em>meeny</em>miny<em>moe</em>"); + test(tests, expects); + } + + public void testSeveralInARow() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("this is not in italics: ~~~~ "); + expects.add("this is not in italics: ~~~~ "); + tests.add("this is a tilde in italics: ~~~~~ "); + expects.add("this is a tilde in italics: <em>~</em> "); + tests.add("this is two tilde in italics: ~~~~~~ "); + expects.add("this is two tilde in italics: <em>~~</em> "); + test(tests, expects); + } + + public void testMultiline() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + tests.add("This is not ~~not\nitalics~~"); + expects.add("This is not ~~not\nitalics~~"); + test(tests, expects); + } + + public void testTimeComplexity() + { + ArrayList tests = new ArrayList(); + ArrayList expects = new ArrayList(); + // Something like this should be (negatively) matched in linear time, thus it should take no + // time. If the build takes a lot, then the regular expression is not in linear time, thus + // wrong. + String text = "~~"; + for (int i = 0; i < 1000; ++i) { + text += "abc~"; + } + tests.add(text); + expects.add(text); + long startTime = System.currentTimeMillis(); + test(tests, expects); + // Even on very slow systems this should not take more than one second. Putting 10 seconds, + // just to be sure we don't get false test errors. + assertTrue(System.currentTimeMillis() - startTime < 10000); + } +} Property changes on: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/ItalicsTest.java ___________________________________________________________________ Name: svn:eol-style + native Modified: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/StrikethroughTest.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/StrikethroughTest.java 2008-02-11 10:23:23 UTC (rev 7483) +++ xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/StrikethroughTest.java 2008-02-11 11:09:32 UTC (rev 7484) @@ -105,6 +105,8 @@ ArrayList expects = new ArrayList(); tests.add("-- this is a list item--"); expects.add("...<li>this is a list item--</li>..."); + tests.add("-- this is a list --item--"); + expects.add("...<li>this is a list <del>item</del></li>..."); test(tests, expects); } Modified: xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/UnderlineTest.java =================================================================== --- xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/UnderlineTest.java 2008-02-11 10:23:23 UTC (rev 7483) +++ xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/render/markup/UnderlineTest.java 2008-02-11 11:09:32 UTC (rev 7484) @@ -128,6 +128,12 @@ } tests.add(text); expects.add(text); + text = "__"; + for (int i = 0; i < 1000; ++i) { + text += "abc _ "; + } + tests.add(text); + expects.add(text); long startTime = System.currentTimeMillis(); test(tests, expects); // Even on very slow systems this should not take more than one second. Putting 10 seconds, _______________________________________________ notifications mailing list notifications@xwiki.org http://lists.xwiki.org/mailman/listinfo/notifications