Skip to content

Commit

Permalink
test: added tests for delimiter bugs
Browse files Browse the repository at this point in the history
Lines that either have no delimiter or that have multiple delimters
are not handled correctly. This commit adds tests for these cases.

See #20
  • Loading branch information
quintesse committed Feb 21, 2024
1 parent 86f4a85 commit 5e5162f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/org/codejive/properties/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,26 @@ void testCursor() throws IOException, URISyntaxException {
assertThat(c.prevCount(t -> true)).isEqualTo(p.last().position() + 1);
}

@Test
void testMissingDelim() throws IOException, URISyntaxException {
Properties p = Properties.loadProperties(getResource("/test-missingdelim.properties"));
assertThat(p).containsOnlyKeys("A-string-without-delimiter");
assertThat(p).containsEntry("A-string-without-delimiter", "");
StringWriter sw = new StringWriter();
p.store(sw);
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-missingdelim.properties")));
}

@Test
void testMultiDelim() throws IOException, URISyntaxException {
Properties p = Properties.loadProperties(getResource("/test-multidelim.properties"));
assertThat(p).containsOnlyKeys("key");
assertThat(p).containsEntry("key", "==value");
StringWriter sw = new StringWriter();
p.store(sw);
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-multidelim.properties")));
}

private Path getResource(String name) throws URISyntaxException {
return Paths.get(getClass().getResource(name).toURI());
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/codejive/properties/TestPropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class TestPropertiesParser {
+ " two \\\r\n"
+ "\tthree\n"
+ "key.4 = \\u1234\r\n"
+ "line-with-missing-delim \n"
+ "multidelim===value\n"
+ " # final comment";

@Test
Expand Down Expand Up @@ -81,6 +83,14 @@ void testTokens() throws IOException {
new Token(Type.SEPARATOR, " = "),
new Token(Type.VALUE, "\\u1234", "\u1234"),
new Token(Type.WHITESPACE, "\r\n"),
new Token(Type.KEY, "line-with-missing-delim"),
new Token(Type.SEPARATOR, " "),
new Token(Type.VALUE, ""),
new Token(Type.WHITESPACE, "\n"),
new Token(Type.KEY, "multidelim"),
new Token(Type.SEPARATOR, "="),
new Token(Type.VALUE, "==value"),
new Token(Type.WHITESPACE, "\n"),
new Token(Type.WHITESPACE, " "),
new Token(Type.COMMENT, "# final comment"));
}
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/test-missingdelim.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A-string-without-delimiter
1 change: 1 addition & 0 deletions src/test/resources/test-multidelim.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
key===value

0 comments on commit 5e5162f

Please sign in to comment.