PageRenderTime 59ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/test/plojuctor/test/core.clj

https://github.com/liquidz/plojuctor
Clojure | 91 lines | 70 code | 21 blank | 0 comment | 5 complexity | a4e6f453098975fa010f9fb3c9b374b8 MD5 | raw file
  1. (ns plojuctor.test.core
  2. (:use [plojuctor core sentence] :reload-all)
  3. (:use [clojure.test]))
  4. (defmacro deftest= [test-name & test-pairs]
  5. `(deftest ~test-name
  6. (are [x# y#] (= x# y#)
  7. ~@test-pairs)))
  8. (defsentence id [v] v)
  9. (defsentence multi [n v] (map #(* % n) v))
  10. (defsentence upper [& v]
  11. (map #(.toUpperCase %) (lines v)))
  12. (deftest test-defsentence
  13. (are [x y] (= x y)
  14. [1] (id [1])
  15. [1] (id 1)
  16. [2] (multi 2 [1])
  17. [2] (multi 2 1)
  18. [2 4 6] (multi 2 [1 2 3])
  19. [2 4 6] (multi 2 '(1 2 3))
  20. ["A"] (upper ["a"])
  21. ["A" "B"] (upper ["a"] ["b"])
  22. ["A" "B"] (upper [["a"] ["b"]])
  23. ["A"] (upper "a")
  24. ["A" "B"] (upper "a" "b")))
  25. (deftest test-lines
  26. (are [x y] (= x y)
  27. ["a" "b"] (lines "a" "b")
  28. ["a" "b"] (lines "a" (lines "b"))))
  29. (deftest test-inline
  30. (are [x y] (= x y)
  31. ["a"] (inline "a")
  32. ["ab"] (inline "a" "b")
  33. ["ab"] (inline "a" (inline "b"))))
  34. (deftest= test-strong
  35. ["\"a\""] (strong "a"))
  36. (deftest= test-header
  37. [":a"] (header "a")
  38. [":a_b"] (header "a b"))
  39. (deftest= test-underline
  40. ["a" *underline-char*] (underline "a"))
  41. (deftest= test-padding-left
  42. [" a"] (padding-left 2 "a"))
  43. (deftest= test-lettr-space
  44. ["a b c"] (letter-space 2 "abc")
  45. ["a b c"] (letter-1space "abc"))
  46. (deftest= test-wrap
  47. ["a"] (wrap 2 "a")
  48. ["ab" "cd"] (wrap 2 "abcd"))
  49. (deftest= test-center
  50. ["abcd"] (center 4 "abcd")
  51. [" ab"] (center 4 "ab"))
  52. (deftest= test-right
  53. ["ab"] (right 2 "ab")
  54. [" ab"] (right 4 "ab"))
  55. (deftest= test-vertical-center
  56. ["ab"] (vertical-center 1 "ab")
  57. ["" "ab"] (vertical-center 3 "ab"))
  58. (deftest= test-bottom
  59. ["ab"] (bottom 1 [] "ab")
  60. ["ab"] (bottom 1 ["ab"] "cd")
  61. ["" "" "ab"] (bottom 3 [] "ab")
  62. ["ab" "" "cd"] (bottom 3 ["ab"] "cd"))
  63. (deftest test-item
  64. (are [space x y] (= (vector (str space *item-char* " " x)) y)
  65. " " "a" (item "a")
  66. " " "a" (item (item "a"))))
  67. (deftest= test-code
  68. ["(+ 1 2)"] (code (+ 1 2)))
  69. (deftest= test-box
  70. ["+---+" "| a |" "+---+"] (box "a"))