logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

expr.sh (1407B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")/../"
  5. target="${WD}/cmd/expr"
  6. plans=41
  7. . "${WD}/test-cmd/tap.sh"
  8. t_expr_no() {
  9. name="$1"; shift
  10. t_args --exit=1 "$name" '0
  11. ' "$@"
  12. }
  13. t_expr_ok() {
  14. name="$1"; shift
  15. t_args "$name" '1
  16. ' "$@"
  17. }
  18. t int 1 '1
  19. '
  20. t_args group '4
  21. ' '(' 2 '*' 3 ')' - 2
  22. t_args 'char_count:1234' '4
  23. ' "X1234" : '.*' - 1
  24. t_args 'char_count:12345' '5
  25. ' "X12345" : '.*' - 1
  26. t_expr_no or:00 0 '|' 0
  27. t_expr_ok or:01 0 '|' 1
  28. t_expr_ok or:10 1 '|' 0
  29. t_expr_ok or:11 1 '|' 1
  30. t_expr_no and:00 0 '&' 0
  31. t_expr_no and:01 0 '&' 1
  32. t_expr_no and:10 1 '&' 0
  33. t_expr_ok and:11 1 '&' 1
  34. t_expr_ok eq:00 0 '=' 0
  35. t_expr_no eq:01 0 '=' 1
  36. t_expr_no eq:10 1 '=' 0
  37. t_expr_ok eq:11 1 '=' 1
  38. t_expr_no gt:00 0 '>' 0
  39. t_expr_no gt:01 0 '>' 1
  40. t_expr_ok gt:10 1 '>' 0
  41. t_expr_no gt:11 1 '>' 1
  42. t_expr_no lt:00 0 '<' 0
  43. t_expr_ok lt:01 0 '<' 1
  44. t_expr_no lt:10 1 '<' 0
  45. t_expr_no lt:11 1 '<' 1
  46. t_expr_ok ge:00 0 '>=' 0
  47. t_expr_no ge:01 0 '>=' 1
  48. t_expr_ok ge:10 1 '>=' 0
  49. t_expr_ok ge:11 1 '>=' 1
  50. t_expr_ok le:00 0 '<=' 0
  51. t_expr_ok le:01 0 '<=' 1
  52. t_expr_no le:10 1 '<=' 0
  53. t_expr_ok le:11 1 '<=' 1
  54. t_expr_no ne:00 0 '!=' 0
  55. t_expr_ok ne:01 0 '!=' 1
  56. t_expr_ok ne:10 1 '!=' 0
  57. t_expr_no ne:11 1 '!=' 1
  58. t_args mul '6
  59. ' 3 '*' 2
  60. t_args div '3
  61. ' 7 / 2
  62. t_args rem '1
  63. ' 7 % 2
  64. t_args add '3
  65. ' 1 + 2
  66. t_args sub '2
  67. ' 3 - 1