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;
*/
public class MessageCleanerTest {
- /** Tests removal of {@link Attributes#bold} formatting. */
- @Test
- public void testRemoveBold() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
+ private final MessageCleaner messageCleaner = getDefaultInstance();
- clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.bold));
- assertThat(clean, is("This contains bold characters."));
+ @Test
+ public void removeBoldFormatting() {
+ assertThat(messageCleaner.clean("Text\u0002bold", of(bold)), is("Textbold"));
+ }
- 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 boldFormattingIsNotRemovedUnwanted() {
+ assertThat(messageCleaner.clean("Text\u0002bold", Collections.<Attributes>emptySet()), is("Text\u0002bold"));
}
- /** Tests removal of {@link Attributes#color} formatting. */
@Test
- public void testRemoveColors() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
+ 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"));
+ assertThat(messageCleaner.clean("Text\u000306color", of(color)), is("Textcolor"));
+ }
- clean = messageCleander.clean("This contains \u0002bold\u0002 characters.", EnumSet.of(Attributes.color));
- assertThat(clean, is("This contains \u0002bold\u0002 characters."));
+ @Test
+ public void colorFormattingIsNotRemovedUnwanted() {
+ assertThat(messageCleaner.clean("Text\u00034color", Collections.<Attributes>emptySet()), is("Text\u00034color"));
+ assertThat(messageCleaner.clean("Text\u000314color", Collections.<Attributes>emptySet()), is("Text\u000314color"));
+ assertThat(messageCleaner.clean("Text\u000318color", Collections.<Attributes>emptySet()), is("Text\u000318color"));
+ assertThat(messageCleaner.clean("Text\u000399color", Collections.<Attributes>emptySet()), is("Text\u000399color"));
+ assertThat(messageCleaner.clean("Text\u00031,color", Collections.<Attributes>emptySet()), is("Text\u00031,color"));
+ assertThat(messageCleaner.clean("Text\u00031,1color", Collections.<Attributes>emptySet()), is("Text\u00031,1color"));
+ assertThat(messageCleaner.clean("Text\u00031,14color", Collections.<Attributes>emptySet()), is("Text\u00031,14color"));
+ assertThat(messageCleaner.clean("Text\u00031,18color", Collections.<Attributes>emptySet()), is("Text\u00031,18color"));
+ assertThat(messageCleaner.clean("Text\u00031,99color", Collections.<Attributes>emptySet()), is("Text\u00031,99color"));
+ assertThat(messageCleaner.clean("Text\u000314,color", Collections.<Attributes>emptySet()), is("Text\u000314,color"));
+ assertThat(messageCleaner.clean("Text\u000314,1color", Collections.<Attributes>emptySet()), is("Text\u000314,1color"));
+ assertThat(messageCleaner.clean("Text\u000314,14color", Collections.<Attributes>emptySet()), is("Text\u000314,14color"));
+ assertThat(messageCleaner.clean("Text\u000314,18color", Collections.<Attributes>emptySet()), is("Text\u000314,18color"));
+ assertThat(messageCleaner.clean("Text\u000314,99color", Collections.<Attributes>emptySet()), is("Text\u000314,99color"));
+ assertThat(messageCleaner.clean("Text\u000399,99color", Collections.<Attributes>emptySet()), is("Text\u000399,99color"));
+ assertThat(messageCleaner.clean("Text\u00039color", Collections.<Attributes>emptySet()), is("Text\u00039color"));
+ }
- 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 removeClearFormatting() {
+ assertThat(messageCleaner.clean("Text\u000fclear", of(clear)), is("Textclear"));
+ }
- 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 clearFormattingIsNotRemovedUnwanted() {
+ assertThat(messageCleaner.clean("Text\u000fclear", Collections.<Attributes>emptySet()), is("Text\u000fclear"));
}
- /** Tests removal of {@link Attributes#clear} formatting. */
@Test
- public void testRemoveClear() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
+ public void removeUnderlineFormatting() {
+ assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline"));
+ }
- 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 underlineFormattingIsNotRemovedUnwanted() {
+ assertThat(messageCleaner.clean("Text\u001funderline", Collections.<Attributes>emptySet()), is("Text\u001funderline"));
+ }
- 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 removeReverseFormatting() {
+ assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
}
- /** Tests removal of all formatting. */
@Test
- public void testRemoveAll() {
- MessageCleaner messageCleander = MessageCleaner.getDefaultInstance();
- String clean;
+ public void reverseFormattingIsNotRemovedUnwanted() {
+ assertThat(messageCleaner.clean("Text\u0016reverse", Collections.<Attributes>emptySet()), is("Text\u0016reverse"));
+ }
- clean = messageCleander.clean("This contains \u0002bold\u0002 and \u00034color\u0003 characters.");
- assertThat(clean, is("This contains bold and color characters."));
+ @Test
+ public void removeItalicFormatting() {
+ assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));
+ }
- 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 italicFormattingIsNotRemovedUnwanted() {
+ assertThat(messageCleaner.clean("Text\u001ditalics", Collections.<Attributes>emptySet()), is("Text\u001ditalics"));
+ }
- 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 removeEverything() {
+ assertThat(messageCleaner.clean("a\u0002b\u00031,49\u001dd\u001fe\u0016f\u000fg"), is("ab9defg"));
}
}