|
43 | 43 | (testing "returns len for an unterminated string" |
44 | 44 | (is (= 4 (sut/skip-string "\"abc" 0))))) |
45 | 45 |
|
46 | | -(deftest unmatched-brackets-test |
| 46 | +(deftest bracket-scan-unmatched-test |
47 | 47 | (testing "balanced inputs have no bad brackets" |
48 | | - (is (= #{} (sut/unmatched-brackets ""))) |
49 | | - (is (= #{} (sut/unmatched-brackets "(foo)"))) |
50 | | - (is (= #{} (sut/unmatched-brackets "[1 2 3]"))) |
51 | | - (is (= #{} (sut/unmatched-brackets "{:a 1}"))) |
52 | | - (is (= #{} (sut/unmatched-brackets "(let [x 1] (* x 2))")))) |
| 48 | + (is (= #{} (:unmatched (sut/bracket-scan "")))) |
| 49 | + (is (= #{} (:unmatched (sut/bracket-scan "(foo)")))) |
| 50 | + (is (= #{} (:unmatched (sut/bracket-scan "[1 2 3]")))) |
| 51 | + (is (= #{} (:unmatched (sut/bracket-scan "{:a 1}")))) |
| 52 | + (is (= #{} (:unmatched (sut/bracket-scan "(let [x 1] (* x 2))"))))) |
53 | 53 | (testing "unclosed openers are flagged at their position" |
54 | | - (is (= #{0} (sut/unmatched-brackets "("))) |
55 | | - (is (= #{0} (sut/unmatched-brackets "(foo"))) |
56 | | - (is (= #{0 11} (sut/unmatched-brackets "(let [x 1] (foo")))) |
| 54 | + (is (= #{0} (:unmatched (sut/bracket-scan "(")))) |
| 55 | + (is (= #{0} (:unmatched (sut/bracket-scan "(foo")))) |
| 56 | + (is (= #{0 11} (:unmatched (sut/bracket-scan "(let [x 1] (foo"))))) |
57 | 57 | (testing "stray closers are flagged" |
58 | | - (is (= #{0} (sut/unmatched-brackets ")"))) |
59 | | - (is (= #{4} (sut/unmatched-brackets "(a) ]")))) |
| 58 | + (is (= #{0} (:unmatched (sut/bracket-scan ")")))) |
| 59 | + (is (= #{4} (:unmatched (sut/bracket-scan "(a) ]"))))) |
60 | 60 | (testing "mismatched type flags both open and close" |
61 | | - (is (= #{0 2} (sut/unmatched-brackets "(a]")))) |
| 61 | + (is (= #{0 2} (:unmatched (sut/bracket-scan "(a]"))))) |
62 | 62 | (testing "brackets inside strings are ignored" |
63 | | - (is (= #{} (sut/unmatched-brackets "\"(\"")))) |
| 63 | + (is (= #{} (:unmatched (sut/bracket-scan "\"(\""))))) |
64 | 64 | (testing "char literal consumes its char" |
65 | | - (is (= #{} (sut/unmatched-brackets "\\("))) |
66 | | - (is (= #{} (sut/unmatched-brackets "\\)"))) |
67 | | - (is (= #{2} (sut/unmatched-brackets "\\;)")))) |
| 65 | + (is (= #{} (:unmatched (sut/bracket-scan "\\(")))) |
| 66 | + (is (= #{} (:unmatched (sut/bracket-scan "\\)")))) |
| 67 | + (is (= #{2} (:unmatched (sut/bracket-scan "\\;)"))))) |
68 | 68 | (testing "brackets after comments are ignored" |
69 | | - (is (= #{} (sut/unmatched-brackets ";(")))) |
| 69 | + (is (= #{} (:unmatched (sut/bracket-scan ";("))))) |
70 | 70 | (testing "brackets in regex are ignored" |
71 | | - (is (= #{} (sut/unmatched-brackets "#\"(\""))))) |
| 71 | + (is (= #{} (:unmatched (sut/bracket-scan "#\"(\"")))))) |
| 72 | + |
| 73 | +(deftest bracket-scan-spans-test |
| 74 | + (testing "spans for each matched pair" |
| 75 | + (is (= [] (:spans (sut/bracket-scan "")))) |
| 76 | + (is (= [[0 5]] (:spans (sut/bracket-scan "(foo)")))) |
| 77 | + (is (= [[5 10] [11 18] [0 19]] (:spans (sut/bracket-scan "(let [x 1] (+ x 2))"))))) |
| 78 | + (testing "unmatched brackets have no span" |
| 79 | + (is (= [] (:spans (sut/bracket-scan "(foo")))) |
| 80 | + (is (= [] (:spans (sut/bracket-scan "(a]"))))) |
| 81 | + (testing " strings and comments do not gen create spans" |
| 82 | + (is (= [] (:spans (sut/bracket-scan "\"(\"")))) |
| 83 | + (is (= [] (:spans (sut/bracket-scan ";(")))))) |
72 | 84 |
|
73 | 85 | (deftest indent-column-test |
74 | | - (testing "balanced inputs return zero" |
75 | | - (is (= 0 (sut/indent-column ""))) |
76 | | - (is (= 0 (sut/indent-column "(foo)"))) |
77 | | - (is (= 0 (sut/indent-column "[1 2 3]")))) |
78 | | - (testing "single unclosed opener at start of buffer" |
79 | | - (is (= 1 (sut/indent-column "(foo"))) |
80 | | - (is (= 1 (sut/indent-column "[1 2 3")))) |
81 | | - (testing "unclosed opener with leading content" |
82 | | - (is (= 4 (sut/indent-column "abc(def")))) |
83 | | - (testing "nested openers indent to the innermost" |
84 | | - (is (= 12 (sut/indent-column "(let [x 1] (foo")))) |
| 86 | + (testing "cursor not in form" |
| 87 | + (is (= 0 (sut/indent-column "" 0))) |
| 88 | + (is (= 0 (sut/indent-column "(foo)" 5))) |
| 89 | + (is (= 0 (sut/indent-column "[1 2 3]" 7)))) |
| 90 | + (testing "cursor at the end of unclosed line" |
| 91 | + (is (= 1 (sut/indent-column "(foo" 4))) |
| 92 | + (is (= 1 (sut/indent-column "[1 2 3" 6))) |
| 93 | + (is (= 4 (sut/indent-column "abc(def" 7))) |
| 94 | + (is (= 12 (sut/indent-column "(let [x 1] (foo" 15)))) |
| 95 | + (testing "paired mode curosr inside a balanced form" |
| 96 | + (is (= 1 (sut/indent-column "(+ 5 6)" 6))) |
| 97 | + (is (= 6 (sut/indent-column "(let [y 7])" 9))) |
| 98 | + (is (= 1 (sut/indent-column "(let [y 7])" 10)))) |
| 99 | + (testing "cursor beyond balanced for does not indent" |
| 100 | + (is (= 1 (sut/indent-column "(foo (bar)" 10)))) |
85 | 101 | (testing "indent is relative to the current line" |
86 | | - (is (= 2 (sut/indent-column "(let\n (foo"))))) |
| 102 | + (is (= 2 (sut/indent-column "(let\n (foo" 10))))) |
0 commit comments