use lib -e 't' ? 't' : 'test';
use TestPegexForth;

test_out '3 4 .', "4", '. works';
test_out '3 4 .s', "<2> 3 4", '.s works';
test_stack '3 4 +', '[7]', '+ works';
test_stack '3 4 -', '[-1]', '- works';
test_stack '3 4 *', '[12]', '* works';
test_stack '35 4 /', '[8]', '/ works';
test_stack '-9 /2', '[-5]', '/2 works';
test_stack '19 5 mod', '[4]', 'mod works';
test_stack '19 5 /mod', '[4,3]', '/mod works';
test_stack '3 4 0sp', '[]', '0sp works';
test_stack '3 4 dup', '[3,4,4]', 'dup works';
test_stack '3 4 swap', '[4,3]', 'dup works';
test_stack '3 4 over', '[3,4,3]', 'dup works';
test_stack '3 4 drop', '[3]', 'dup works';
test_stack '3 4 5 rot', '[4,5,3]', 'dup works';
test_stack '3 4 5 2 pick', '[3,4,5,3]', 'pick works';
test_stack '3 4 ?dup', '[3,4,4]', '?dup works with non-zero';
test_stack '3 4 0 ?dup', '[3,4,0]', '?dup works with zero';
test_stack '3 4 5 -rot', '[5,3,4]', '-rot works';
test_stack '3 4 5 6 2swap', '[5,6,3,4]', '2swap works';
test_stack '3 4 5 6 2over', '[3,4,5,6,3,4]', '2over works';
test_stack '3 4 2dup', '[3,4,3,4]', '2dup works';
test_stack '3 4 nip', '[4]', 'nip works';
test_stack '3 4 tuck', '[4,3,4]', 'tuck works';
test_stack '-3 -4 abs', '[-3,4]', 'abs works';
test_stack '3 4 negate', '[3,-4]', 'negate works';
test_stack '8 2 lshift', '[32]', 'lshift works';
test_stack '8 2 rshift', '[2]', 'rshift works';
test_stack '-8 2 arshift', '[-2]', 'arshift works';
test_stack '3 4 min', '[3]', 'min works';
test_stack '3 4 max', '[4]', 'max works';
test_out '72 EMIT 105 EMIT', 'Hi', 'emit works';
test_out 'words', '* + - -rot . .s / /2 /mod 0sp 2dup 2over 2swap ?dup abs arshift clearstack drop dup emit lshift max min mod negate nip over pick rot rshift swap tuck words', 'words works';
