diff options
author | Shawn O. Pearce <sop@google.com> | 2009-11-05 15:51:59 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-11-05 15:51:59 -0800 |
commit | 96040217f6f7a2bfcc7d40e8ccbb38c3527a93ba (patch) | |
tree | 137daa97eb644402a5a92457405d01913aba1540 | |
parent | 9aae468486433c1827ddeaa2b2c149c4c3fb0fd7 (diff) | |
download | gwtexpui-96040217f6f7a2bfcc7d40e8ccbb38c3527a93ba.tar.gz |
Add tests for SafeHtml linkify and wikify
Test the common filter rules, as we have had some trouble with
these patterns in the past.
Change-Id: I6c45e3bea762fa19a8042524799a8bae2fe94728
Signed-off-by: Shawn O. Pearce <sop@google.com>
4 files changed, 337 insertions, 0 deletions
diff --git a/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_LinkifyTest.java b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_LinkifyTest.java new file mode 100644 index 0000000..365db0b --- /dev/null +++ b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_LinkifyTest.java @@ -0,0 +1,58 @@ +// Copyright (C) 2009 The Android Open Source Project +// +// Licensed 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.google.gwtexpui.safehtml.client; + +import junit.framework.TestCase; + +public class SafeHtml_LinkifyTest extends TestCase { + public void testLinkify_SimpleHttp1() { + final SafeHtml o = html("A http://go.here/ B"); + final SafeHtml n = o.linkify(); + assertNotSame(o, n); + assertEquals("A <a href=\"http://go.here/\">http://go.here/</a> B", n.asString()); + } + + public void testLinkify_SimpleHttps2() { + final SafeHtml o = html("A https://go.here/ B"); + final SafeHtml n = o.linkify(); + assertNotSame(o, n); + assertEquals("A <a href=\"https://go.here/\">https://go.here/</a> B", n.asString()); + } + + public void testLinkify_Parens1() { + final SafeHtml o = html("A (http://go.here/) B"); + final SafeHtml n = o.linkify(); + assertNotSame(o, n); + assertEquals("A (<a href=\"http://go.here/\">http://go.here/</a>) B", n.asString()); + } + + public void testLinkify_Parens() { + final SafeHtml o = html("A http://go.here/#m() B"); + final SafeHtml n = o.linkify(); + assertNotSame(o, n); + assertEquals("A <a href=\"http://go.here/#m()\">http://go.here/#m()</a> B", n.asString()); + } + + public void testLinkify_AngleBrackets1() { + final SafeHtml o = html("A <http://go.here/> B"); + final SafeHtml n = o.linkify(); + assertNotSame(o, n); + assertEquals("A <<a href=\"http://go.here/\">http://go.here/</a>> B", n.asString()); + } + + private static SafeHtml html(String text) { + return new SafeHtmlBuilder().append(text).toSafeHtml(); + } +} diff --git a/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyListTest.java b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyListTest.java new file mode 100644 index 0000000..c3a0871 --- /dev/null +++ b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyListTest.java @@ -0,0 +1,104 @@ +// Copyright (C) 2009 The Android Open Source Project +// +// Licensed 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 "<p>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.google.gwtexpui.safehtml.client; + +import junit.framework.TestCase; + +public class SafeHtml_WikifyListTest extends TestCase { + private static final String BEGIN_LIST = "<ul class=\"gwtexpui-SafeHtml-WikiList\">"; + private static final String END_LIST = "</ul>"; + + private static String item(String raw) { + return "<li>" + raw + "</li>"; + } + + public void testBulletList1() { + final SafeHtml o = html("A\n\n* line 1\n* 2nd line"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>"// + + BEGIN_LIST // + + item("line 1") // + + item("2nd line") // + + END_LIST // + , n.asString()); + } + + public void testBulletList2() { + final SafeHtml o = html("A\n\n* line 1\n* 2nd line\n\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>"// + + BEGIN_LIST // + + item("line 1") // + + item("2nd line") // + + END_LIST // + + "<p>B</p>" // + , n.asString()); + } + + public void testBulletList3() { + final SafeHtml o = html("* line 1\n* 2nd line\n\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals(BEGIN_LIST // + + item("line 1") // + + item("2nd line") // + + END_LIST // + + "<p>B</p>" // + , n.asString()); + } + + public void testDashList1() { + final SafeHtml o = html("A\n\n- line 1\n- 2nd line"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>"// + + BEGIN_LIST // + + item("line 1") // + + item("2nd line") // + + END_LIST // + , n.asString()); + } + + public void testDashList2() { + final SafeHtml o = html("A\n\n- line 1\n- 2nd line\n\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>"// + + BEGIN_LIST // + + item("line 1") // + + item("2nd line") // + + END_LIST // + + "<p>B</p>" // + , n.asString()); + } + + public void testDashList3() { + final SafeHtml o = html("- line 1\n- 2nd line\n\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals(BEGIN_LIST // + + item("line 1") // + + item("2nd line") // + + END_LIST // + + "<p>B</p>" // + , n.asString()); + } + + private static SafeHtml html(String text) { + return new SafeHtmlBuilder().append(text).toSafeHtml(); + } +} diff --git a/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyPreformatTest.java b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyPreformatTest.java new file mode 100644 index 0000000..27e7565 --- /dev/null +++ b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyPreformatTest.java @@ -0,0 +1,82 @@ +// Copyright (C) 2009 The Android Open Source Project +// +// Licensed 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 "<p>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.google.gwtexpui.safehtml.client; + +import junit.framework.TestCase; + +public class SafeHtml_WikifyPreformatTest extends TestCase { + private static final String B = "<span class=\"gwtexpui-SafeHtml-WikiPreFormat\">"; + private static final String E = "</span><br />"; + + private static String pre(String raw) { + return B + raw + E; + } + + public void testPreformat1() { + final SafeHtml o = html("A\n\n This is pre\n formatted"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>"// + + "<p>" // + + pre(" This is pre") // + + pre(" formatted") // + + "</p>" // + , n.asString()); + } + + public void testPreformat2() { + final SafeHtml o = html("A\n\n This is pre\n formatted\n\nbut this is not"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>" // + + "<p>" // + + pre(" This is pre") // + + pre(" formatted") // + + "</p>" // + + "<p>but this is not</p>" // + , n.asString()); + } + + public void testPreformat3() { + final SafeHtml o = html("A\n\n Q\n <R>\n S\n\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A</p>" // + + "<p>" // + + pre(" Q") // + + pre(" <R>") // + + pre(" S") // + + "</p>" // + + "<p>B</p>" // + , n.asString()); + } + + public void testPreformat4() { + final SafeHtml o = html(" Q\n <R>\n S\n\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>" // + + pre(" Q") // + + pre(" <R>") // + + pre(" S") // + + "</p>" // + + "<p>B</p>" // + , n.asString()); + } + + private static SafeHtml html(String text) { + return new SafeHtmlBuilder().append(text).toSafeHtml(); + } +} diff --git a/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyTest.java b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyTest.java new file mode 100644 index 0000000..9b39b77 --- /dev/null +++ b/src/test/java/com/google/gwtexpui/safehtml/client/SafeHtml_WikifyTest.java @@ -0,0 +1,93 @@ +// Copyright (C) 2009 The Android Open Source Project +// +// Licensed 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 "<p>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.google.gwtexpui.safehtml.client; + +import junit.framework.TestCase; + +public class SafeHtml_WikifyTest extends TestCase { + public void testWikify_OneLine1() { + final SafeHtml o = html("A B"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A B</p>", n.asString()); + } + + public void testWikify_OneLine2() { + final SafeHtml o = html("A B\n"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A B\n</p>", n.asString()); + } + + public void testWikify_OneParagraph1() { + final SafeHtml o = html("A\nB"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A\nB</p>", n.asString()); + } + + public void testWikify_OneParagraph2() { + final SafeHtml o = html("A\nB\n"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A\nB\n</p>", n.asString()); + } + + public void testWikify_TwoParagraphs() { + final SafeHtml o = html("A\nB\n\nC\nD"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A\nB</p><p>C\nD</p>", n.asString()); + } + + public void testLinkify_SimpleHttp1() { + final SafeHtml o = html("A http://go.here/ B"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A <a href=\"http://go.here/\">http://go.here/</a> B</p>", n.asString()); + } + + public void testLinkify_SimpleHttps2() { + final SafeHtml o = html("A https://go.here/ B"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A <a href=\"https://go.here/\">https://go.here/</a> B</p>", n.asString()); + } + + public void testLinkify_Parens1() { + final SafeHtml o = html("A (http://go.here/) B"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A (<a href=\"http://go.here/\">http://go.here/</a>) B</p>", n.asString()); + } + + public void testLinkify_Parens() { + final SafeHtml o = html("A http://go.here/#m() B"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A <a href=\"http://go.here/#m()\">http://go.here/#m()</a> B</p>", n.asString()); + } + + public void testLinkify_AngleBrackets1() { + final SafeHtml o = html("A <http://go.here/> B"); + final SafeHtml n = o.wikify(); + assertNotSame(o, n); + assertEquals("<p>A <<a href=\"http://go.here/\">http://go.here/</a>> B</p>", n.asString()); + } + + private static SafeHtml html(String text) { + return new SafeHtmlBuilder().append(text).toSafeHtml(); + } +} |