Skip to content

Commit

Permalink
add test cases for --items and -0,-2,-4
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed May 26, 2014
1 parent ba1a3c8 commit b268f96
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/items/cmd
@@ -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

7 changes: 7 additions & 0 deletions test/items/expected.stdout
@@ -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}]
12 changes: 12 additions & 0 deletions test/json-indent/cmd
@@ -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
24 changes: 24 additions & 0 deletions test/json-indent/expected.stdout
@@ -0,0 +1,24 @@
[{"foo":"bar"},{"baz":"bat"}]
[
{
"foo": "bar"
},
{
"baz": "bat"
}
]
[
{
"foo": "bar"
},
{
"baz": "bat"
}
]

{"foo":"bar"}
{"baz":"bat"}

{
"foo": "bar"
}

0 comments on commit b268f96

Please sign in to comment.