diff --git a/src/test/java/org/codejive/properties/TestProperties.java b/src/test/java/org/codejive/properties/TestProperties.java index c9f608f..4c51c72 100644 --- a/src/test/java/org/codejive/properties/TestProperties.java +++ b/src/test/java/org/codejive/properties/TestProperties.java @@ -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()); } diff --git a/src/test/java/org/codejive/properties/TestPropertiesParser.java b/src/test/java/org/codejive/properties/TestPropertiesParser.java index cf31786..d2f719b 100644 --- a/src/test/java/org/codejive/properties/TestPropertiesParser.java +++ b/src/test/java/org/codejive/properties/TestPropertiesParser.java @@ -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 @@ -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")); } diff --git a/src/test/resources/test-missingdelim.properties b/src/test/resources/test-missingdelim.properties new file mode 100644 index 0000000..32172df --- /dev/null +++ b/src/test/resources/test-missingdelim.properties @@ -0,0 +1 @@ +A-string-without-delimiter diff --git a/src/test/resources/test-multidelim.properties b/src/test/resources/test-multidelim.properties new file mode 100644 index 0000000..b95aa30 --- /dev/null +++ b/src/test/resources/test-multidelim.properties @@ -0,0 +1 @@ +key===value