forked from dominictarr/JSON.sh
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove readlink -f from test scripts.
Clean up tokenizer-test.sh Hide successful test output.
- Loading branch information
Showing
5 changed files
with
67 additions
and
62 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
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,24 @@ | |||
#! /usr/bin/env bash | |||
|
|
||
__filename=`readlink -f $0` | cd ${0%/*} | ||
__dirname=`dirname $__filename` | |||
cd $__dirname | |||
|
|
||
. ../parse.sh | . ../parse.sh | ||
|
|
||
cat ../package.json | tokenize | parse | ptest () { | ||
tokenize | parse >/dev/null | |||
} | |||
|
|
||
#echo '"oooo" ' | tokenize | parse | fails=0 | ||
echo '[true, 1, [0, {}]] ' | tokenize | parse | for input in '"oooo" ' '[true, 1, [0, {}]] ' '{"true": 1}' | ||
echo '{"true": 1}' | tokenize | parse | do | ||
echo "$input" | ptest || let fails=$fails+1 | |||
done | |||
|
|||
if ! ptest < ../package.json | |||
then | |||
echo "Parsing package.json failed!" | |||
let fails=$fails+1 | |||
fi | |||
|
|||
echo "$fails test(s) failed" | |||
exit $fails |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,40 +1,50 @@ | |||
#! /usr/bin/env bash | #! /usr/bin/env bash | ||
|
|
||
__filename=`readlink -f $0` | cd ${0%/*} | ||
__dirname=`dirname $__filename` | |||
cd $__dirname | |||
|
|
||
. ../parse.sh | . ../parse.sh | ||
set -e | set -e | ||
|
|
||
diff <( echo '"dah"' | tokenize ) <( echo '"dah"' ) | ttest () { | ||
diff <( echo '""' | tokenize ) <( echo '""' ) | local input="$1"; shift | ||
diff <( echo '["dah"]' | tokenize ) <( printf '[\n\"dah\"\n]\n' ) | local expected="$(printf '%s\n' "$@")" | ||
diff <( echo '" "' | tokenize ) <( printf '" "\n' ) | if ! echo "$input" | tokenize |diff -u - <(echo "$expected") | ||
diff <( printf '" \\" "' | tokenize ) <( printf '" \\" "\n' ) | then | ||
|
let fails=$fails+1 | ||
diff \ | fi | ||
<( echo '["dah"]' | tokenize ) \ | } | ||
<( echo \ |
|
||
'[ | fails=0 | ||
"dah" | ttest '"dah"' '"dah"' | ||
]') | ttest '""' '""' | ||
|
ttest '["dah"]' '[' '"dah"' ']' | ||
diff <( echo '123' | tokenize ) <( echo '123' ) | ttest '" "' '" "' | ||
diff <( echo '123.142' | tokenize ) <( echo '123.142' ) | ttest '" \" "' '" \" "' | ||
diff <( echo '-123' | tokenize ) <( echo '-123') |
|
||
|
ttest '["dah"]' '[' '"dah"' ']' | ||
#diff <( echo '1e23' | tokenize ) <( printf '1e23\n' ) |
|
||
diff <( echo '0.1' | tokenize ) <( echo '0.1' ) | ttest '123' '123' | ||
diff <( echo '-110' | tokenize ) <( echo '-110' ) | ttest '123.142' '123.142' | ||
diff <( echo '-110.10' | tokenize ) <( echo '-110.10' ) | ttest '-123' '-123' | ||
diff <( echo '-110e10' | tokenize ) <( echo '-110e10' ) |
|
||
diff <( echo 'null' | tokenize ) <( echo 'null' ) | ttest '1e23' '1e23' | ||
diff <( echo 'true' | tokenize ) <( echo 'true' ) | ttest '0.1' '0.1' | ||
diff <( echo 'false' | tokenize ) <( echo 'false' ) | ttest '-110' '-110' | ||
diff <( echo '[ null , -110e10, "null" ]' \ | ttest '-110.10' '-110.10' | ||
| tokenize ) <( printf '[\nnull\n,\n-110e10\n,\n"null"\n]\n' ) | ttest '-110e10' '-110e10' | ||
diff <( echo '{"e": false}' | tokenize ) <( printf '{\n"e"\n:\nfalse\n}\n' ) | ttest 'null' 'null' | ||
diff <( echo '{"e": "string"}' | tokenize ) <( printf '{\n"e"\n:\n"string"\n}\n' ) | ttest 'true' 'true' | ||
|
ttest 'false' 'false' | ||
cat ../package.json | tokenize | ttest '[ null , -110e10, "null" ]' \ | ||
'[' 'null' ',' '-110e10' ',' '"null"' ']' | |||
ttest '{"e": false}' '{' '"e"' ':' 'false' '}' | |||
ttest '{"e": "string"}' '{' '"e"' ':' '"string"' '}' | |||
|
|||
if ! cat ../package.json | tokenize >/dev/null | |||
then | |||
let fails=$fails+1 | |||
echo "Tokenizing package.json failed!" | |||
fi | |||
|
|||
echo "$fails test(s) failed" | |||
exit $fails |
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