Add test for fixed color code removal
[xudocci.git] / src / test / java / net / pterodactylus / irc / util / MessageCleanerTest.java
1 /*
2  * XdccDownloader - MessageCleanerTest.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.irc.util;
19
20 import static java.util.EnumSet.of;
21 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.bold;
22 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.clear;
23 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.color;
24 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.italics;
25 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.reverse;
26 import static net.pterodactylus.irc.util.MessageCleaner.Attributes.underline;
27 import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance;
28 import static org.hamcrest.MatcherAssert.assertThat;
29 import static org.hamcrest.Matchers.is;
30
31 import java.util.Collections;
32
33 import net.pterodactylus.irc.util.MessageCleaner.Attributes;
34
35 import org.junit.Test;
36
37 /**
38  * Tests for {@link MessageCleaner}.
39  *
40  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
41  */
42 public class MessageCleanerTest {
43
44         private final MessageCleaner messageCleaner = getDefaultInstance();
45
46         @Test
47         public void removeBoldFormatting() {
48                 assertThat(messageCleaner.clean("Text\u0002bold", of(bold)), is("Textbold"));
49         }
50
51         @Test
52         public void boldFormattingIsNotRemovedUnwanted() {
53                 assertThat(messageCleaner.clean("Text\u0002bold", Collections.<Attributes>emptySet()), is("Text\u0002bold"));
54         }
55
56         @Test
57         public void removeColorFormatting() {
58                 assertThat(messageCleaner.clean("Text\u0003!color", of(color)), is("Text!color"));
59                 assertThat(messageCleaner.clean("Text\u0003color", of(color)), is("Textcolor"));
60                 assertThat(messageCleaner.clean("Text\u00034color", of(color)), is("Textcolor"));
61                 assertThat(messageCleaner.clean("Text\u00034!color", of(color)), is("Text!color"));
62                 assertThat(messageCleaner.clean("Text\u000314color", of(color)), is("Textcolor"));
63                 assertThat(messageCleaner.clean("Text\u000318color", of(color)), is("Text8color"));
64                 assertThat(messageCleaner.clean("Text\u000399color", of(color)), is("Textcolor"));
65                 assertThat(messageCleaner.clean("Text\u00031,!color", of(color)), is("Text!color"));
66                 assertThat(messageCleaner.clean("Text\u00031,color", of(color)), is("Textcolor"));
67                 assertThat(messageCleaner.clean("Text\u00031,1!color", of(color)), is("Text!color"));
68                 assertThat(messageCleaner.clean("Text\u00031,1color", of(color)), is("Textcolor"));
69                 assertThat(messageCleaner.clean("Text\u00031,14color", of(color)), is("Textcolor"));
70                 assertThat(messageCleaner.clean("Text\u00031,18color", of(color)), is("Text8color"));
71                 assertThat(messageCleaner.clean("Text\u00031,99color", of(color)), is("Textcolor"));
72                 assertThat(messageCleaner.clean("Text\u000314,color", of(color)), is("Textcolor"));
73                 assertThat(messageCleaner.clean("Text\u000314,1color", of(color)), is("Textcolor"));
74                 assertThat(messageCleaner.clean("Text\u000314,14color", of(color)), is("Textcolor"));
75                 assertThat(messageCleaner.clean("Text\u000314,18color", of(color)), is("Text8color"));
76                 assertThat(messageCleaner.clean("Text\u000314,99color", of(color)), is("Textcolor"));
77                 assertThat(messageCleaner.clean("Text\u000399,99color", of(color)), is("Textcolor"));
78                 assertThat(messageCleaner.clean("Text\u000399,9color", of(color)), is("Textcolor"));
79                 assertThat(messageCleaner.clean("Text\u00039color", of(color)), is("Textcolor"));
80                 assertThat(messageCleaner.clean("Text\u00039,color", of(color)), is("Textcolor"));
81                 assertThat(messageCleaner.clean("Text\u000306color", of(color)), is("Textcolor"));
82         }
83
84         @Test
85         public void colorFormattingIsNotRemovedUnwanted() {
86                 assertThat(messageCleaner.clean("Text\u00034color", Collections.<Attributes>emptySet()), is("Text\u00034color"));
87                 assertThat(messageCleaner.clean("Text\u000314color", Collections.<Attributes>emptySet()), is("Text\u000314color"));
88                 assertThat(messageCleaner.clean("Text\u000318color", Collections.<Attributes>emptySet()), is("Text\u000318color"));
89                 assertThat(messageCleaner.clean("Text\u000399color", Collections.<Attributes>emptySet()), is("Text\u000399color"));
90                 assertThat(messageCleaner.clean("Text\u00031,color", Collections.<Attributes>emptySet()), is("Text\u00031,color"));
91                 assertThat(messageCleaner.clean("Text\u00031,1color", Collections.<Attributes>emptySet()), is("Text\u00031,1color"));
92                 assertThat(messageCleaner.clean("Text\u00031,14color", Collections.<Attributes>emptySet()), is("Text\u00031,14color"));
93                 assertThat(messageCleaner.clean("Text\u00031,18color", Collections.<Attributes>emptySet()), is("Text\u00031,18color"));
94                 assertThat(messageCleaner.clean("Text\u00031,99color", Collections.<Attributes>emptySet()), is("Text\u00031,99color"));
95                 assertThat(messageCleaner.clean("Text\u000314,color", Collections.<Attributes>emptySet()), is("Text\u000314,color"));
96                 assertThat(messageCleaner.clean("Text\u000314,1color", Collections.<Attributes>emptySet()), is("Text\u000314,1color"));
97                 assertThat(messageCleaner.clean("Text\u000314,14color", Collections.<Attributes>emptySet()), is("Text\u000314,14color"));
98                 assertThat(messageCleaner.clean("Text\u000314,18color", Collections.<Attributes>emptySet()), is("Text\u000314,18color"));
99                 assertThat(messageCleaner.clean("Text\u000314,99color", Collections.<Attributes>emptySet()), is("Text\u000314,99color"));
100                 assertThat(messageCleaner.clean("Text\u000399,99color", Collections.<Attributes>emptySet()), is("Text\u000399,99color"));
101                 assertThat(messageCleaner.clean("Text\u00039color", Collections.<Attributes>emptySet()), is("Text\u00039color"));
102         }
103
104         @Test
105         public void removeClearFormatting() {
106                 assertThat(messageCleaner.clean("Text\u000fclear", of(clear)), is("Textclear"));
107         }
108
109         @Test
110         public void clearFormattingIsNotRemovedUnwanted() {
111                 assertThat(messageCleaner.clean("Text\u000fclear", Collections.<Attributes>emptySet()), is("Text\u000fclear"));
112         }
113
114         @Test
115         public void removeUnderlineFormatting() {
116                 assertThat(messageCleaner.clean("Text\u001funderline", of(underline)), is("Textunderline"));
117         }
118
119         @Test
120         public void underlineFormattingIsNotRemovedUnwanted() {
121                 assertThat(messageCleaner.clean("Text\u001funderline", Collections.<Attributes>emptySet()), is("Text\u001funderline"));
122         }
123
124         @Test
125         public void removeReverseFormatting() {
126                 assertThat(messageCleaner.clean("Text\u0016reverse", of(reverse)), is("Textreverse"));
127         }
128
129         @Test
130         public void reverseFormattingIsNotRemovedUnwanted() {
131                 assertThat(messageCleaner.clean("Text\u0016reverse", Collections.<Attributes>emptySet()), is("Text\u0016reverse"));
132         }
133
134         @Test
135         public void removeItalicFormatting() {
136                 assertThat(messageCleaner.clean("Text\u001ditalics", of(italics)), is("Textitalics"));
137         }
138
139         @Test
140         public void italicFormattingIsNotRemovedUnwanted() {
141                 assertThat(messageCleaner.clean("Text\u001ditalics", Collections.<Attributes>emptySet()), is("Text\u001ditalics"));
142         }
143
144         @Test
145         public void removeEverything() {
146                 assertThat(messageCleaner.clean("a\u0002b\u00031,49\u001dd\u001fe\u0016f\u000fg"), is("ab9defg"));
147         }
148
149 }