Skip to content

Commit 786793b

Browse files
committed
Add unit tests, fix async bug
1 parent 7a2a975 commit 786793b

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

src/neovim_client/nvim.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
[component op & args]
2525
(rpc/send-message-async!
2626
component
27-
(message/->request-msg op (vec (rest args)))
27+
(message/->request-msg op (vec (butlast args)))
2828
(last args)))
2929

3030
(def register-method! rpc/register-method!)

src/user.clj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
(ns user
22
(:require
3-
[neovim-client.nvim :as nvim]
4-
[clojure.tools.namespace.repl :refer [refresh]]))
3+
[clojure.test]
4+
[clojure.tools.namespace.repl :refer [refresh]]
5+
[neovim-client.nvim :as nvim]))
56

67
(defn tcp-connection
78
"Get an nvim connection."
89
[]
9-
(nvim/new "localhost" 7777))
10+
(nvim/new 1 "localhost" 7777))
11+
12+
(defn run-tests
13+
"Run all tests with clojure.test"
14+
[]
15+
(refresh)
16+
(clojure.test/run-all-tests))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(ns neovim-client.1.api.buffer-ext-test
2+
(:require [clojure.core.async :as async]
3+
[clojure.test :as test :refer [deftest use-fixtures is]]
4+
[neovim-client.1.api :as api]
5+
[neovim-client.1.api.buffer :as api.buffer]
6+
[neovim-client.1.api.buffer-ext :as api.buffer-ext]
7+
[neovim-client.nvim :as client.nvim]
8+
[neovim-client.test-helper :refer [with-neovim]]))
9+
10+
(deftest get-lines
11+
(with-neovim
12+
(let [{:keys [in out]} *neovim*
13+
conn (client.nvim/new* 1 in out false)]
14+
(api/command conn "norm ifoo\nbar\nbaz\nqux")
15+
(is (= ["bar" "baz"] (api.buffer-ext/get-lines
16+
conn
17+
(api/get-current-buf conn)
18+
1 3))))))
19+
20+
(deftest get-lines-async
21+
(with-neovim
22+
(let [{:keys [in out]} *neovim*
23+
conn (client.nvim/new* 1 in out false)
24+
p (promise)]
25+
(api/command conn "norm ifoo\nbar\nbaz\nqux")
26+
(api.buffer-ext/get-lines-async
27+
conn
28+
(api/get-current-buf conn)
29+
1 3
30+
#(deliver p %))
31+
(is (= ["bar" "baz"] @p)))))

test/neovim_client/1/api_ext_test.clj

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns neovim-client.1.api-ext-test
2-
(:require [clojure.test :as test :refer [deftest use-fixtures is]]
2+
(:require [clojure.core.async :as async]
3+
[clojure.test :as test :refer [deftest use-fixtures is]]
34
[neovim-client.1.api :as api]
45
[neovim-client.1.api.buffer :as api.buffer]
56
[neovim-client.1.api-ext :as api-ext]
@@ -15,6 +16,32 @@
1516
(is (= row 3))
1617
(is (= col 2))))))
1718

18-
;; TODO get-current-buffer-text
19-
;; TODO get-current-word-async
20-
;; TODO buffer-visible?-async
19+
(deftest get-current-buffer-text
20+
(with-neovim
21+
(let [{:keys [in out]} *neovim*
22+
conn (client.nvim/new* 1 in out false)]
23+
(api/command conn "norm ifoo\nbar\nbaz")
24+
(api/command conn "new")
25+
(api/command conn "norm iqux")
26+
(let [text (api-ext/get-current-buffer-text conn)]
27+
(is (= text "qux"))))))
28+
29+
(deftest get-current-word-async
30+
(with-neovim
31+
(let [{:keys [in out]} *neovim*
32+
conn (client.nvim/new* 1 in out false)]
33+
(api/command conn "norm ifoo\nbar\nbaz")
34+
(api/command conn "norm bb")
35+
(let [p (promise)] (api-ext/get-current-word-async conn #(deliver p %))
36+
(is (= @p "bar"))))))
37+
38+
(deftest buffer-visible?-async
39+
(with-neovim
40+
(let [{:keys [in out]} *neovim*
41+
conn (client.nvim/new* 1 in out false)
42+
filename (str "/tmp/" (java.util.UUID/randomUUID))]
43+
44+
(spit filename "test")
45+
(api/command conn (str "e " filename))
46+
(is (= filename
47+
(async/<!! (api-ext/buffer-visible?-async conn filename)))))))

0 commit comments

Comments
 (0)