Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright 2015 by Bernhard Reutner-Fischer |
| 3 | # Licensed under GPLv2 or later, see file LICENSE in this source tree. |
| 4 | |
| 5 | . ./testing.sh |
| 6 | |
| 7 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 8 | |
| 9 | testing "dc basic syntax (stdin, multiple args)" \ |
| 10 | "dc" \ |
| 11 | "30\n" \ |
| 12 | "" "10 20+p" |
| 13 | |
| 14 | testing "dc basic syntax (argv, single arg)" \ |
Denys Vlasenko | a133137 | 2018-12-06 18:46:42 +0100 | [diff] [blame] | 15 | "dc -e'10 20+p'" \ |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 16 | "30\n" \ |
| 17 | "" "" |
| 18 | |
| 19 | testing "dc basic syntax (argv, multiple args)" \ |
Denys Vlasenko | a133137 | 2018-12-06 18:46:42 +0100 | [diff] [blame] | 20 | "dc -e10 -e20+p" \ |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 21 | "30\n" \ |
| 22 | "" "" |
| 23 | |
| 24 | testing "dc complex with spaces (single arg)" \ |
Denys Vlasenko | a133137 | 2018-12-06 18:46:42 +0100 | [diff] [blame] | 25 | "dc -e'8 8 * 2 2 + / p'" \ |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 26 | "16\n" \ |
| 27 | "" "" |
| 28 | |
| 29 | testing "dc complex without spaces (single arg)" \ |
Denys Vlasenko | a133137 | 2018-12-06 18:46:42 +0100 | [diff] [blame] | 30 | "dc -e'8 8*2 2+/p'" \ |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 31 | "16\n" \ |
| 32 | "" "" |
| 33 | |
| 34 | testing "dc complex with spaces (multiple args)" \ |
Denys Vlasenko | a133137 | 2018-12-06 18:46:42 +0100 | [diff] [blame] | 35 | "dc -e8 -e8 -e\* -e2 -e2 -e+ -e/ -ep" \ |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 36 | "16\n" \ |
| 37 | "" "" |
| 38 | |
| 39 | testing "dc complex without spaces (multiple args)" \ |
Denys Vlasenko | a133137 | 2018-12-06 18:46:42 +0100 | [diff] [blame] | 40 | "dc -e8 -e8\*2 -e2+/p" \ |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 41 | "16\n" \ |
| 42 | "" "" |
| 43 | |
Chen Qi | 32c8ce4 | 2019-04-17 09:39:25 +0800 | [diff] [blame] | 44 | optional FEATURE_DC_BIG |
| 45 | # All tests below depend on FEATURE_DC_BIG |
| 46 | |
Brian Foley | 7454879 | 2019-09-05 10:46:22 +0200 | [diff] [blame] | 47 | testing "dc: x should execute strings" \ |
| 48 | "dc -e'[40 2 +] x f'" \ |
| 49 | "42\n" \ |
| 50 | "" "" |
| 51 | |
| 52 | testing "dc: x should not execute or pop non-strings" \ |
| 53 | "dc -e'42 x f'" \ |
| 54 | "42\n" \ |
| 55 | "" "" |
| 56 | |
Brian Foley | b64470b | 2019-09-05 10:50:13 +0200 | [diff] [blame] | 57 | testing "dc: x should work with strings created from a" \ |
| 58 | "dc -e'42 112 a x'" \ |
| 59 | "42\n" \ |
| 60 | "" "" |
| 61 | |
Brian Foley | 10509a7 | 2019-09-05 10:53:21 +0200 | [diff] [blame] | 62 | testing "dc: p should print invalid escapes" \ |
| 63 | "dc -e '[\q] p'" \ |
| 64 | "\\q\n" \ |
| 65 | "" "" |
| 66 | |
| 67 | testing "dc: p should print trailing backslashes" \ |
| 68 | "dc -e '[q\] p'" \ |
| 69 | "q\\\\\n" \ |
| 70 | "" "" |
| 71 | |
| 72 | testing "dc: p should parse/print single backslashes" \ |
| 73 | "dc -e '[\] p'" \ |
| 74 | "\\\\\n" \ |
| 75 | "" "" |
| 76 | |
| 77 | testing "dc: p should print single backslash strings" \ |
| 78 | "dc -e '92 a p'" \ |
| 79 | "\\\\\n" \ |
| 80 | "" "" |
| 81 | |
Denys Vlasenko | 6842c60 | 2019-01-04 05:41:47 +0100 | [diff] [blame] | 82 | testing "dc read" \ |
| 83 | "dc -finput" \ |
| 84 | "2\n9\n1\n" \ |
| 85 | "1?2\nf" "9\n" |
| 86 | |
Denys Vlasenko | 1db367a | 2019-01-04 06:18:00 +0100 | [diff] [blame] | 87 | testing "dc read string" \ |
| 88 | "dc -finput" \ |
| 89 | "2\nstr\n1\n" \ |
| 90 | "1?2\nf" "[str]\n" |
| 91 | |
Denys Vlasenko | badf683 | 2018-12-22 18:04:08 +0100 | [diff] [blame] | 92 | testing "dc '>a' (conditional execute string) 1" \ |
| 93 | "dc" \ |
| 94 | "1\n9\n" \ |
| 95 | "" "[1p]sa [2p]sb 1 2>a\n9p" |
| 96 | |
| 97 | testing "dc '>a' (conditional execute string) 2" \ |
| 98 | "dc" \ |
| 99 | "9\n" \ |
| 100 | "" "[1p]sa [2p]sb 2 1>a\n9p" |
| 101 | |
| 102 | testing "dc '>aeb' (conditional execute string with else)" \ |
| 103 | "dc" \ |
| 104 | "2\n9\n" \ |
| 105 | "" "[1p]sa [2p]sb 2 1>aeb\n9p" |
| 106 | |
Denys Vlasenko | 8fac1c7 | 2018-12-25 20:50:41 +0100 | [diff] [blame] | 107 | testing "dc space can be a register" \ |
| 108 | "dc" \ |
| 109 | "2\n9\n" \ |
| 110 | "" "[2p]s \n[3p]\nl x\n9p" |
| 111 | |
| 112 | testing "dc newline can be a register" \ |
| 113 | "dc" \ |
| 114 | "2\n9\n" \ |
| 115 | "" "[2p]s\n[3p]l\nx\n9p" |
| 116 | |
Denys Vlasenko | ace81cd | 2021-02-26 14:05:28 +0100 | [diff] [blame^] | 117 | testing "dc Z (length) for numbers" \ |
| 118 | "dc" \ |
| 119 | "1\n1\n3\n1\n3\n1\n" \ |
| 120 | "" "0Zp\n0.000Zp\n100Zp\n0.01Zp\n0.00120Zp\n0.0012 0.0012 - Zp\n" |
| 121 | |
Denys Vlasenko | 9a23b07 | 2018-12-12 21:41:40 +0100 | [diff] [blame] | 122 | for f in dc_*.dc; do |
| 123 | r="`basename "$f" .dc`_results.txt" |
| 124 | test -f "$r" || continue |
| 125 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 126 | testing "dc $f" \ |
| 127 | "{ { dc $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \ |
| 128 | "E:0\nE:0\n" \ |
| 129 | "" "" |
| 130 | done |
| 131 | |
| 132 | for f in dcx_*.dc; do |
| 133 | r="`basename "$f" .dc`_results.txt" |
| 134 | test -f "$r" || continue |
| 135 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 136 | testing "dc -x $f" \ |
| 137 | "{ { dc -x $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \ |
| 138 | "E:0\nE:0\n" \ |
| 139 | "" "" |
| 140 | done |
| 141 | |
Bernhard Reutner-Fischer | 70e30e8 | 2015-02-16 17:12:04 +0100 | [diff] [blame] | 142 | exit $FAILCOUNT |