Skip to content

Commit b5fc4a9

Browse files
committed
Added more tests
1 parent 134ceba commit b5fc4a9

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;
@@ -1185,6 +1187,54 @@ void xmpToJson7() {
11851187
IllegalArgumentException.class, () -> U.xmlToJson("<Comment stringValue='a\"/>"));
11861188
}
11871189

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

0 commit comments

Comments
 (0)