Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test cases for --items and -0,-2,-4
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
JSON="../../lib/json.js" | ||
JSON0="../../lib/json.js -o json-0" | ||
|
||
# Basic --items usage: | ||
# 1. Map an object(key,value) into an array of objects {key: key, value: value} | ||
echo '{"foo":1,"bar":2,"baz":3}' | $JSON0 --items | ||
# [{"key":"foo","value":1},{"key":"bar","value":2},{"key":"baz","value":3}] | ||
|
||
# 2. Pass array input through | ||
echo '[1,2,3]' | $JSON0 --items | ||
echo '' | ||
|
||
# 3. Lookup values in the resulting array | ||
echo '{"foo":{"data":1},"bar":{"data":2}}' | $JSON --items -a key value.data | ||
echo '' | ||
|
||
# 4. Alias to -M | ||
echo '{"foo":1,"bar":2,"baz":3}' | $JSON0 -M | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[{"key":"foo","value":1},{"key":"bar","value":2},{"key":"baz","value":3}] | ||
[1,2,3] | ||
|
||
foo 1 | ||
bar 2 | ||
|
||
[{"key":"foo","value":1},{"key":"bar","value":2},{"key":"baz","value":3}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Test the -0, -2, -4 convenience options. | ||
JSON=../../lib/json.js | ||
|
||
echo '[{"foo": "bar"},{"baz": "bat"}]' | $JSON -0 | ||
echo '[{"foo": "bar"},{"baz": "bat"}]' | $JSON -2 | ||
echo '[{"foo": "bar"},{"baz": "bat"}]' | $JSON -4 | ||
|
||
echo '' | ||
echo '[{"foo": "bar"},{"baz": "bat"}]' | $JSON -0a | ||
|
||
echo '' | ||
echo '[{"foo": "bar"},{"baz": "bat"}]' | $JSON -j4 -- -2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[{"foo":"bar"},{"baz":"bat"}] | ||
[ | ||
{ | ||
"foo": "bar" | ||
}, | ||
{ | ||
"baz": "bat" | ||
} | ||
] | ||
[ | ||
{ | ||
"foo": "bar" | ||
}, | ||
{ | ||
"baz": "bat" | ||
} | ||
] | ||
|
||
{"foo":"bar"} | ||
{"baz":"bat"} | ||
|
||
{ | ||
"foo": "bar" | ||
} |