Skip to content

Commit 7a2a975

Browse files
committed
Add api-ext test
1 parent e0fc8b5 commit 7a2a975

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

src/neovim_client/1/api_ext.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
[neovim-client.1.api.window :as api.window]))
99

1010
(defn get-cursor-location
11-
"Gets the cursor's current position as a tuple (row, col)."
11+
"Gets the cursor's current position as a tuple (row, col).
12+
row - starts at 1
13+
col - starts at 0"
1214
[nvim]
1315
(api.window/get-cursor nvim (api/get-current-win nvim)))
1416

test/neovim_client/1/api_ext_test.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns neovim-client.1.api-ext-test
2+
(:require [clojure.test :as test :refer [deftest use-fixtures is]]
3+
[neovim-client.1.api :as api]
4+
[neovim-client.1.api.buffer :as api.buffer]
5+
[neovim-client.1.api-ext :as api-ext]
6+
[neovim-client.nvim :as client.nvim]
7+
[neovim-client.test-helper :refer [with-neovim]]))
8+
9+
(deftest get-cursor-location
10+
(with-neovim
11+
(let [{:keys [in out]} *neovim*
12+
conn (client.nvim/new* 1 in out false)]
13+
(api/command conn "norm ifoo\nbar\nbaz")
14+
(let [[row col] (api-ext/get-cursor-location conn)]
15+
(is (= row 3))
16+
(is (= col 2))))))
17+
18+
;; TODO get-current-buffer-text
19+
;; TODO get-current-word-async
20+
;; TODO buffer-visible?-async

test/neovim_client/nvim_test.clj

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,8 @@
22
(:require [clojure.test :as test :refer [deftest use-fixtures is]]
33
[neovim-client.1.api :as api]
44
[neovim-client.1.api.buffer :as api.buffer]
5-
[neovim-client.nvim :as client.nvim]))
6-
7-
(defn- neovim
8-
"Make a neovim subprocess."
9-
[]
10-
(let [p (.exec (Runtime/getRuntime) "nvim --embed")]
11-
{:process p
12-
:in (.getInputStream p)
13-
:out (.getOutputStream p)}))
14-
15-
(defn- stop-neovim
16-
[{:keys [process]}]
17-
(.destroy process))
18-
19-
(defmacro with-neovim
20-
[& body]
21-
`(let [~'*neovim* (neovim)]
22-
(try
23-
~@body
24-
(finally (stop-neovim ~'*neovim*)))))
5+
[neovim-client.nvim :as client.nvim]
6+
[neovim-client.test-helper :refer [with-neovim stop-neovim]]))
257

268
;; TODO - this one will be hard to test. From the client-library's perspective,
279
;; it will always have access to standard out. If it runs at all, standard
@@ -63,7 +45,3 @@
6345
_ (api.buffer/set-lines conn b2 0 1 false ["bar"])]
6446
(is (= ["foo"] (api.buffer/get-lines conn b1 0 1 false)))
6547
(is (= ["bar"] (api.buffer/get-lines conn b2 0 1 false)))))))
66-
67-
#_(clojure.tools.namespace.repl/refresh)
68-
#_(clojure.test/run-tests 'neovim-client.nvim-test)
69-
#_(neovim-client.nvim-test/change-buffer-text)

test/neovim_client/test_helper.clj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(ns neovim-client.test-helper)
2+
3+
(defn neovim
4+
"Make a neovim subprocess."
5+
[]
6+
(let [p (.exec (Runtime/getRuntime) "nvim --embed")]
7+
{:process p
8+
:in (.getInputStream p)
9+
:out (.getOutputStream p)}))
10+
11+
(defn stop-neovim
12+
[{:keys [process]}]
13+
(.destroy process))
14+
15+
(defmacro with-neovim
16+
[& body]
17+
`(let [~'*neovim* (neovim)]
18+
(try
19+
~@body
20+
(finally (stop-neovim ~'*neovim*)))))

0 commit comments

Comments
 (0)