aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDanny van Heumen <danny@dannyvanheumen.nl>2014-03-29 16:50:19 +0100
committerDanny van Heumen <danny@dannyvanheumen.nl>2014-07-30 18:30:02 +0200
commit727ad04763b8287e9423c1f02565e65831a7415e (patch)
tree16d9f47539d4e2711658b25e0c88d7174c145edb /test
parentc3c6e2320349e3000405aab76c28b0e1b1345c77 (diff)
downloadjitsi-727ad04763b8287e9423c1f02565e65831a7415e.zip
jitsi-727ad04763b8287e9423c1f02565e65831a7415e.tar.gz
jitsi-727ad04763b8287e9423c1f02565e65831a7415e.tar.bz2
Implemented separate text formatter for IRC control codes.
Diffstat (limited to 'test')
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilderTest.java61
-rw-r--r--test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java10
2 files changed, 64 insertions, 7 deletions
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilderTest.java b/test/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilderTest.java
index 5f064e7..69a15bd 100644
--- a/test/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilderTest.java
+++ b/test/net/java/sip/communicator/impl/protocol/irc/FormattedTextBuilderTest.java
@@ -24,6 +24,17 @@ public class FormattedTextBuilderTest
Assert.assertEquals("Hello world!", formatted.done());
}
+ public void testPlainChar()
+ {
+ FormattedTextBuilder formatted = new FormattedTextBuilder();
+ formatted.append('H');
+ formatted.append('e');
+ formatted.append('l');
+ formatted.append('l');
+ formatted.append('o');
+ Assert.assertEquals("Hello", formatted.done());
+ }
+
public void testDoneWithoutFormatting()
{
FormattedTextBuilder formatted = new FormattedTextBuilder();
@@ -43,7 +54,53 @@ public class FormattedTextBuilderTest
public void testOnlyFormatting()
{
FormattedTextBuilder formatted = new FormattedTextBuilder();
- formatted.append("Hello world!");
- Assert.assertEquals("Hello world!", formatted.done());
+ formatted.apply(ControlChar.BOLD);
+ Assert.assertEquals("<b></b>", formatted.done());
+ }
+
+ public void testMixedFormattingContent()
+ {
+ FormattedTextBuilder formatted = new FormattedTextBuilder();
+ formatted.apply(ControlChar.BOLD);
+ formatted.append("Hello ");
+ formatted.apply(ControlChar.ITALICS);
+ formatted.append("world");
+ formatted.apply(ControlChar.BOLD);
+ formatted.append("!!!");
+ Assert.assertEquals("<b>Hello <i>world</i></b><i>!!!</i>",
+ formatted.done());
+ }
+
+ public void testToStringIntermediateResult()
+ {
+ FormattedTextBuilder formatted = new FormattedTextBuilder();
+ formatted.apply(ControlChar.BOLD);
+ formatted.append("Hello ");
+ formatted.apply(ControlChar.ITALICS);
+ Assert.assertEquals("<b>Hello <i>", formatted.toString());
+ formatted.append("world");
+ formatted.apply(ControlChar.BOLD);
+ formatted.append("!!!");
+ Assert.assertEquals("<b>Hello <i>world</i></b><i>!!!",
+ formatted.toString());
+ Assert.assertEquals("<b>Hello <i>world</i></b><i>!!!</i>",
+ formatted.done());
+ Assert.assertEquals("<b>Hello <i>world</i></b><i>!!!</i>",
+ formatted.toString());
+ }
+
+ public void testActiveFormatting()
+ {
+ FormattedTextBuilder formatted = new FormattedTextBuilder();
+ Assert.assertFalse(formatted.isActive(ControlChar.BOLD));
+ formatted.apply(ControlChar.BOLD);
+ Assert.assertTrue(formatted.isActive(ControlChar.BOLD));
+ formatted.append("Hello ");
+ Assert.assertFalse(formatted.isActive(ControlChar.ITALICS));
+ formatted.apply(ControlChar.ITALICS);
+ Assert.assertTrue(formatted.isActive(ControlChar.ITALICS));
+ formatted.done();
+ Assert.assertFalse(formatted.isActive(ControlChar.BOLD));
+ Assert.assertFalse(formatted.isActive(ControlChar.ITALICS));
}
}
diff --git a/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java b/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java
index 83cfc0c..c1934dd 100644
--- a/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java
+++ b/test/net/java/sip/communicator/impl/protocol/irc/UtilsTest.java
@@ -51,7 +51,7 @@ public class UtilsTest
public void testParseStringWithItalicsCode()
{
final String ircMessage =
- "My \u001Ditalics\u001D message \u001DITALICS!\u001D.";
+ "My \u0016italics\u0016 message \u0016ITALICS!\u0016.";
final String htmlMessage = "My <i>italics</i> message <i>ITALICS!</i>.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
}
@@ -125,7 +125,7 @@ public class UtilsTest
public void testParseSringAndNeutralizeWithNormalControlCode()
{
final String ircMessage =
- "My \u0002\u001D\u001F\u000304,12RED on Light Blue\u000F message.";
+ "My \u0002\u0016\u001F\u000304,12RED on Light Blue\u000F message.";
final String htmlMessage =
"My <b><i><u><font color=\"Red\" bgcolor=\"RoyalBlue\">RED on Light Blue</font></u></i></b> message.";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
@@ -134,7 +134,7 @@ public class UtilsTest
public void testParseStringWithUnclosedFormattingI()
{
final String ircMessage =
- "My \u0002\u001D\u001F\u000304,12RED on Light Blue message.";
+ "My \u0002\u0016\u001F\u000304,12RED on Light Blue message.";
final String htmlMessage =
"My <b><i><u><font color=\"Red\" bgcolor=\"RoyalBlue\">RED on Light Blue message.</font></u></i></b>";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
@@ -156,14 +156,14 @@ public class UtilsTest
public void testStackIncompatibleFormatToggling()
{
- final String ircMessage = "\u0002\u001D\u001FHello\u0002 W\u001Dorld\u001F!";
+ final String ircMessage = "\u0002\u0016\u001FHello\u0002 W\u0016orld\u001F!";
final String htmlMessage = "<b><i><u>Hello</u></i></b><i><u> W</u></i><u>orld</u>!";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
}
public void testColorSwitch()
{
- final String ircMessage = "\u000302,03Hello \u000308,09World\u000F!";
+ final String ircMessage = "\u000302,03Hello \u0003\u000308,09World\u000F!";
final String htmlMessage = "<font color=\"Navy\" bgcolor=\"Green\">Hello </font><font color=\"Yellow\" bgcolor=\"Lime\">World</font>!";
Assert.assertEquals(htmlMessage, Utils.parse(ircMessage));
}