-
Notifications
You must be signed in to change notification settings - Fork 0
Issue #48: Support wildcard iterations #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5e7d956
6440dd1
f4bb770
ff7d5ae
1cb5ee3
f4541e1
a4a6b02
63d88fb
5cdd248
dd139a0
636ed93
bbd74f8
d970dd6
ce0aa94
172ee43
9664e51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,10 @@ void flatMap() throws IllegalStateException, ParseException, IOException { | |
| jFlat = new JFlat(getResourceAsString("/large.json")); | ||
| jFlat.parse(); | ||
| assertEquals(getResourceAsString("/large-flatMap.txt"), jFlat.getFlatTree().toString()); | ||
|
|
||
| jFlat = new JFlat(getResourceAsString("/object-keys.json")); | ||
| jFlat.parse(); | ||
| assertEquals(getResourceAsString("/object-keys-flatMap.txt"), jFlat.getFlatTree().toString()); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -65,13 +69,14 @@ void csv() throws IllegalStateException, ParseException, IOException { | |
| simple.parse(); | ||
| assertEquals("[0];\n[1];\n", simple.toCSV("/", null, null).toString()); | ||
| assertEquals("[0]/attribute1;\n[1]/attribute1;\n", simple.toCSV("/attribute1", null, null).toString()); | ||
| assertEquals("[0]/attribute1;\n[1]/attribute1;\n", simple.toCSV("/*/attribute1", null, null).toString()); | ||
| assertEquals( | ||
| "[0]/arrayA[0];\n[0]/arrayA[1];\n[0]/arrayA[2];\n[1]/arrayA[0];\n[1]/arrayA[1];\n[1]/arrayA[2];\n", | ||
| simple.toCSV("/arrayA", null, null).toString() | ||
| ); | ||
| assertEquals( | ||
| "[0]/arrayB[0]/id;\n[0]/arrayB[1]/id;\n[0]/arrayB[2]/id;\n[1]/arrayB[0]/id;\n[1]/arrayB[1]/id;\n[1]/arrayB[2]/id;\n", | ||
| simple.toCSV("/arrayB/id", null, null).toString() | ||
| simple.toCSV("/arrayB/*/id", null, null).toString() | ||
| ); | ||
|
Comment on lines
77
to
80
|
||
| assertEquals("", simple.toCSV("/nonexistent", null, null).toString()); | ||
| } | ||
|
|
@@ -102,6 +107,56 @@ void csvProperties() throws IllegalStateException, ParseException, IOException { | |
| assertEquals("[0] {object} \n[1] {object} \n", simple.toCSV("/", new String[] { "." }, " ").toString()); | ||
| } | ||
|
|
||
| @Test | ||
| void csvWildcard() throws IllegalStateException, ParseException, IOException { | ||
| JFlat nodeDrives = new JFlat(getResourceAsString("/object-keys.json")); | ||
| nodeDrives.parse(); | ||
|
|
||
| // Wildcard to list all drive entries | ||
| assertEquals( | ||
| "/members/2415********************************;\n" + | ||
| "/members/4959********************************;\n" + | ||
| "/members/93a3********************************;\n" + | ||
| "/members/9f02********************************;\n", | ||
| nodeDrives.toCSV("/members/*", null, ";").toString() | ||
| ); | ||
|
|
||
| // Wildcard with id and name properties | ||
| assertEquals( | ||
| "/members/2415********************************;1;Internal Drive 1;\n" + | ||
| "/members/4959********************************;0;Internal Drive 0;\n" + | ||
| "/members/93a3********************************;0;Internal Drive 0;\n" + | ||
| "/members/9f02********************************;1;Internal Drive 1;\n", | ||
| nodeDrives.toCSV("/members/*", new String[] { "id", "name" }, ";").toString() | ||
| ); | ||
|
|
||
| // Wildcard with nested paths | ||
| assertEquals( | ||
| "/members/2415********************************;Internal Drive 1;416Y******91;NVMe;\n" + | ||
| "/members/4959********************************;Internal Drive 0;416Y******91;NVMe;\n" + | ||
| "/members/93a3********************************;Internal Drive 0;214F******S1;NVMe;\n" + | ||
| "/members/9f02********************************;Internal Drive 1;214F******S1;NVMe;\n", | ||
| nodeDrives | ||
| .toCSV("/members/*", new String[] { "name", "manufacturing/serialNumber", "type/default" }, ";") | ||
| .toString() | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void csvWildcardEscape() throws IllegalStateException, ParseException, IOException { | ||
| JFlat jFlat = new JFlat(getResourceAsString("/wildcard-key.json")); | ||
| jFlat.parse(); | ||
|
|
||
| // Wildcard "*" expands all children of "items" | ||
| assertEquals( | ||
| "/items/*;1;star;\n/items/alpha;2;alpha;\n/items/beta;3;beta;\n", | ||
| jFlat.toCSV("/items/*", new String[] { "id", "name" }, ";").toString() | ||
| ); | ||
|
|
||
| // Escaped "\*" targets only the literal "*" property | ||
| assertEquals("/items/*;1;star;\n", jFlat.toCSV("/items/\\*", new String[] { "id", "name" }, ";").toString()); | ||
| } | ||
|
|
||
| /** | ||
| * Reads the specified resource file and returns its content as a String | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
"\\*"path element is now reserved to mean “literal*key”. This makes it impossible to target a JSON property whose name is literally"\\*"(backslash + asterisk), because it will always be interpreted as an escape sequence. If supporting such keys matters, consider defining an escape for the backslash itself (e.g.,"\\\\*"in the path syntax) and handling it before the wildcard escape logic.