Skip to content

Commit bf7b9f7

Browse files
committed
Added tests
1 parent 809e569 commit bf7b9f7

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@
216216
<version>1.14.4</version>
217217
<scope>test</scope>
218218
</dependency>
219+
<dependency>
220+
<groupId>org.junit.jupiter</groupId>
221+
<artifactId>junit-jupiter-params</artifactId>
222+
<version>5.14.4</version>
223+
<scope>test</scope>
224+
</dependency>
219225
<dependency>
220226
<groupId>org.awaitility</groupId>
221227
<artifactId>awaitility</artifactId>

‎src/test/java/com/github/underscore/LodashTest.java‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import static java.util.Collections.singletonList;
3434

3535
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.params.ParameterizedTest;
37+
import org.junit.jupiter.params.provider.CsvSource;
3638

3739
import java.io.IOException;
3840
import java.net.URISyntaxException;
@@ -1183,6 +1185,54 @@ void xmpToJson7() {
11831185
assertThrows(IllegalArgumentException.class, () -> U.xmlToJson("<Comment stringValue='a\"/>"));
11841186
}
11851187

1188+
@ParameterizedTest(name = "{0}")
1189+
@CsvSource(delimiter = '|', value = {
1190+
// input | expected (k=v,k=v)
1191+
"key=\"value\" | key=value",
1192+
"key='value' | key=value",
1193+
"a=\"1\" b='2' | a=1,b=2",
1194+
"key=\"it's a value\" | key=it's a value",
1195+
"key='say \"hi\"' | key=say \"hi\"",
1196+
"key=\"a=b=c\" | key=a=b=c",
1197+
"key=\"\" | key=",
1198+
" key =\"value\" | key=value",
1199+
"data-id=\"5\" | data-id=5",
1200+
"x==\"y\" | x=y",
1201+
"k=\"first\" k=\"second\" | k=second",
1202+
})
1203+
void parses(String input, String expected) {
1204+
assertEquals(parse(expected), Xml.parseAttributes(input));
1205+
}
1206+
1207+
@ParameterizedTest(name = "empty: \"{0}\"")
1208+
@CsvSource({
1209+
"''",
1210+
"\"orphan\"",
1211+
"lonekey",
1212+
"key=\"value",
1213+
})
1214+
void producesNothing(String input) {
1215+
assertTrue(Xml.parseAttributes(input).isEmpty());
1216+
}
1217+
1218+
@Test
1219+
void preservesInsertionOrder() {
1220+
assertEquals("[z, a, m]",
1221+
Xml.parseAttributes("z=\"1\" a=\"2\" m=\"3\"").keySet().toString());
1222+
}
1223+
1224+
// builds expected map from "k=v,k=v"
1225+
private static Map<String, String> parse(String s) {
1226+
Map<String, String> m = new LinkedHashMap<>();
1227+
if (s != null && !s.isEmpty()) {
1228+
for (String pair : s.split(",", -1)) {
1229+
int i = pair.indexOf('=');
1230+
m.put(pair.substring(0, i), pair.substring(i + 1));
1231+
}
1232+
}
1233+
return m;
1234+
}
1235+
11861236
@Test
11871237
void xmlToJsonMinimum() {
11881238
assertEquals(

0 commit comments

Comments
 (0)