summaryrefslogtreecommitdiff
path: root/tests
blob: 50e1c75473c37d4f3e34034f9874ce6102e09272 (plain)
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
#!/bin/sh
# Test suite for mp.

run() {
	# shellcheck disable=SC2254
	[ "$filter" ] && case $1 in ($filter) ;; (*) return; esac
	out=$(echo "$2" | ./mp 2>&1)
	[ "$out" = "$3" ] && pass=$((pass + 1)) && return
	printf "%s FAIL\nWant: \"%s\"\n Got: \"%s\"\n" "$1" "$3" "$out"
	fail=$((fail + 1))
	return 1
}

[ "$FAILFAST" ] && set -e
pass=0 fail=0 filter="$1"
trap 'echo "$pass passed, $fail failed"; exit $((fail))' EXIT

run basic1 'parse' ''
run basic2 'parse null' 'null'
run basic3 'parse true' 'true'
run basic4 'parse false' 'false'
run num1 'parse 12' '12'
run str1 'parse "hello"' '"hello"'
run obj1 'parse {}' '{}'
run arr1 'parse []' '[]'