Skip to content

Commit

Permalink
Test: Simple keyboard input <-> read buffer roundtrip (#20)
Browse files Browse the repository at this point in the history
* Validate neovim reads input and sends us data back

* Test to validate Neovim can take input and respond
  • Loading branch information
bryphe committed Jan 11, 2019
1 parent aa8ee5c commit 847a7d1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
22 changes: 22 additions & 0 deletions test/editor/Neovim/Helpers.re
@@ -1,5 +1,7 @@
open Rench;

open Oni_Neovim;

exception EnvironmentVariableNotFound;

let optOrThrow = (s: option(string)) => {
Expand All @@ -20,3 +22,23 @@ let repeat = (times: int, f) => {
count := count^ + 1;
};
};

let uiAttach = (api: NeovimApi.t) => {
api.requestSync(
"nvim_ui_attach",
Msgpck.List([
Msgpck.Int(20),
Msgpck.Int(20),
Msgpck.Map([
(Msgpck.String("rgb"), Msgpck.Bool(true)),
(Msgpck.String("ext_popupmenu"), Msgpck.Bool(true)),
(Msgpck.String("ext_tabline"), Msgpck.Bool(true)),
(Msgpck.String("ext_cmdline"), Msgpck.Bool(true)),
(Msgpck.String("ext_wildmenu"), Msgpck.Bool(true)),
(Msgpck.String("ext_linegrid"), Msgpck.Bool(true)),
/* (Msgpck.String("ext_multigrid"), Msgpck.Bool(true)), */
/* (Msgpck.String("ext_hlstate"), Msgpck.Bool(true)), */
]),
]),
);
};
50 changes: 32 additions & 18 deletions test/editor/Neovim/NeovimApiTests.re
Expand Up @@ -76,24 +76,7 @@ describe("NeovimApi", ({describe, test, _}) => {
notifications := List.append([n], notifications^)
);

let _result =
api.requestSync(
"nvim_ui_attach",
Msgpck.List([
Msgpck.Int(20),
Msgpck.Int(20),
Msgpck.Map([
(Msgpck.String("rgb"), Msgpck.Bool(true)),
(Msgpck.String("ext_popupmenu"), Msgpck.Bool(true)),
(Msgpck.String("ext_tabline"), Msgpck.Bool(true)),
(Msgpck.String("ext_cmdline"), Msgpck.Bool(true)),
(Msgpck.String("ext_wildmenu"), Msgpck.Bool(true)),
(Msgpck.String("ext_linegrid"), Msgpck.Bool(true)),
/* (Msgpck.String("ext_multigrid"), Msgpck.Bool(true)), */
/* (Msgpck.String("ext_hlstate"), Msgpck.Bool(true)), */
]),
]),
);
let _result = Helpers.uiAttach(api);

let f = () => {
api.pump();
Expand All @@ -113,4 +96,35 @@ describe("NeovimApi", ({describe, test, _}) => {
)
)
);

describe("basic buffer edit", ({test, _}) =>
test("modify lines in buffer", ({expect}) =>
Helpers.repeat(10, () =>
withNeovimApi(api => {
let notifications: ref(list(NeovimApi.notification)) = ref([]);

let _ =
Event.subscribe(api.onNotification, n =>
notifications := List.append([n], notifications^)
);

let _result = Helpers.uiAttach(api);

let _response =
api.requestSync(
"nvim_input",
Msgpck.List([Msgpck.String("iabcd<CR>efghi")]),
);

let lines =
api.requestSync("nvim_get_current_line", Msgpck.List([]));

switch (lines) {
| Msgpck.String(s) => expect.string(s).toEqual("efghi")
| _ => expect.string("fail").toEqual("to get proper input")
};
})
)
)
);
});

0 comments on commit 847a7d1

Please sign in to comment.