/test/lein_monolith/task/util_test.clj

https://github.com/amperity/lein-monolith · Clojure · 51 lines · 47 code · 4 blank · 0 comment · 20 complexity · e86c04adcdf4dc2514a7ea5d89338515 MD5 · raw file

  1. (ns lein-monolith.task.util-test
  2. (:require
  3. [clojure.test :refer [deftest testing is]]
  4. [lein-monolith.task.util :as u]))
  5. (deftest shell-escaping
  6. (is (= "nil" (u/shell-escape nil)))
  7. (is (= "123" (u/shell-escape 123)))
  8. (is (= "foo" (u/shell-escape "foo")))
  9. (is (= ":abc" (u/shell-escape :abc)))
  10. (is (= "'[123 true]'" (u/shell-escape [123 true])))
  11. (is (= "'\\'foo'" (u/shell-escape "'foo")))
  12. (is (= "'\"xyz\"'" (u/shell-escape "\"xyz\""))))
  13. (deftest kw-arg-parsing
  14. (testing "empty arguments"
  15. (is (= [{} []]
  16. (u/parse-kw-args {} [])))
  17. (is (= [{} []]
  18. (u/parse-kw-args {:foo 0} []))))
  19. (testing "flag options"
  20. (is (= [{:foo true} []]
  21. (u/parse-kw-args {:foo 0} [":foo"])))
  22. (is (= [{:foo true} ["bar"]]
  23. (u/parse-kw-args {:foo 0} [":foo" "bar"]))))
  24. (testing "single-value options"
  25. (is (= [{:abc "xyz"} ["123"]]
  26. (u/parse-kw-args {:abc 1} [":abc" "xyz" "123"])))
  27. (is (= [{} ["%" ":abc" "123"]]
  28. (u/parse-kw-args {:abc 1} ["%" ":abc" "123"]))))
  29. (testing "multi-arg options"
  30. (is (= [{:tri-arg ["1" "2" "3"]} ["abc"]]
  31. (u/parse-kw-args {:tri-arg 3} [":tri-arg" "1" "2" "3" "abc"])))
  32. (is (= [{:missing ["abc"]} []]
  33. (u/parse-kw-args {:missing 2} [":missing" "abc"])))
  34. (is (= [{:foo ["x" "y"]} ["bar"]]
  35. (u/parse-kw-args {:foo 2} [":foo" "a" "b" ":foo" "x" "y" "bar"]))
  36. "should overwrite prior option"))
  37. (testing "multi-value options"
  38. (is (= [{:foo ["a"]} []]
  39. (u/parse-kw-args {:foo* 1} [":foo" "a"])))
  40. (is (= [{:foo ["a" "b"], :bar true} []]
  41. (u/parse-kw-args {:foo* 1, :bar 0} [":foo" "a" ":bar" ":foo" "b"]))))
  42. (testing "combo args"
  43. (is (= [{:foo "1", :bar true} ["xyz"]]
  44. (u/parse-kw-args {:foo 1, :bar 0} [":foo" "1" ":bar" "xyz"])))
  45. (is (= [{:foo "x"} [":bar" "123" ":foo" "y"]]
  46. (u/parse-kw-args {:foo 1} [":foo" "x" ":bar" "123" ":foo" "y"]))
  47. "unknown arg should halt parsing")))