Add missing call to escape
[frak.git] / test / frak_test.clj
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
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 #{}}}}}})))
33
34 (deftest pattern-test
35 (let [strs1 ["foo" "bar" "baz"]
36 strs2 ["baz" "bar" "foo"]
37 match1 (partial re-matches (pattern strs1))
38 match2 (partial re-matches (pattern strs2))]
39 (is (every? match1 strs1))
40
41 (is (every? match2 strs1))
42
43 (is (every? match1 strs2))
44
45 (is (every? match2 strs2))
46
47 (is (not (or (match1 "f")
48 (match1 "b")
49 (match1 "ba")
50 (match1 "fo")))))
51
52 (is (= (string-pattern ["foo" "foot"] nil)
53 (string-pattern ["foo" "" "foot"] nil)))
54
55 (is (= (re-matches
56 #"ba\[[trz]{3}\]"
57 (string-pattern ["bat" "bar" "baz"] nil))))
58
59 (is (= "b(?:i[pt]|at)"
60 (string-pattern ["bat" "bip" "bit"] nil)))
61
62 (is (= "foo\\??"
63 (string-pattern ["foo" "foo?"])))
64
65 (are [words] (every? #(re-matches (pattern words) %) words)
66 ["achy" "achylia" "achylous" "achymia" "achymous"]
67 ["aching" "achingly"]))