-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·61 lines (48 loc) · 1.22 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash -e
OWN_FILE="$0"
JPRO="$(dirname "$0")/index.js"
function print_prev_line() {
head -n "$(( BASH_LINENO - 1 ))" "$OWN_FILE" | tail -1
}
function jpro ()
{
"$JPRO" "$@"
}
echo 'run tests...'
# ==============================
expected='[
"sushi",
"orange"
]'
actual="$( \
echo '{"name":"bob","like":["sushi","orange"]}' | jpro '.like'
)"; print_prev_line
test "$expected" = "$actual"
# ==============================
expected='[
"name",
"like"
]'
actual="$( \
echo '{"name":"bob","like":["sushi","orange"]}' | jpro '&& Object.keys(input)'
)"; print_prev_line
test "$expected" = "$actual"
# ==============================
expected='sushi&orange'
actual="$( \
echo '{"name":"bob","like":["sushi","orange"]}' | jpro '; stdout = input.like.join("&")'
)"; print_prev_line
test "$expected" = "$actual"
# ==============================
expected='Warning: failed to parse JSON from STDIN
HELLO, WORLD'
actual="$( \
echo 'hello, world' | jpro ';stdout = stdin.toUpperCase()' 2>&1
)"; print_prev_line
test "$expected" = "$actual"
# ==============================
expected='HELLO, WORLD'
actual="$( \
echo 'hello, world' | JPRO_SILENT=true jpro ';stdout = stdin.toUpperCase()'
)"; print_prev_line
test "$expected" = "$actual"