From 018bdfd5338173c7fcaa263923be62b2773613ac Mon Sep 17 00:00:00 2001 From: Valentyn Kolesnikov Date: Wed, 11 Dec 2024 04:23:55 +0200 Subject: [PATCH] Added tests --- .../com/github/underscore/StringTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/test/java/com/github/underscore/StringTest.java b/src/test/java/com/github/underscore/StringTest.java index 4562c810..692f3891 100644 --- a/src/test/java/com/github/underscore/StringTest.java +++ b/src/test/java/com/github/underscore/StringTest.java @@ -2365,6 +2365,66 @@ void parseAttributes() { Xml.parseAttributes(" version = 1.0\" encoding= \"UTF-8\" ").toString()); } + @Test + void testSingleAttribute() { + Map result = Xml.parseAttributes("key1=\"value1\""); + assertEquals(Map.of("key1", "value1"), result); + } + + @Test + void testMultipleAttributes() { + Map result = Xml.parseAttributes("key1=\"value1\" key2=\"value2\""); + assertEquals(Map.of("key1", "value1", "key2", "value2"), result); + } + + @Test + void testAttributeWithSpaces() { + Map result = Xml.parseAttributes("key1=\"value with spaces\" key2=\"another value\""); + assertEquals(Map.of("key1", "value with spaces", "key2", "another value"), result); + } + + @Test + void testEmptyValue() { + Map result = Xml.parseAttributes("key1=\"value1\" key2=\"\""); + assertEquals(Map.of("key1", "value1", "key2", ""), result); + } + + @Test + void testAttributesWithoutSpaceSeparation() { + Map result = Xml.parseAttributes("key1=\"value1\"key2=\"value2\""); + assertEquals(Map.of("key1", "value1", "key2", "value2"), result); + } + + @Test + void testUnclosedQuotes() { + Map result = Xml.parseAttributes("key1=\"value1 key2=\"value2\""); + assertEquals(Map.of("key1", "value1 key2="), result); + } + + @Test + void testEqualsSignInValue() { + Map result = Xml.parseAttributes("key1=\"value=1\" key2=\"value=2\""); + assertEquals(Map.of("key1", "value=1", "key2", "value=2"), result); + } + + @Test + void testTrailingWhitespace() { + Map result = Xml.parseAttributes("key1=\"value1\" key2=\"value2\" "); + assertEquals(Map.of("key1", "value1", "key2", "value2"), result); + } + + @Test + void testLeadingWhitespace() { + Map result = Xml.parseAttributes(" key1=\"value1\" key2=\"value2\""); + assertEquals(Map.of("key1", "value1", "key2", "value2"), result); + } + + @Test + void testNoEqualsSign() { + Map result = Xml.parseAttributes("key1\"value1\" key2=\"value2\""); + assertEquals(Map.of("key1key2", "value1value2"), result); + } + @SuppressWarnings("unchecked") @Test void toJsonFromXml23() {