X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Firc%2Futil%2FMessageCleanerTest.java;h=986cbad38c0a825ed5fa7736f99bd368f6dfbc14;hb=0c607fe61d662a15fb9b6368a7f32b92a694096a;hp=6ab7b0a19e32f0a1906f717f6cdcae2307ebde48;hpb=b138564a95720fa1238256b219acb4c28019dae9;p=xudocci.git diff --git a/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java b/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java index 6ab7b0a..986cbad 100644 --- a/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java +++ b/src/test/java/net/pterodactylus/irc/util/MessageCleanerTest.java @@ -17,14 +17,22 @@ package net.pterodactylus.irc.util; +import static java.util.EnumSet.of; +import static net.pterodactylus.irc.util.MessageCleaner.Attributes.bold; +import static net.pterodactylus.irc.util.MessageCleaner.Attributes.clear; +import static net.pterodactylus.irc.util.MessageCleaner.Attributes.color; +import static net.pterodactylus.irc.util.MessageCleaner.Attributes.italics; +import static net.pterodactylus.irc.util.MessageCleaner.Attributes.reverse; +import static net.pterodactylus.irc.util.MessageCleaner.Attributes.underline; +import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import java.util.EnumSet; +import java.util.Collections; import net.pterodactylus.irc.util.MessageCleaner.Attributes; -import org.testng.annotations.Test; +import org.junit.Test; /** * Tests for {@link MessageCleaner}. @@ -33,62 +41,103 @@ import org.testng.annotations.Test; */ public class MessageCleanerTest { - /** Tests removal of {@link Attributes#bold} formatting. */ - @Test - public void testRemoveBold() { - MessageCleaner messageCleander = MessageCleaner.getDefaultInstance(); - String clean; - - clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.bold)); - assertThat(clean, is("This contains bold characters.")); + private final MessageCleaner messageCleaner = getDefaultInstance(); - clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.bold)); - assertThat(clean, is("This contains bold and \u00034color\u0003 characters.")); + @Test + public void removeBoldFormatting() { + assertThat(messageCleaner.clean("Text\u0002bold", of(bold)), is("Textbold")); } - /** Tests removal of {@link Attributes#color} formatting. */ @Test - public void testRemoveColors() { - MessageCleaner messageCleander = MessageCleaner.getDefaultInstance(); - String clean; + public void boldFormattingIsNotRemovedUnwanted() { + assertThat(messageCleaner.clean("Text\u0002bold", Collections.emptySet()), is("Text\u0002bold")); + } - clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.color)); - assertThat(clean, is("This contains \u0002bold\u0002 characters.")); + @Test + public void removeColorFormatting() { + assertThat(messageCleaner.clean("Text\u0003!color", of(color)), is("Text!color")); + assertThat(messageCleaner.clean("Text\u0003color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00034color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00034!color", of(color)), is("Text!color")); + assertThat(messageCleaner.clean("Text\u000314color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000318color", of(color)), is("Text8color")); + assertThat(messageCleaner.clean("Text\u000399color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00031,!color", of(color)), is("Text!color")); + assertThat(messageCleaner.clean("Text\u00031,color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00031,1!color", of(color)), is("Text!color")); + assertThat(messageCleaner.clean("Text\u00031,1color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00031,14color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00031,18color", of(color)), is("Text8color")); + assertThat(messageCleaner.clean("Text\u00031,99color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000314,color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000314,1color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000314,14color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000314,18color", of(color)), is("Text8color")); + assertThat(messageCleaner.clean("Text\u000314,99color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000399,99color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u000399,9color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00039color", of(color)), is("Textcolor")); + assertThat(messageCleaner.clean("Text\u00039,color", of(color)), is("Textcolor")); + } - clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.color)); - assertThat(clean, is("This contains \u0002bold\u0002 and color characters.")); + @Test + public void colorFormattingIsNotRemovedUnwanted() { + assertThat(messageCleaner.clean("Text\u00034color", Collections.emptySet()), is("Text\u00034color")); + assertThat(messageCleaner.clean("Text\u000314color", Collections.emptySet()), is("Text\u000314color")); + assertThat(messageCleaner.clean("Text\u000318color", Collections.emptySet()), is("Text\u000318color")); + assertThat(messageCleaner.clean("Text\u000399color", Collections.emptySet()), is("Text\u000399color")); + assertThat(messageCleaner.clean("Text\u00031,color", Collections.emptySet()), is("Text\u00031,color")); + assertThat(messageCleaner.clean("Text\u00031,1color", Collections.emptySet()), is("Text\u00031,1color")); + assertThat(messageCleaner.clean("Text\u00031,14color", Collections.emptySet()), is("Text\u00031,14color")); + assertThat(messageCleaner.clean("Text\u00031,18color", Collections.emptySet()), is("Text\u00031,18color")); + assertThat(messageCleaner.clean("Text\u00031,99color", Collections.emptySet()), is("Text\u00031,99color")); + assertThat(messageCleaner.clean("Text\u000314,color", Collections.emptySet()), is("Text\u000314,color")); + assertThat(messageCleaner.clean("Text\u000314,1color", Collections.emptySet()), is("Text\u000314,1color")); + assertThat(messageCleaner.clean("Text\u000314,14color", Collections.emptySet()), is("Text\u000314,14color")); + assertThat(messageCleaner.clean("Text\u000314,18color", Collections.emptySet()), is("Text\u000314,18color")); + assertThat(messageCleaner.clean("Text\u000314,99color", Collections.emptySet()), is("Text\u000314,99color")); + assertThat(messageCleaner.clean("Text\u000399,99color", Collections.emptySet()), is("Text\u000399,99color")); + assertThat(messageCleaner.clean("Text\u00039color", Collections.emptySet()), is("Text\u00039color")); + } - clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters.", EnumSet.of(Attributes.color)); - assertThat(clean, is("This contains colorful 8shit and 8stuff and characters.")); + @Test + public void removeClearFormatting() { + assertThat(messageCleaner.clean("Text\u000fclear", of(clear)), is("Textclear")); } - /** Tests removal of {@link Attributes#clear} formatting. */ @Test - public void testRemoveClear() { - MessageCleaner messageCleander = MessageCleaner.getDefaultInstance(); - String clean; + public void clearFormattingIsNotRemovedUnwanted() { + assertThat(messageCleaner.clean("Text\u000fclear", Collections.emptySet()), is("Text\u000fclear")); + } - clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.", EnumSet.of(Attributes.clear)); - assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 characters.")); + @Test + public void removeUnderlineFormatting() { + assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline")); + } - clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters.", EnumSet.of(Attributes.clear)); - assertThat(clean, is("This contains \u0002bold\u0002 and \u00034color\u0003 and clear characters.")); + @Test + public void underlineFormattingIsNotRemovedUnwanted() { + assertThat(messageCleaner.clean("Text\u001funderline", Collections.emptySet()), is("Text\u001funderline")); } - /** Tests removal of all formatting. */ @Test - public void testRemoveAll() { - MessageCleaner messageCleander = MessageCleaner.getDefaultInstance(); - String clean; + public void removeReverseFormatting() { + assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse")); + } - clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters."); - assertThat(clean, is("This contains bold and color characters.")); + @Test + public void reverseFormattingIsNotRemovedUnwanted() { + assertThat(messageCleaner.clean("Text\u0016reverse", Collections.emptySet()), is("Text\u0016reverse")); + } - clean = messageCleander.clean("This contains \u00034,12colorful \u00039,18shit and \u000328stuff\u0003 and characters."); - assertThat(clean, is("This contains colorful 8shit and 8stuff and characters.")); + @Test + public void removeItalicFormatting() { + assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics")); + } - clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 and \u000fclear characters."); - assertThat(clean, is("This contains bold and color and clear characters.")); + @Test + public void italicFormattingIsNotRemovedUnwanted() { + assertThat(messageCleaner.clean("Text\u001ditalics", Collections.emptySet()), is("Text\u001ditalics")); } }