#!/bin/sh cd $(0%/*) # Can't detect sourcing in sh, so immediately terminate the attempt to parse source ../JSON.sh /tmp/json_ttest_expected if echo $input | tokenize | diff -u - /tmp/json_ttest_expected { echo "ok $i - $input" } else { echo "not ok $i - $input" global fails := $(fails+1) } } ttest '"dah"' '"dah"' ttest '""' '""' ttest '["dah"]' '[' '"dah"' ']' ttest '" "' '" "' ttest '" \" "' '" \" "' ttest '["dah"]' '[' '"dah"' ']' ttest '123' '123' ttest '123.142' '123.142' ttest '-123' '-123' ttest '1e23' '1e23' ttest '0.1' '0.1' ttest '-110' '-110' ttest '-110.10' '-110.10' ttest '-110e10' '-110e10' ttest 'null' 'null' ttest 'true' 'true' ttest 'false' 'false' ttest '[ null , -110e10, "null" ]' \ '[' 'null' ',' '-110e10' ',' '"null"' ']' ttest '{"e": false}' '{' '"e"' ':' 'false' '}' ttest '{"e": "string"}' '{' '"e"' ':' '"string"' '}' if ! cat ../package.json | tokenize >/dev/null { global fails := $(fails+1) echo "Tokenizing package.json failed!" } echo "$fails test(s) failed" exit $fails (CommandList children: [ (C {(cd)} { (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Percent arg_word:{(Lit_Slash /) ("*")}) spids: [6 11] ) } ) (SimpleCommand words: [{(.)} {(../JSON.sh)}] redirects: [(Redir op_id:Redir_Less fd:-1 arg_word:{(/dev/null)} spids:[21])] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:i) op:Equal rhs:{(0)} spids:[25])] spids: [25] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:fails) op:Equal rhs:{(0)} spids:[28])] spids: [28] ) (FuncDef name: ttest body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:i) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [40 45] ) } spids: [39] ) ] spids: [39] ) (Sentence child: (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:input) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [50] ) ] spids: [48] ) terminator: ) (C {(shift)}) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:expected) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(printf)} {(SQ <"%s\\n">)} {(DQ ($ VSub_At "$@"))})] ) left_token: spids: [63 73] ) ) } spids: [61] ) ] spids: [59] ) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$expected"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/tmp/json_ttest_expected)} spids: [83] ) ] ) (If arms: [ (if_arm cond: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$input"))}) (C {(tokenize)}) (C {(diff)} {(-u)} {(-)} {(/tmp/json_ttest_expected)}) ] negated: False ) ] action: [(C {(echo)} {(DQ ("ok ") ($ VSub_Name "$i") (" - ") ($ VSub_Name "$input"))})] spids: [-1 111] ) ] else_action: [ (C {(echo)} {(DQ ("not ok ") ($ VSub_Name "$i") (" - ") ($ VSub_Name "$input"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fails) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:fails) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [140 145] ) } spids: [139] ) ] spids: [139] ) ] spids: [125 148] ) ] spids: [36] ) spids: [31 35] ) (C {(ttest)} {(SQ <"\"dah\"">)} {(SQ <"\"dah\"">)}) (C {(ttest)} {(SQ <"\"\"">)} {(SQ <"\"\"">)}) (C {(ttest)} {(SQ <"[\"dah\"]">)} {(SQ <"[">)} {(SQ <"\"dah\"">)} {(SQ <"]">)}) (C {(ttest)} {(SQ <"\" \"">)} {(SQ <"\" \"">)}) (C {(ttest)} {(SQ <"\" \\\" \"">)} {(SQ <"\" \\\" \"">)}) (C {(ttest)} {(SQ <"[\"dah\"]">)} {(SQ <"[">)} {(SQ <"\"dah\"">)} {(SQ <"]">)}) (C {(ttest)} {(SQ <123>)} {(SQ <123>)}) (C {(ttest)} {(SQ <123.142>)} {(SQ <123.142>)}) (C {(ttest)} {(SQ <-123>)} {(SQ <-123>)}) (C {(ttest)} {(SQ <1e23>)} {(SQ <1e23>)}) (C {(ttest)} {(SQ <0.1>)} {(SQ <0.1>)}) (C {(ttest)} {(SQ <-110>)} {(SQ <-110>)}) (C {(ttest)} {(SQ <-110.10>)} {(SQ <-110.10>)}) (C {(ttest)} {(SQ <-110e10>)} {(SQ <-110e10>)}) (C {(ttest)} {(SQ )} {(SQ )}) (C {(ttest)} {(SQ )} {(SQ )}) (C {(ttest)} {(SQ )} {(SQ )}) (C {(ttest)} {(SQ <"[ null , -110e10, \"null\" ]">)} {(SQ <"[">)} {(SQ )} {(SQ <",">)} {(SQ <-110e10>)} {(SQ <",">)} {(SQ <"\"null\"">)} {(SQ <"]">)} ) (C {(ttest)} {(SQ <"{\"e\": false}">)} {(SQ <"{">)} {(SQ <"\"e\"">)} {(SQ <":">)} {(SQ )} {(SQ <"}">)} ) (C {(ttest)} {(SQ <"{\"e\": \"string\"}">)} {(SQ <"{">)} {(SQ <"\"e\"">)} {(SQ <":">)} {(SQ <"\"string\"">)} {(SQ <"}">)} ) (If arms: [ (if_arm cond: [ (Pipeline children: [ (C {(cat)} {(../package.json)}) (SimpleCommand words: [{(tokenize)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[443])] ) ] negated: True ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fails) op: Equal rhs: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:fails) right: (ArithWord w:{(Lit_Digits 1)}) ) spids: [450 455] ) } spids: [449] ) ] spids: [449] ) (C {(echo)} {(DQ ("Tokenizing package.json failed!"))}) ] spids: [-1 446] ) ] spids: [-1 464] ) (C {(echo)} {(DQ ($ VSub_Name "$fails") (" test(s) failed"))}) (C {(exit)} {($ VSub_Name "$fails")}) ] )