|
| 1 | +import { assertEquals, assertThrowsAsync, test } from "../deps_test.ts"; |
| 2 | +import { gather } from "./gather.ts"; |
| 3 | + |
| 4 | +test({ |
| 5 | + mode: "any", |
| 6 | + name: "gather() sequentially execute 'denops.call()'.", |
| 7 | + fn: async (denops) => { |
| 8 | + const results = await gather(denops, async (denops) => { |
| 9 | + await denops.call("range", 0); |
| 10 | + await denops.call("range", 1); |
| 11 | + await denops.call("range", 2); |
| 12 | + }); |
| 13 | + assertEquals(results, [[], [0], [0, 1]]); |
| 14 | + }, |
| 15 | +}); |
| 16 | +test({ |
| 17 | + mode: "any", |
| 18 | + name: "gather() throws an error when 'denops.cmd()' is called.", |
| 19 | + fn: async (denops) => { |
| 20 | + await denops.cmd("let g:denops_gather_test = 0"); |
| 21 | + await denops.cmd("command! DenopsGatherTest let g:denops_gather_test += 1"); |
| 22 | + const results = await gather(denops, async (denops) => { |
| 23 | + await denops.cmd("DenopsGatherTest"); |
| 24 | + await denops.cmd("DenopsGatherTest"); |
| 25 | + await denops.cmd("DenopsGatherTest"); |
| 26 | + }); |
| 27 | + assertEquals(results, [0, 0, 0]); |
| 28 | + assertEquals(await denops.eval("g:denops_gather_test") as number, 3); |
| 29 | + }, |
| 30 | +}); |
| 31 | +test({ |
| 32 | + mode: "any", |
| 33 | + name: "gather() sequentially execute 'denops.eval()'.", |
| 34 | + fn: async (denops) => { |
| 35 | + await denops.cmd("let g:denops_gather_test = 10"); |
| 36 | + const results = await gather(denops, async (denops) => { |
| 37 | + await denops.eval("g:denops_gather_test + 1"); |
| 38 | + await denops.eval("g:denops_gather_test - 1"); |
| 39 | + await denops.eval("g:denops_gather_test * 10"); |
| 40 | + }); |
| 41 | + assertEquals(results, [11, 9, 100]); |
| 42 | + }, |
| 43 | +}); |
| 44 | +test({ |
| 45 | + mode: "any", |
| 46 | + name: "gather() throws an error when 'denops.batch()' is called.", |
| 47 | + fn: async (denops) => { |
| 48 | + await assertThrowsAsync( |
| 49 | + async () => { |
| 50 | + await gather(denops, async (denops) => { |
| 51 | + await denops.batch(); |
| 52 | + }); |
| 53 | + }, |
| 54 | + undefined, |
| 55 | + "method is not available", |
| 56 | + ); |
| 57 | + }, |
| 58 | +}); |
0 commit comments