test-string-utils.scm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. (import
  2. ;; unit tests
  3. (srfi srfi-64)
  4. ;; module to test
  5. (string-utils))
  6. (test-begin "string-utils-test")
  7. (test-group
  8. "char-to-string-test"
  9. (test-equal "char->string converts a character to a string"
  10. "a"
  11. (char->string #\a)))
  12. (test-group
  13. "string-to-char-test"
  14. (test-equal "string->char convers a string of length 1 to a character"
  15. #\a
  16. (string->char "a")))
  17. (test-group
  18. "has-prefixp-test"
  19. (test-assert "has-prefix? recognizes a non-empty prefix of a non-empty string"
  20. (has-prefix? "abcdef" "abc"))
  21. (test-assert "has-prefix? recognizes a non-empty non-prefix of an empty string"
  22. (not (has-prefix? "" "abc")))
  23. (test-assert "has-prefix? recognizes an empty prefix of a non-empty string"
  24. (has-prefix? "abc" ""))
  25. (test-assert "has-prefix? recognizes an empty prefix of an empty string"
  26. (has-prefix? "" ""))
  27. (test-assert "has-prefix? recognizes a non-prefix of a non-empty string"
  28. (not (has-prefix? "abcdef" "def"))))
  29. (test-group
  30. "has-suffixp-test"
  31. (test-assert "has-suffix? recognizes a non-empty suffix of a non-empty string"
  32. (has-suffix? "abcdef" "def"))
  33. (test-assert "has-suffix? recognizes a non-empty non-suffix of an empty string"
  34. (not (has-suffix? "" "abc")))
  35. (test-assert "has-suffix? recognizes an empty suffix of a non-empty string"
  36. (has-suffix? "abc" ""))
  37. (test-assert "has-suffix? recognizes an empty suffix of an empty string"
  38. (has-suffix? "" ""))
  39. (test-assert "has-suffix? recognizes a non-suffix of a non-empty string"
  40. (not (has-suffix? "abcdef" "abc"))))
  41. (test-group
  42. "remove-prefix-test-group"
  43. (test-equal "remove-prefix does not remove other stuff"
  44. "abcdef"
  45. (remove-prefix "abcdef" "123"))
  46. (test-equal "remove-prefix does remove the prefix"
  47. "def"
  48. (remove-prefix "abcdef" "abc")))
  49. (test-group
  50. "remove-suffix-test-group"
  51. (test-equal "remove-suffix does not remove other stuff"
  52. "abcdef"
  53. (remove-suffix "abcdef" "123"))
  54. (test-equal "remove-suffix does remove the suffix"
  55. "abc"
  56. (remove-suffix "abcdef" "def")))
  57. (test-group
  58. "remove-multiple-prefix-test-group"
  59. (test-equal "remove-multiple-prefix does not remove other stuff"
  60. "abcabcdef"
  61. (remove-multiple-prefix "abcabcdef" "bc"))
  62. (test-equal "remove-multiple-prefix does remove the prefix"
  63. "def"
  64. (remove-multiple-prefix "abcabcdef" "abc")))
  65. (test-group
  66. "remove-multiple-suffix-test-group"
  67. (test-equal "remove-multiple-suffix does not remove other stuff"
  68. "abcabcdef"
  69. (remove-multiple-suffix "abcabcdef" "bc"))
  70. (test-equal "remove-multiple-suffix does remove the suffix"
  71. "abc"
  72. (remove-multiple-suffix "abcdefdef" "def")))
  73. (test-end "string-utils-test")