|
| 1 | +(ns neovim-client.nvim-test |
| 2 | + (:require [clojure.test :as test :refer [deftest use-fixtures is]] |
| 3 | + [neovim-client.nvim :as client.nvim])) |
| 4 | + |
| 5 | +(defn- neovim |
| 6 | + "Make a neovim subprocess." |
| 7 | + [] |
| 8 | + (let [p (.exec (Runtime/getRuntime) "nvim --embed")] |
| 9 | + {:process p |
| 10 | + :in (.getInputStream p) |
| 11 | + :out (.getOutputStream p)})) |
| 12 | + |
| 13 | +(defn- stop-neovim |
| 14 | + [{:keys [process]}] |
| 15 | + (.destroy process)) |
| 16 | + |
| 17 | +(defmacro with-neovim |
| 18 | + [& body] |
| 19 | + `(let [~'*neovim* (neovim)] |
| 20 | + (try |
| 21 | + ~@body |
| 22 | + (finally (stop-neovim ~'*neovim*))))) |
| 23 | + |
| 24 | +;; TODO - this one will be hard to test. From the client-library's perspective, |
| 25 | +;; it will always have access to standard out. If it runs at all, standard |
| 26 | +;; out will exist. So is this worth testing? |
| 27 | +(deftest connect-fail-not-running |
| 28 | + (is true)) |
| 29 | + |
| 30 | +(deftest connect |
| 31 | + (with-neovim |
| 32 | + (let [{:keys [in out]} *neovim*] |
| 33 | + (is (not (client.nvim/version-supported? |
| 34 | + (client.nvim/new* -1 in out false)))))) |
| 35 | + |
| 36 | + (with-neovim |
| 37 | + (let [{:keys [in out]} *neovim*] |
| 38 | + (is (not (client.nvim/version-supported? |
| 39 | + (client.nvim/new* 2 in out false)))))) |
| 40 | + |
| 41 | + (with-neovim |
| 42 | + (let [{:keys [in out]} *neovim*] |
| 43 | + (is (client.nvim/version-supported? |
| 44 | + (client.nvim/new* 0 in out false))))) |
| 45 | + |
| 46 | + (with-neovim |
| 47 | + (let [{:keys [in out]} *neovim*] |
| 48 | + (is (client.nvim/version-supported? |
| 49 | + (client.nvim/new* 1 in out false)))))) |
| 50 | + |
| 51 | +#_(clojure.tools.namespace.repl/refresh) |
| 52 | +#_(clojure.test/run-tests 'neovim-client.nvim-test) |
0 commit comments