|
76 | 76 | ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
77 | 77 | {"path" (h/file-path "/foo/qux")} |
78 | 78 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
79 | | - (testing "heading a file" |
| 79 | + (testing "with line_offset" |
80 | 80 | (is (match? |
81 | 81 | {:contents [{:type :text |
82 | 82 | :error false |
83 | | - :content "fooo\nbar"}]} |
84 | | - (with-redefs [slurp (constantly "fooo\nbar\nbaz") |
| 83 | + :content "line3\nline4\nline5"}]} |
| 84 | + (with-redefs [slurp (constantly "line1\nline2\nline3\nline4\nline5") |
85 | 85 | fs/exists? (constantly true) |
86 | 86 | fs/readable? (constantly true) |
87 | 87 | f.tools.filesystem/allowed-path? (constantly true)] |
88 | 88 | ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
89 | | - {"path" (h/file-path "/foo/qux") |
90 | | - "head" 2} |
| 89 | + {"path" (h/file-path "/foo/qux") "line_offset" 2} |
91 | 90 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
92 | | - (testing "tailling a file" |
| 91 | + (testing "with limit" |
93 | 92 | (is (match? |
94 | 93 | {:contents [{:type :text |
95 | 94 | :error false |
96 | | - :content "bar\nbaz"}]} |
97 | | - (with-redefs [slurp (constantly "fooo\nbar\nbaz") |
| 95 | + :content "line1\nline2"}]} |
| 96 | + (with-redefs [slurp (constantly "line1\nline2\nline3\nline4\nline5") |
98 | 97 | fs/exists? (constantly true) |
99 | 98 | fs/readable? (constantly true) |
100 | 99 | f.tools.filesystem/allowed-path? (constantly true)] |
101 | 100 | ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
102 | | - {"path" (h/file-path "/foo/qux") |
103 | | - "tail" 2} |
| 101 | + {"path" (h/file-path "/foo/qux") "limit" 2} |
| 102 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}}))))) |
| 103 | + (testing "with line_offset and limit" |
| 104 | + (is (match? |
| 105 | + {:contents [{:type :text |
| 106 | + :error false |
| 107 | + :content "line3\nline4"}]} |
| 108 | + (with-redefs [slurp (constantly "line1\nline2\nline3\nline4\nline5") |
| 109 | + fs/exists? (constantly true) |
| 110 | + fs/readable? (constantly true) |
| 111 | + f.tools.filesystem/allowed-path? (constantly true)] |
| 112 | + ((get-in f.tools.filesystem/definitions ["eca_read_file" :handler]) |
| 113 | + {"path" (h/file-path "/foo/qux") "line_offset" 2 "limit" 2} |
104 | 114 | {:db {:workspace-folders [{:uri (h/file-uri "file:///foo/bar/baz") :name "foo"}]}})))))) |
105 | 115 |
|
106 | 116 | (deftest write-file-test |
|
119 | 129 | (deftest search-files-test |
120 | 130 | (testing "invalid pattern" |
121 | 131 | (is (match? |
122 | | - {:contents [{:type :text |
123 | | - :error true |
124 | | - :content "Invalid glob pattern ' '"}]} |
125 | | - (with-redefs [fs/exists? (constantly true)] |
126 | | - ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
127 | | - {"path" (h/file-path "/project/foo") |
128 | | - "pattern" " "} |
129 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
| 132 | + {:contents [{:type :text |
| 133 | + :error true |
| 134 | + :content "Invalid glob pattern ' '"}]} |
| 135 | + (with-redefs [fs/exists? (constantly true)] |
| 136 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
| 137 | + {"path" (h/file-path "/project/foo") |
| 138 | + "pattern" " "} |
| 139 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
130 | 140 | (testing "no matches" |
131 | 141 | (is (match? |
132 | | - {:contents [{:type :text |
133 | | - :error false |
134 | | - :content "No matches found"}]} |
135 | | - (with-redefs [fs/exists? (constantly true) |
136 | | - fs/glob (constantly [])] |
137 | | - ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
138 | | - {"path" (h/file-path "/project/foo") |
139 | | - "pattern" "foo"} |
140 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
| 142 | + {:contents [{:type :text |
| 143 | + :error false |
| 144 | + :content "No matches found"}]} |
| 145 | + (with-redefs [fs/exists? (constantly true) |
| 146 | + fs/glob (constantly [])] |
| 147 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
| 148 | + {"path" (h/file-path "/project/foo") |
| 149 | + "pattern" "foo"} |
| 150 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
141 | 151 | (testing "matches with wildcard" |
142 | 152 | (is (match? |
143 | | - {:contents [{:type :text |
144 | | - :error false |
145 | | - :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
146 | | - (h/file-path "/project/foo/qux.txt") "\n" |
147 | | - (h/file-path "/project/foo/qux.clj"))}]} |
148 | | - (with-redefs [fs/exists? (constantly true) |
149 | | - fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
150 | | - (fs/path (h/file-path "/project/foo/qux.txt")) |
151 | | - (fs/path (h/file-path "/project/foo/qux.clj"))])] |
152 | | - ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
153 | | - {"path" (h/file-path "/project/foo") |
154 | | - "pattern" "**"} |
155 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
| 153 | + {:contents [{:type :text |
| 154 | + :error false |
| 155 | + :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
| 156 | + (h/file-path "/project/foo/qux.txt") "\n" |
| 157 | + (h/file-path "/project/foo/qux.clj"))}]} |
| 158 | + (with-redefs [fs/exists? (constantly true) |
| 159 | + fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
| 160 | + (fs/path (h/file-path "/project/foo/qux.txt")) |
| 161 | + (fs/path (h/file-path "/project/foo/qux.clj"))])] |
| 162 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
| 163 | + {"path" (h/file-path "/project/foo") |
| 164 | + "pattern" "**"} |
| 165 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}}))))) |
156 | 166 | (testing "matches without wildcard" |
157 | 167 | (is (match? |
158 | | - {:contents [{:type :text |
159 | | - :error false |
160 | | - :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
161 | | - (h/file-path "/project/foo/qux.txt"))}]} |
162 | | - (with-redefs [fs/exists? (constantly true) |
163 | | - fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
164 | | - (fs/path (h/file-path "/project/foo/qux.txt"))])] |
165 | | - ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
166 | | - {"path" (h/file-path "/project/foo") |
167 | | - "pattern" ".txt"} |
168 | | - {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))) |
| 168 | + {:contents [{:type :text |
| 169 | + :error false |
| 170 | + :content (str (h/file-path "/project/foo/bar/baz.txt") "\n" |
| 171 | + (h/file-path "/project/foo/qux.txt"))}]} |
| 172 | + (with-redefs [fs/exists? (constantly true) |
| 173 | + fs/glob (constantly [(fs/path (h/file-path "/project/foo/bar/baz.txt")) |
| 174 | + (fs/path (h/file-path "/project/foo/qux.txt"))])] |
| 175 | + ((get-in f.tools.filesystem/definitions ["eca_search_files" :handler]) |
| 176 | + {"path" (h/file-path "/project/foo") |
| 177 | + "pattern" ".txt"} |
| 178 | + {:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}})))))) |
169 | 179 |
|
170 | 180 | (deftest grep-test |
171 | 181 | (testing "invalid pattern" |
|
0 commit comments