|
@@ -33,13 +33,13 @@ import org.junit.Test;
|
33
|
33
|
import static org.junit.Assert.*;
|
34
|
34
|
|
35
|
35
|
public class ConfigFileTest {
|
36
|
|
-
|
|
36
|
+
|
37
|
37
|
private ConfigFile cf;
|
38
|
|
-
|
|
38
|
+
|
39
|
39
|
@Before
|
40
|
40
|
public void setUp() throws Exception {
|
41
|
41
|
cf = new ConfigFile(getClass().getResourceAsStream("test2.txt"));
|
42
|
|
- }
|
|
42
|
+ }
|
43
|
43
|
|
44
|
44
|
@Test
|
45
|
45
|
public void testRead() throws IOException, InvalidConfigFileException {
|
|
@@ -50,7 +50,7 @@ public class ConfigFileTest {
|
50
|
50
|
public void testWrite() throws IOException {
|
51
|
51
|
cf.write();
|
52
|
52
|
}
|
53
|
|
-
|
|
53
|
+
|
54
|
54
|
@Test
|
55
|
55
|
public void testDomains() throws IOException, InvalidConfigFileException {
|
56
|
56
|
cf.read();
|
|
@@ -60,7 +60,7 @@ public class ConfigFileTest {
|
60
|
60
|
assertTrue(cf.hasDomain("section one"));
|
61
|
61
|
assertFalse(cf.hasDomain("random domain"));
|
62
|
62
|
}
|
63
|
|
-
|
|
63
|
+
|
64
|
64
|
@Test
|
65
|
65
|
public void testKeyDomains() throws IOException, InvalidConfigFileException {
|
66
|
66
|
cf.read();
|
|
@@ -68,7 +68,7 @@ public class ConfigFileTest {
|
68
|
68
|
assertFalse(cf.isKeyDomain("section one point one"));
|
69
|
69
|
assertFalse(cf.isKeyDomain("section two"));
|
70
|
70
|
}
|
71
|
|
-
|
|
71
|
+
|
72
|
72
|
@Test
|
73
|
73
|
public void testFlatDomains() throws IOException, InvalidConfigFileException {
|
74
|
74
|
cf.read();
|
|
@@ -76,9 +76,9 @@ public class ConfigFileTest {
|
76
|
76
|
assertTrue(cf.isFlatDomain("section alpha"));
|
77
|
77
|
assertTrue(cf.isFlatDomain("section one point one"));
|
78
|
78
|
assertFalse(cf.isFlatDomain("section one"));
|
79
|
|
- assertFalse(cf.hasDomain("random domain"));
|
|
79
|
+ assertFalse(cf.hasDomain("random domain"));
|
80
|
80
|
}
|
81
|
|
-
|
|
81
|
+
|
82
|
82
|
@Test
|
83
|
83
|
public void testFlatDomainContents() throws IOException, InvalidConfigFileException {
|
84
|
84
|
cf.read();
|
|
@@ -86,7 +86,7 @@ public class ConfigFileTest {
|
86
|
86
|
assertEquals("line 1", cf.getFlatDomain("section alpha").get(0));
|
87
|
87
|
assertEquals("line 2", cf.getFlatDomain("section alpha").get(1));
|
88
|
88
|
}
|
89
|
|
-
|
|
89
|
+
|
90
|
90
|
@Test
|
91
|
91
|
public void testKeyDomainContents() throws IOException, InvalidConfigFileException {
|
92
|
92
|
cf.read();
|
|
@@ -95,7 +95,7 @@ public class ConfigFileTest {
|
95
|
95
|
assertEquals("two", cf.getKeyDomain("section one").get("2"));
|
96
|
96
|
assertEquals("three", cf.getKeyDomain("section one").get("3"));
|
97
|
97
|
}
|
98
|
|
-
|
|
98
|
+
|
99
|
99
|
@Test
|
100
|
100
|
public void testColons() throws IOException, InvalidConfigFileException {
|
101
|
101
|
final File file = File.createTempFile("DMDirc.unittest", null);
|
|
@@ -106,17 +106,17 @@ public class ConfigFileTest {
|
106
|
106
|
data.put("test3", "hello:");
|
107
|
107
|
config.addDomain("test", data);
|
108
|
108
|
config.write();
|
109
|
|
-
|
|
109
|
+
|
110
|
110
|
config = new ConfigFile(file);
|
111
|
111
|
config.read();
|
112
|
|
-
|
|
112
|
+
|
113
|
113
|
assertTrue(config.isKeyDomain("test"));
|
114
|
114
|
data = config.getKeyDomain("test");
|
115
|
115
|
assertEquals("hello", data.get("test1"));
|
116
|
116
|
assertEquals("hello", data.get("test:2"));
|
117
|
117
|
assertEquals("hello:", data.get("test3"));
|
118
|
118
|
}
|
119
|
|
-
|
|
119
|
+
|
120
|
120
|
@Test
|
121
|
121
|
public void testEquals() throws IOException, InvalidConfigFileException {
|
122
|
122
|
final File file = File.createTempFile("DMDirc.unittest", null);
|
|
@@ -127,17 +127,17 @@ public class ConfigFileTest {
|
127
|
127
|
data.put("test3", "hello=");
|
128
|
128
|
config.addDomain("test", data);
|
129
|
129
|
config.write();
|
130
|
|
-
|
|
130
|
+
|
131
|
131
|
config = new ConfigFile(file);
|
132
|
132
|
config.read();
|
133
|
|
-
|
|
133
|
+
|
134
|
134
|
assertTrue(config.isKeyDomain("test"));
|
135
|
135
|
data = config.getKeyDomain("test");
|
136
|
136
|
assertEquals("hello", data.get("test1"));
|
137
|
137
|
assertEquals("hello", data.get("test=2"));
|
138
|
138
|
assertEquals("hello=", data.get("test3"));
|
139
|
139
|
}
|
140
|
|
-
|
|
140
|
+
|
141
|
141
|
@Test
|
142
|
142
|
public void testNewlines() throws IOException, InvalidConfigFileException {
|
143
|
143
|
final File file = File.createTempFile("DMDirc.unittest", null);
|
|
@@ -149,10 +149,10 @@ public class ConfigFileTest {
|
149
|
149
|
data.put("test4", "hello\r\ngoodbye");
|
150
|
150
|
config.addDomain("test", data);
|
151
|
151
|
config.write();
|
152
|
|
-
|
|
152
|
+
|
153
|
153
|
config = new ConfigFile(file);
|
154
|
154
|
config.read();
|
155
|
|
-
|
|
155
|
+
|
156
|
156
|
assertTrue(config.isKeyDomain("test"));
|
157
|
157
|
data = config.getKeyDomain("test");
|
158
|
158
|
assertEquals("hello", data.get("test1"));
|
|
@@ -160,7 +160,7 @@ public class ConfigFileTest {
|
160
|
160
|
assertEquals("hello\n", data.get("test3"));
|
161
|
161
|
assertEquals("hello\r\ngoodbye", data.get("test4"));
|
162
|
162
|
}
|
163
|
|
-
|
|
163
|
+
|
164
|
164
|
@Test
|
165
|
165
|
public void testBackslash() throws IOException, InvalidConfigFileException {
|
166
|
166
|
final File file = File.createTempFile("DMDirc.unittest", null);
|
|
@@ -171,17 +171,17 @@ public class ConfigFileTest {
|
171
|
171
|
data.put("test3\\", "hello");
|
172
|
172
|
config.addDomain("test", data);
|
173
|
173
|
config.write();
|
174
|
|
-
|
|
174
|
+
|
175
|
175
|
config = new ConfigFile(file);
|
176
|
176
|
config.read();
|
177
|
|
-
|
|
177
|
+
|
178
|
178
|
assertTrue(config.isKeyDomain("test"));
|
179
|
179
|
data = config.getKeyDomain("test");
|
180
|
180
|
assertEquals("hello\\", data.get("test1"));
|
181
|
181
|
assertEquals("\\nhello", data.get("test2"));
|
182
|
182
|
assertEquals("hello", data.get("test3\\"));
|
183
|
183
|
}
|
184
|
|
-
|
|
184
|
+
|
185
|
185
|
@Test
|
186
|
186
|
public void testHash() throws IOException, InvalidConfigFileException {
|
187
|
187
|
final File file = File.createTempFile("DMDirc.unittest", null);
|
|
@@ -192,30 +192,30 @@ public class ConfigFileTest {
|
192
|
192
|
data.put("test3", "#hello");
|
193
|
193
|
config.addDomain("test", data);
|
194
|
194
|
config.write();
|
195
|
|
-
|
|
195
|
+
|
196
|
196
|
config = new ConfigFile(file);
|
197
|
197
|
config.read();
|
198
|
|
-
|
|
198
|
+
|
199
|
199
|
assertTrue(config.isKeyDomain("test"));
|
200
|
200
|
data = config.getKeyDomain("test");
|
201
|
201
|
assertEquals("hello", data.get("test1#"));
|
202
|
202
|
assertEquals("hello", data.get("#test2"));
|
203
|
203
|
assertEquals("#hello", data.get("test3"));
|
204
|
|
- }
|
205
|
|
-
|
|
204
|
+ }
|
|
205
|
+
|
206
|
206
|
@Test
|
207
|
207
|
public void testEscape() {
|
208
|
208
|
final String input = "blah blah\\foo\r\nbar=:";
|
209
|
209
|
final String output = "blah blah\\\\foo\\r\\nbar\\=\\:";
|
210
|
210
|
assertEquals(output, ConfigFile.escape(input));
|
211
|
211
|
}
|
212
|
|
-
|
|
212
|
+
|
213
|
213
|
@Test
|
214
|
214
|
public void testUnescape() {
|
215
|
215
|
final String input = "blah blah\\foo\r\nbar=:";
|
216
|
216
|
assertEquals(input, ConfigFile.unescape(ConfigFile.escape(input)));
|
217
|
217
|
}
|
218
|
|
-
|
|
218
|
+
|
219
|
219
|
@Test
|
220
|
220
|
public void testDelete() throws IOException {
|
221
|
221
|
final File file = File.createTempFile("DMDirc_unittest", null);
|
|
@@ -225,12 +225,12 @@ public class ConfigFileTest {
|
225
|
225
|
config.delete();
|
226
|
226
|
assertFalse(file.exists());
|
227
|
227
|
}
|
228
|
|
-
|
|
228
|
+
|
229
|
229
|
@Test
|
230
|
230
|
public void testDuplicateKeys() throws IOException, InvalidConfigFileException {
|
231
|
231
|
final ConfigFile file = new ConfigFile(getClass().getResourceAsStream("test2.txt"));
|
232
|
232
|
file.read();
|
233
|
|
-
|
|
233
|
+
|
234
|
234
|
assertTrue(file.isKeyDomain("section one"));
|
235
|
235
|
assertEquals(3, file.getKeyDomain("section one").size());
|
236
|
236
|
assertTrue(file.isFlatDomain("section one point one"));
|