Refactor and finish rendering process, add new tests
[frak.git] / test / frak_test.clj
CommitLineData
fef2a3db
JH
1(ns frak-test
2 (:use clojure.test
3 frak))
4
5(def trie-put #'frak/trie-put)
6(def build-trie #'frak/build-trie)
7
8(deftest trie-test
d62e03b3
JH
9 (is (= (build-trie ["a" "b"])
10 {:char nil
11 :terminal? false
12 :children #{{:char \a
13 :terminal? true
14 :children #{}}
15 {:char \b
16 :terminal? true
17 :children #{}}}}))
18
19 (is (= (build-trie ["aaa" "ab"])
20 (build-trie ["ab" "aaa"])
21 {:char nil
22 :terminal? false
23 :children #{{:char \a
24 :terminal? false
25 :children #{{:char \a
26 :terminal? false
27 :children #{{:char \a
28 :terminal? true
29 :children #{}}}}
30 {:char \b
31 :terminal? true
32 :children #{}}}}}})))
fef2a3db
JH
33
34(deftest pattern-test
35 (let [strs1 ["foo" "bar" "baz"]
36 strs2 ["baz" "bar" "foo"]
e8b7ce94
JH
37 match1 (partial re-matches (pattern strs1))
38 match2 (partial re-matches (pattern strs2))]
39 (is (every? match1 strs1))
fef2a3db 40
e8b7ce94 41 (is (every? match2 strs1))
fef2a3db 42
e8b7ce94 43 (is (every? match1 strs2))
fef2a3db 44
e8b7ce94 45 (is (every? match2 strs2))
fef2a3db 46
e8b7ce94
JH
47 (is (not (or (match1 "f")
48 (match1 "b")
49 (match1 "ba")
50 (match1 "fo")))))
11fd73a8 51
d62e03b3
JH
52 (is (= (string-pattern ["foo" "foot"] nil)
53 (string-pattern ["foo" "" "foot"] nil)))
14a44feb 54
d62e03b3
JH
55 (is (= (re-matches
56 #"ba\[[trz]{3}\]"
57 (string-pattern ["bat" "bar" "baz"] nil))))
14a44feb
JH
58
59 (is (= "b(?:i[pt]|at)"
f68c3d55
JH
60 (string-pattern ["bat" "bip" "bit"] nil)))
61
62 (are [words] (every? #(re-matches (pattern words) %) words)
63 ["achy" "achylia" "achylous" "achymia" "achymous"]
64 ["aching" "achingly"]))