logo

utils-std

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

expr.sh (996B)


  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=23
  7. . "${WD}/test-cmd/tap.sh"
  8. t int 1 '1
  9. '
  10. t_args group '4
  11. ' '(' 2 '*' 3 ')' - 2
  12. t_args 'char_count:1234' '4
  13. ' "X1234" : '.*' - 1
  14. t_args 'char_count:12345' '5
  15. ' "X12345" : '.*' - 1
  16. t_args mul '6
  17. ' 3 '*' 2
  18. t_args div '3
  19. ' 7 / 2
  20. t_args rem '1
  21. ' 7 % 2
  22. t_args add '3
  23. ' 1 + 2
  24. t_args sub '2
  25. ' 3 - 1
  26. good='1
  27. '
  28. bad='0
  29. '
  30. t_args eq:eq "$good" 1 = 1
  31. t_args --exit=1 eq:ne "$bad" 1 = 0
  32. t_args gt:gt "$good" 2 '>' 1
  33. t_args --exit=1 gt:lt "$bad" 1 '>' 2
  34. t_args gte:gt "$good" 2 '>=' 1
  35. t_args gte:eq "$good" 2 '>=' 2
  36. t_args --exit=1 gte:lt "$bad" 1 '>=' 2
  37. t_args lt:lt "$good" 1 '<' 2
  38. t_args --exit=1 lt:gt "$bad" 2 '<' 1
  39. t_args lte:lt "$good" 1 '<=' 2
  40. t_args lte:eq "$good" 2 '<=' 2
  41. t_args --exit=1 lte:gt "$bad" 2 '<=' 1
  42. t_args ne:ne "$good" 1 != 2
  43. t_args --exit=1 ne:eq "$bad" 1 != 1
  44. # TODO: and (&), or (|)