Skip to content

Commit

Permalink
Design a unit-test suite for jsqry executable #7
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Jul 6, 2020
1 parent ea030fa commit 19a63cc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
.idea/
target/
build/
temp/
node_modules/
*.iml
12 changes: 12 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

# Uses https://github.com/adolfopa/tush

mydir=$(cd "$(dirname $0)" ; pwd)

export PATH=$mydir/build:$PATH:~/proj_src/tush/bin/

#which jsqry
#jsqry -v

tush-check tests.tush
65 changes: 65 additions & 0 deletions tests.tush
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

$ echo '[{"a":1},{"a":2}]' | jsqry 'a'
| [
| 1,
| 2
| ]

$ echo '[{"a":1},{"a":2}]' | jsqry # pretty-print
| [
| {
| "a": 1
| },
| {
| "a": 2
| }
| ]

$ echo '[{"a":1},{"a":2}]' | jsqry -1 'a' # first
| 1

$ echo '["a", "b", "c", "d", "e"]' | jsqry '[i%2==0]'
| [
| "a",
| "c",
| "e"
| ]

$ echo '[{ "k": [{ "a": 1 }, { "a": 2 }] }, { "k": [{ "a": 3 }] }]' | jsqry 'k.*.a'
| [
| 1,
| 2,
| 3
| ]

$ echo '[{ "k": [{ "a": 1 }, { "a": 2 }] }, { "k": [{ "a": 3 }] }]' | jsqry 'k.*.a[::-1]'
| [
| 3,
| 2,
| 1
| ]

$ echo '[{ "k": [{ "a": 1 }, { "a": 2 }] }, { "k": [{ "a": 3 }] }]' | jsqry -1 'k.*.a[::-1][_<3][1]{_+100}'
| 101

$ echo 'hello' | jsqry 'a'
@ error: Wrong JSON
? 1

$ echo '{}' | jsqry '['
@ error: Not closed [
? 1

$ echo '{}' | jsqry '}'
@ error: } without {
? 1

$ jsqry -v
| 0.0.2

$ jsqry -h
| jsqry ver. 0.0.2
| Usage: echo $JSON | jsqry 'query'
| -1,--first return first result element
| -h,--help print help and exit
| -v,--version print version and exit

0 comments on commit 19a63cc

Please sign in to comment.