From 727ad04763b8287e9423c1f02565e65831a7415e Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Sat, 29 Mar 2014 16:50:19 +0100 Subject: Implemented separate text formatter for IRC control codes. --- .../protocol/irc/FormattedTextBuilderTest.java | 61 +++++++++++++++++++++- .../communicator/impl/protocol/irc/UtilsTest.java | 10 ++-- 2 files changed, 64 insertions(+), 7 deletions(-) (limited to 'test/net/java/sip/communicator') 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("", 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("Hello world!!!", + formatted.done()); + } + + public void testToStringIntermediateResult() + { + FormattedTextBuilder formatted = new FormattedTextBuilder(); + formatted.apply(ControlChar.BOLD); + formatted.append("Hello "); + formatted.apply(ControlChar.ITALICS); + Assert.assertEquals("Hello ", formatted.toString()); + formatted.append("world"); + formatted.apply(ControlChar.BOLD); + formatted.append("!!!"); + Assert.assertEquals("Hello world!!!", + formatted.toString()); + Assert.assertEquals("Hello world!!!", + formatted.done()); + Assert.assertEquals("Hello world!!!", + 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 italics message ITALICS!."; 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 RED on Light Blue 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 RED on Light Blue message."; 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 = "Hello World!"; 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 = "Hello World!"; Assert.assertEquals(htmlMessage, Utils.parse(ircMessage)); } -- cgit v1.1