|
3 | 3 | (local extract (require :conjure.extract)) |
4 | 4 | (local {: with-buf} (require :conjure-spec.util)) |
5 | 5 |
|
| 6 | +(fn ex [...] |
| 7 | + (let [result (extract.form ...)] |
| 8 | + (when result |
| 9 | + (set result.node nil)) |
| 10 | + result)) |
| 11 | + |
6 | 12 | (describe :extract |
7 | 13 | (fn [] |
8 | 14 | (describe :current-form |
|
15 | 21 | (assert.same {:range {:start [3 9] |
16 | 22 | :end [3 16]} |
17 | 23 | :content "(* 10 2)"} |
18 | | - (extract.form {})))) |
| 24 | + (ex {})))) |
19 | 25 | (it "on the opening paren" |
20 | 26 | (fn [] |
21 | 27 | (at [3 9]) |
22 | 28 | (assert.same {:range {:start [3 9] |
23 | 29 | :end [3 16]} |
24 | 30 | :content "(* 10 2)"} |
25 | | - (extract.form {})))) |
| 31 | + (ex {})))) |
26 | 32 | (it "on the closing paren" |
27 | 33 | (fn [] |
28 | 34 | (at [3 16]) |
29 | 35 | (assert.same {:range {:start [3 9] |
30 | 36 | :end [3 16]} |
31 | 37 | :content "(* 10 2)"} |
32 | | - (extract.form {})))) |
| 38 | + (ex {})))) |
33 | 39 | (it "one before the inner form" |
34 | 40 | (fn [] |
35 | 41 | (at [3 8]) |
36 | 42 | (assert.same {:range {:start [3 0] |
37 | 43 | :end [3 17]} |
38 | 44 | :content "(+ 10 20 (* 10 2))"} |
39 | | - (extract.form {})))) |
| 45 | + (ex {})))) |
40 | 46 | (it "on the last paren of the outer form" |
41 | 47 | (fn [] |
42 | 48 | (at [3 17]) |
43 | 49 | (assert.same {:range {:start [3 0] |
44 | 50 | :end [3 17]} |
45 | 51 | :content "(+ 10 20 (* 10 2))"} |
46 | | - (extract.form {})))) |
| 52 | + (ex {})))) |
47 | 53 | (it "matching nothing" |
48 | 54 | (fn [] |
49 | 55 | (at [2 0]) |
50 | | - (assert.are.equals nil (extract.form {})))) |
| 56 | + (assert.are.equals nil (ex {})))) |
51 | 57 | (it "ns form" |
52 | 58 | (fn [] |
53 | 59 | (at [1 0]) |
54 | 60 | (assert.same {:range {:start [1 0] |
55 | 61 | :end [1 7]} |
56 | 62 | :content "(ns foo)"} |
57 | | - (extract.form {})))))))) |
| 63 | + (ex {})))))))) |
58 | 64 | (describe :root-form |
59 | 65 | (fn [] |
60 | 66 | (with-buf ["(ns foo)" "" "(+ 10 20 (* 10 2))"] |
|
65 | 71 | (assert.same {:range {:start [3 0] |
66 | 72 | :end [3 17]} |
67 | 73 | :content "(+ 10 20 (* 10 2))"} |
68 | | - (extract.form {:root? true})))) |
| 74 | + (ex {:root? true})))) |
69 | 75 | (it "root from the root" |
70 | 76 | (fn [] |
71 | 77 | (at [3 6]) |
72 | 78 | (assert.same {:range {:start [3 0] |
73 | 79 | :end [3 17]} |
74 | 80 | :content "(+ 10 20 (* 10 2))"} |
75 | | - (extract.form {:root? true})))) |
| 81 | + (ex {:root? true})))) |
76 | 82 | (it "root from the opening paren of the root" |
77 | 83 | (fn [] |
78 | 84 | (at [3 0]) |
79 | 85 | (assert.same {:range {:start [3 0] |
80 | 86 | :end [3 17]} |
81 | 87 | :content "(+ 10 20 (* 10 2))"} |
82 | | - (extract.form {:root? true})))) |
| 88 | + (ex {:root? true})))) |
83 | 89 | (it "root from the opening paren of the child form" |
84 | 90 | (fn [] |
85 | 91 | (at [3 9]) |
86 | 92 | (assert.same {:range {:start [3 0] |
87 | 93 | :end [3 17]} |
88 | 94 | :content "(+ 10 20 (* 10 2))"} |
89 | | - (extract.form {:root? true})))) |
| 95 | + (ex {:root? true})))) |
90 | 96 | (it "matching nothing for root" |
91 | 97 | (fn [] |
92 | 98 | (at [2 0]) |
93 | | - (assert.equals nil |
94 | | - (extract.form {:root? true})))))))) |
| 99 | + (assert.equals nil (ex {:root? true})))))))) |
95 | 100 | (describe :ignoring-comments |
96 | 101 | (fn [] |
97 | 102 | (with-buf ["(ns ohno)" "" "(inc" " ; ()" " 5)"] |
|
102 | 107 | (assert.same {:range {:start [3 0] |
103 | 108 | :end [5 2]} |
104 | 109 | :content "(inc\n ; ()\n 5)"} |
105 | | - (extract.form {})))) |
| 110 | + (ex {})))) |
106 | 111 | (it "skips the comment paren with root form" |
107 | 112 | (fn [] |
108 | 113 | (at [4 0]) |
109 | 114 | (assert.same {:range {:start [3 0] |
110 | 115 | :end [5 2]} |
111 | 116 | :content "(inc\n ; ()\n 5)"} |
112 | | - (extract.form {:root? true})))))))) |
| 117 | + (ex {:root? true})))))))) |
113 | 118 | (describe :escaped-parens |
114 | 119 | (fn [] |
115 | 120 | (with-buf ["(str \\))"] |
|
120 | 125 | (assert.same {:range {:start [1 0] |
121 | 126 | :end [1 7]} |
122 | 127 | :content "(str \\))"} |
123 | | - (extract.form {})))))) |
| 128 | + (ex {})))))) |
124 | 129 | (with-buf |
125 | 130 | ["(ns foo)" |
126 | 131 | "" |
|
138 | 143 | (assert.same {:range {:start [5 0] |
139 | 144 | :end [5 6]} |
140 | 145 | :content "(+ 1 2)"} |
141 | | - (extract.form {:root? true})))))))))) |
| 146 | + (ex {:root? true})))))))))) |
0 commit comments