mirror of https://github.com/sipwise/jitsi.git
A more advanced pattern that tries to take quotes into account. In case this pattern does not work, this commit can be reverted and instead a simpler pattern is used that relies on html tags being opened and closed with < and > brackets. It assumes that < and > are always part of HTML tags so any textual (content) occurrence should be replaced with html entities (escaping).cefexperiments
parent
61a9ae412d
commit
ff00a10765
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.impl.gui.main.chat;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.*;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
/**
|
||||
* Tests for functionality of the ChatConversationPanel.
|
||||
*
|
||||
* @author Danny van Heumen
|
||||
*/
|
||||
public class ChatConversationPanelTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for various better and worse pieces of HTML to test the resilience
|
||||
* of the pattern.
|
||||
*/
|
||||
public void testHtmlSnippetsOnTextToReplacePattern()
|
||||
{
|
||||
final HashMap<String, String[]> tests = new HashMap<String, String[]>();
|
||||
tests.put("just a piece of text",
|
||||
new String[] {"just a piece of text", ""});
|
||||
tests.put(">another piece of text",
|
||||
new String[] {">another piece of text", ""});
|
||||
tests.put("<another piece of text",
|
||||
new String[] {"", ""});
|
||||
tests.put("<another piece> of text",
|
||||
new String[] {"", " of text", ""});
|
||||
tests.put("<another attribute=\"piece\"> of text",
|
||||
new String[] {"", " of text", ""});
|
||||
tests.put("<another attribute=\"<\"> of text",
|
||||
new String[] {"", " of text", ""});
|
||||
tests.put("piece of text<tag>'nother piece</tag>stuff at the end",
|
||||
new String[]
|
||||
{"piece of text", "'nother piece", "stuff at the end", "" });
|
||||
tests.put("<br />", new String[] {"", ""});
|
||||
tests.put("<br />text", new String[] {"", "text", ""});
|
||||
tests.put("some<br />text", new String[] {"some", "text", ""});
|
||||
tests.put("<img src=\"blablabla.jpg\" />",
|
||||
new String[] {"", ""});
|
||||
tests.put("some<img src=\"blablabla.jpg\" />",
|
||||
new String[] {"some", ""});
|
||||
tests.put("some<img src=\"blablabla.jpg\" />foobar",
|
||||
new String[] {"some", "foobar", ""});
|
||||
tests.put(">some text between cut-off tags<",
|
||||
new String[] {">some text between cut-off tags", ""});
|
||||
tests.put("<some text between pointy brackets>",
|
||||
new String[] {"", ""});
|
||||
tests.put("fake <br/> tag",
|
||||
new String[] {"fake <br/> tag", ""});
|
||||
tests.put("fake <br/> tag",
|
||||
new String[] {"fake <br/> tag", ""});
|
||||
tests.put("fake <br/> tag",
|
||||
new String[] {"fake ", ""});
|
||||
tests.put("a piece <b>of <u>formatted</u> text for </b>testing...",
|
||||
new String[] {"a piece ", "of ", "formatted", " text for ",
|
||||
"testing...", ""});
|
||||
tests.put("a piece <a href=\"www.google.com?query=blabla#blabla\">"
|
||||
+ "www.google.com</a> hyperlinked text",
|
||||
new String[] {"a piece ", "www.google.com", " hyperlinked text",
|
||||
""});
|
||||
tests.put("<another attribute=\">\"> of text",
|
||||
new String[] {"", " of text", ""});
|
||||
tests.put("<a name=\"Click here ><\" href=\"www.google.com\">"
|
||||
+ "For a treat</a> or something ...",
|
||||
new String[] {"", "For a treat", " or something ...", ""});
|
||||
tests.put("and here is <a \"some weird syntax\"> to test",
|
||||
new String[] {"and here is ", " to test", ""});
|
||||
tests.put("and here <option name=\"opt\" checked> checked option",
|
||||
new String[] {"and here ", " checked option", ""});
|
||||
tests.put("incomplete <img href=\"www.goo",
|
||||
new String[] {"incomplete ", ""});
|
||||
tests.put("incomplete <img href=\"www.goo > <a href=\">test",
|
||||
new String[] {"incomplete ", "test", ""});
|
||||
tests.put("\"blablabla\">See if this text is ignored ...",
|
||||
new String[] {"\"blablabla\">See if this text is ignored ...", ""});
|
||||
tests.put("bla\">See if this<img src=\"test1\">test2</img>",
|
||||
new String[] {"bla\">See if this", "test2", ""});
|
||||
tests.put("<the-end", new String[] {"", ""});
|
||||
tests.put("<this-is-not-a-tag>",
|
||||
new String[] {"<this-is-not-a-tag>", ""});
|
||||
tests.put("<this-is-a-tag>", new String[] {"", ""});
|
||||
|
||||
for (final Entry<String, String[]> entry : tests.entrySet())
|
||||
{
|
||||
final String input = entry.getKey();
|
||||
int index = 0;
|
||||
final Matcher matcher =
|
||||
ChatConversationPanel.TEXT_TO_REPLACE_PATTERN.matcher(input);
|
||||
while (matcher.find())
|
||||
{
|
||||
final String piece = matcher.group(1);
|
||||
Assert.assertEquals("INPUT [[" + input + "]]:",
|
||||
entry.getValue()[index], piece);
|
||||
index++;
|
||||
}
|
||||
// ensure that we have checked all predicted pieces
|
||||
Assert.assertEquals(entry.getValue().length, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue