test_file_extentions 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. source "${BASH_SOURCE%/*}/assertions.sh"
  6. test_get_file_ext() {
  7. local path=${1:?}
  8. source "${BASH_SOURCE%/*}/../src/utils/functions.sh"
  9. get_file_ext "$path"
  10. }
  11. test_get_ext_to_replace_with_html() {
  12. local file_type=${1:?}
  13. source "${BASH_SOURCE%/*}/../src/utils/functions.sh"
  14. get_ext_to_replace_with_html "$file_type"
  15. }
  16. test_get_working_ext() {
  17. local file_type=${1:?}
  18. local path=${2:?}
  19. source "${BASH_SOURCE%/*}/../src/utils/functions.sh"
  20. get_working_ext "$file_type" "$path"
  21. }
  22. test_get_working_ext_main() {
  23. assert_equal \
  24. "test_get_working_ext" \
  25. "html" \
  26. "$(test_get_working_ext "markdown" "/foo/bar/glux.md")"
  27. assert_equal \
  28. "test_get_working_ext" \
  29. "html" \
  30. "$(test_get_working_ext "org" "/foo/bar/glux.org")"
  31. assert_equal \
  32. "test_get_working_ext" \
  33. "txt" \
  34. "$(test_get_working_ext "org" "/foo/bar/glux.txt")"
  35. # NOTE: Returns the filename when no ext
  36. assert_equal \
  37. "test_get_working_ext" \
  38. "glux" \
  39. "$(test_get_working_ext "org" "/foo/bar/glux")"
  40. }
  41. test_get_ext_to_replace_with_html_main() {
  42. assert_equal \
  43. "test_get_ext_to_replace_with_html" \
  44. "md" \
  45. "$(test_get_ext_to_replace_with_html "markdown")"
  46. assert_equal \
  47. "test_get_ext_to_replace_with_html" \
  48. "org" \
  49. "$(test_get_ext_to_replace_with_html "org")"
  50. echo "INFO: Expect output to stderr:"
  51. assert_not_equal \
  52. "test_get_ext_to_replace_with_html" \
  53. "foo" \
  54. "$(test_get_ext_to_replace_with_html "foo")"
  55. }
  56. test_get_file_ext_main() {
  57. assert_equal \
  58. "test_get_file_ext" \
  59. "glux" \
  60. "$(test_get_file_ext "/foo/bar/glux")"
  61. assert_equal \
  62. "test_get_file_ext" \
  63. "md" \
  64. "$(test_get_file_ext "/foo/bar/glux.md")"
  65. assert_equal \
  66. "test_get_file_ext" \
  67. "foo" \
  68. "$(test_get_file_ext "/foo/bar/glux.foo")"
  69. }
  70. test_file_extentions_main() {
  71. echo "${FUNCNAME[0]}"
  72. test_get_working_ext_main
  73. test_get_ext_to_replace_with_html_main
  74. test_get_file_ext_main
  75. }
  76. test_file_extentions_main