Skip to content

Commit 5e5162f

Browse files
committed
test: added tests for delimiter bugs
Lines that either have no delimiter or that have multiple delimters are not handled correctly. This commit adds tests for these cases. See #20
1 parent 86f4a85 commit 5e5162f

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/test/java/org/codejive/properties/TestProperties.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,26 @@ void testCursor() throws IOException, URISyntaxException {
671671
assertThat(c.prevCount(t -> true)).isEqualTo(p.last().position() + 1);
672672
}
673673

674+
@Test
675+
void testMissingDelim() throws IOException, URISyntaxException {
676+
Properties p = Properties.loadProperties(getResource("/test-missingdelim.properties"));
677+
assertThat(p).containsOnlyKeys("A-string-without-delimiter");
678+
assertThat(p).containsEntry("A-string-without-delimiter", "");
679+
StringWriter sw = new StringWriter();
680+
p.store(sw);
681+
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-missingdelim.properties")));
682+
}
683+
684+
@Test
685+
void testMultiDelim() throws IOException, URISyntaxException {
686+
Properties p = Properties.loadProperties(getResource("/test-multidelim.properties"));
687+
assertThat(p).containsOnlyKeys("key");
688+
assertThat(p).containsEntry("key", "==value");
689+
StringWriter sw = new StringWriter();
690+
p.store(sw);
691+
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-multidelim.properties")));
692+
}
693+
674694
private Path getResource(String name) throws URISyntaxException {
675695
return Paths.get(getClass().getResource(name).toURI());
676696
}

src/test/java/org/codejive/properties/TestPropertiesParser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class TestPropertiesParser {
3030
+ " two \\\r\n"
3131
+ "\tthree\n"
3232
+ "key.4 = \\u1234\r\n"
33+
+ "line-with-missing-delim \n"
34+
+ "multidelim===value\n"
3335
+ " # final comment";
3436

3537
@Test
@@ -81,6 +83,14 @@ void testTokens() throws IOException {
8183
new Token(Type.SEPARATOR, " = "),
8284
new Token(Type.VALUE, "\\u1234", "\u1234"),
8385
new Token(Type.WHITESPACE, "\r\n"),
86+
new Token(Type.KEY, "line-with-missing-delim"),
87+
new Token(Type.SEPARATOR, " "),
88+
new Token(Type.VALUE, ""),
89+
new Token(Type.WHITESPACE, "\n"),
90+
new Token(Type.KEY, "multidelim"),
91+
new Token(Type.SEPARATOR, "="),
92+
new Token(Type.VALUE, "==value"),
93+
new Token(Type.WHITESPACE, "\n"),
8494
new Token(Type.WHITESPACE, " "),
8595
new Token(Type.COMMENT, "# final comment"));
8696
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A-string-without-delimiter
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key===value

0 commit comments

Comments
 (0)