3
0

dc.tests 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/sh
  2. # Copyright 2015 by Bernhard Reutner-Fischer
  3. # Licensed under GPLv2 or later, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # testing "test name" "command" "expected result" "file input" "stdin"
  6. testing "dc basic syntax (stdin, multiple args)" \
  7. "dc" \
  8. "30\n" \
  9. "" "10 20+p"
  10. testing "dc basic syntax (argv, single arg)" \
  11. "dc -e'10 20+p'" \
  12. "30\n" \
  13. "" ""
  14. testing "dc basic syntax (argv, multiple args)" \
  15. "dc -e10 -e20+p" \
  16. "30\n" \
  17. "" ""
  18. testing "dc complex with spaces (single arg)" \
  19. "dc -e'8 8 * 2 2 + / p'" \
  20. "16\n" \
  21. "" ""
  22. testing "dc complex without spaces (single arg)" \
  23. "dc -e'8 8*2 2+/p'" \
  24. "16\n" \
  25. "" ""
  26. testing "dc complex with spaces (multiple args)" \
  27. "dc -e8 -e8 -e\* -e2 -e2 -e+ -e/ -ep" \
  28. "16\n" \
  29. "" ""
  30. testing "dc complex without spaces (multiple args)" \
  31. "dc -e8 -e8\*2 -e2+/p" \
  32. "16\n" \
  33. "" ""
  34. optional FEATURE_DC_BIG
  35. # All tests below depend on FEATURE_DC_BIG
  36. testing "dc: x should execute strings" \
  37. "dc -e'[40 2 +] x f'" \
  38. "42\n" \
  39. "" ""
  40. testing "dc: x should not execute or pop non-strings" \
  41. "dc -e'42 x f'" \
  42. "42\n" \
  43. "" ""
  44. testing "dc: x should work with strings created from a" \
  45. "dc -e'42 112 a x'" \
  46. "42\n" \
  47. "" ""
  48. testing "dc: p should print invalid escapes" \
  49. "dc -e '[\q] p'" \
  50. "\\q\n" \
  51. "" ""
  52. testing "dc: p should print trailing backslashes" \
  53. "dc -e '[q\] p'" \
  54. "q\\\\\n" \
  55. "" ""
  56. testing "dc: p should parse/print single backslashes" \
  57. "dc -e '[\] p'" \
  58. "\\\\\n" \
  59. "" ""
  60. testing "dc: p should print single backslash strings" \
  61. "dc -e '92 a p'" \
  62. "\\\\\n" \
  63. "" ""
  64. testing "dc read" \
  65. "dc -finput" \
  66. "2\n9\n1\n" \
  67. "1?2\nf" "9\n"
  68. testing "dc read string" \
  69. "dc -finput" \
  70. "2\nstr\n1\n" \
  71. "1?2\nf" "[str]\n"
  72. testing "dc '>a' (conditional execute string) 1" \
  73. "dc" \
  74. "1\n9\n" \
  75. "" "[1p]sa [2p]sb 1 2>a\n9p"
  76. testing "dc '>a' (conditional execute string) 2" \
  77. "dc" \
  78. "9\n" \
  79. "" "[1p]sa [2p]sb 2 1>a\n9p"
  80. testing "dc '>aeb' (conditional execute string with else)" \
  81. "dc" \
  82. "2\n9\n" \
  83. "" "[1p]sa [2p]sb 2 1>aeb\n9p"
  84. testing "dc space can be a register" \
  85. "dc" \
  86. "2\n9\n" \
  87. "" "[2p]s \n[3p]\nl x\n9p"
  88. testing "dc newline can be a register" \
  89. "dc" \
  90. "2\n9\n" \
  91. "" "[2p]s\n[3p]l\nx\n9p"
  92. for f in dc_*.dc; do
  93. r="`basename "$f" .dc`_results.txt"
  94. test -f "$r" || continue
  95. # testing "test name" "command" "expected result" "file input" "stdin"
  96. testing "dc $f" \
  97. "{ { dc $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
  98. "E:0\nE:0\n" \
  99. "" ""
  100. done
  101. for f in dcx_*.dc; do
  102. r="`basename "$f" .dc`_results.txt"
  103. test -f "$r" || continue
  104. # testing "test name" "command" "expected result" "file input" "stdin"
  105. testing "dc -x $f" \
  106. "{ { dc -x $f 2>&1; echo E:\$? >&2; } | diff -u - $r; echo E:\$?; } 2>&1" \
  107. "E:0\nE:0\n" \
  108. "" ""
  109. done
  110. exit $FAILCOUNT