Skip to content

Commit fe5334c

Browse files
committed
Add tests for command
1 parent a598fd2 commit fe5334c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(ns eca.features.commands-test
2+
(:require
3+
[clojure.test :refer [deftest is testing]]
4+
[eca.features.commands :as f.commands]))
5+
6+
(deftest get-custom-command-tests
7+
(testing "returns nil when command not found"
8+
(is (nil? (#'f.commands/get-custom-command "nope" [] []))))
9+
10+
(testing "$ARGS is replaced with the joined args"
11+
(let [custom [{:name "greet" :content "Hello $ARGS!"}]]
12+
(is (= "Hello Alice Bob!"
13+
(#'f.commands/get-custom-command "greet" ["Alice" "Bob"] custom)))))
14+
15+
(testing "numbered $ARGn placeholders are replaced and $ARGS contains all args"
16+
(let [custom [{:name "pair" :content "First:$ARG1 Second:$ARG2 All:$ARGS"}]]
17+
(is (= "First:one Second:two All:one two"
18+
(#'f.commands/get-custom-command "pair" ["one" "two"] custom)))))
19+
20+
(testing "unmatched placeholders remain when args are missing"
21+
(let [custom [{:name "partial" :content "A:$ARG1 B:$ARG2 C:$ARG3"}]]
22+
(is (= "A:only B: C:$ARG3"
23+
(#'f.commands/get-custom-command "partial" ["only" ""] custom)))))
24+
25+
(testing "multiple occurrences of the same placeholder are all replaced"
26+
(let [custom [{:name "dup" :content "$ARG1-$ARG1 $ARGS"}]]
27+
(is (= "x-x x y"
28+
(#'f.commands/get-custom-command "dup" ["x" "y"] custom))))))

0 commit comments

Comments
 (0)