|
1 | 1 | (ns vim.indent-test
|
2 |
| - (:require [clojure.test :refer [deftest]] |
3 |
| - [vim.test :refer [test-indent]])) |
| 2 | + (:require [clojure.test :refer [deftest testing is]] |
| 3 | + [clojure.string :as str] |
| 4 | + [clojure.java.io :as io] |
| 5 | + [vim.helpers :as h]) |
| 6 | + (:import [java.io File])) |
4 | 7 |
|
5 |
| -(deftest test-basic-sexp-indent |
6 |
| - (test-indent "works as expected with basic S-expressions" |
7 |
| - :in "test-basic-sexp-indent.txt" |
8 |
| - :out "test-basic-sexp-indent.txt")) |
| 8 | +(defn get-test-cases [^File test-case-dir] |
| 9 | + (into [] |
| 10 | + (comp |
| 11 | + (filter #(.isDirectory ^File %)) |
| 12 | + (map #(.getName ^File %))) |
| 13 | + (.listFiles test-case-dir))) |
9 | 14 |
|
10 |
| -(deftest test-multibyte-indent |
11 |
| - (test-indent "with multibyte characters" |
12 |
| - :in "test-multibyte-indent.txt" |
13 |
| - :out "test-multibyte-indent.txt")) |
| 15 | +(defn run-test-case [test-case-dir test-case] |
| 16 | + (testing (str "Preparation for " test-case) |
| 17 | + (let [input (io/file test-case-dir test-case "in.clj") |
| 18 | + expected (io/file test-case-dir test-case "out.clj") |
| 19 | + actual (File/createTempFile test-case ".clj") |
| 20 | + config (let [f (io/file test-case-dir test-case "config.edn")] |
| 21 | + (or (h/read-edn-file f) {})) |
| 22 | + cmds (concat (:extra-cmds config) |
| 23 | + (when (:indent? config true) ["normal! gg=G"]) |
| 24 | + ["write"])] |
| 25 | + (io/make-parents actual) |
| 26 | + (io/copy input actual) |
| 27 | + (h/vim! actual cmds :vimrc (io/file "vim/test-runtime.vim")) |
| 28 | + {:test-case test-case |
| 29 | + :expected (slurp expected) |
| 30 | + :expected-file expected |
| 31 | + :actual (slurp actual) |
| 32 | + :actual-file actual}))) |
14 | 33 |
|
15 |
| -(deftest test-inherit-indent |
16 |
| - (test-indent "is inherited from previous element" |
17 |
| - :in "test-inherit-indent.in" |
18 |
| - :out "test-inherit-indent.out" |
19 |
| - :keys "/α\\<CR>s\\<C-O>Oa\\<Esc>/β\\<CR>s\\<CR>\\<CR>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>b\\<CR>c\\<CR>\\<CR>d\\<Esc>")) |
20 |
| - |
21 |
| -(deftest test-side-effects-in-indentexpr |
22 |
| - (test-indent "GetClojureIndent does not move cursor" |
23 |
| - :in "test-side-effects-in-indentexpr.in" |
24 |
| - :out "test-side-effects-in-indentexpr.out" |
25 |
| - :keys "/α\\<CR>:call GetClojureIndent()\\<CR>rxj:call GetClojureIndent()\\<CR>ry")) |
26 |
| - |
27 |
| -(deftest test-reader-conditional-indent |
28 |
| - (test-indent "reader conditionals are indented like maps" |
29 |
| - :in "test-reader-conditional-indent.in" |
30 |
| - :out "test-reader-conditional-indent.out")) |
31 |
| - |
32 |
| -(deftest test-dispatch-macro-indent |
33 |
| - (test-indent "dispatch macro indentation is handled correctly" |
34 |
| - :in "test-dispatch-macro-indent.in" |
35 |
| - :out "test-dispatch-macro-indent.out")) |
36 |
| - |
37 |
| -(deftest test-special-case-indent |
38 |
| - (test-indent "special case indentation is handled correctly" |
39 |
| - :in "test-special-case-indent.in" |
40 |
| - :out "test-special-case-indent.out")) |
| 34 | +;; TODO: do this parallisation more intelligently with agents. |
| 35 | +(deftest test-indent |
| 36 | + "Runs all indentation tests in parallel" |
| 37 | + (let [test-case-dir (io/file (io/resource "indent-test-cases")) |
| 38 | + test-cases (get-test-cases test-case-dir)] |
| 39 | + (doseq [{:keys [test-case expected expected-file actual actual-file]} |
| 40 | + (pmap (partial run-test-case test-case-dir) test-cases)] |
| 41 | + (testing test-case |
| 42 | + (is (= expected actual) |
| 43 | + (format "(not= \"%s\"\n \"%s\")" expected-file actual-file)))))) |
0 commit comments