|
| 1 | +import { test } from "../vendor/https/deno.land/x/denops_core/test/mod.ts"; |
| 2 | +import { assertEquals } from "../vendor/https/deno.land/std/testing/asserts.ts"; |
| 3 | +import * as fn from "../function/mod.ts"; |
| 4 | +import { batch } from "./batch.ts"; |
| 5 | + |
| 6 | +test({ |
| 7 | + mode: "any", |
| 8 | + name: "batch() sequentially execute 'helper.call()' as batch process.", |
| 9 | + fn: async (denops) => { |
| 10 | + const results = await batch(denops, (helper) => { |
| 11 | + helper.call("range", 0); |
| 12 | + helper.call("range", 1); |
| 13 | + helper.call("range", 2); |
| 14 | + }); |
| 15 | + assertEquals(results, [[], [0], [0, 1]]); |
| 16 | + }, |
| 17 | +}); |
| 18 | +test({ |
| 19 | + mode: "any", |
| 20 | + name: "batch() sequentially execute 'helper.cmd()' as batch process.", |
| 21 | + fn: async (denops) => { |
| 22 | + await denops.cmd("let g:denops_batch_test = 0"); |
| 23 | + await denops.cmd("command! DenopsBatchTest let g:denops_batch_test += 1"); |
| 24 | + const results = await batch(denops, (helper) => { |
| 25 | + helper.cmd("DenopsBatchTest"); |
| 26 | + helper.cmd("DenopsBatchTest"); |
| 27 | + helper.cmd("DenopsBatchTest"); |
| 28 | + }); |
| 29 | + assertEquals(results, [0, 0, 0]); |
| 30 | + assertEquals(await denops.eval("g:denops_batch_test") as number, 3); |
| 31 | + }, |
| 32 | +}); |
| 33 | +test({ |
| 34 | + mode: "any", |
| 35 | + name: "batch() sequentially execute 'helper.eval()' as batch process.", |
| 36 | + fn: async (denops) => { |
| 37 | + await denops.cmd("let g:denops_batch_test = 10"); |
| 38 | + const results = await batch(denops, (helper) => { |
| 39 | + helper.eval("g:denops_batch_test + 1"); |
| 40 | + helper.eval("g:denops_batch_test - 1"); |
| 41 | + helper.eval("g:denops_batch_test * 10"); |
| 42 | + }); |
| 43 | + assertEquals(results, [11, 9, 100]); |
| 44 | + }, |
| 45 | +}); |
| 46 | +test({ |
| 47 | + mode: "any", |
| 48 | + name: "batch() sequentially execute 'fn.XXX(helper, ...)' as batch process.", |
| 49 | + fn: async (denops) => { |
| 50 | + const results = await batch(denops, (helper) => { |
| 51 | + fn.range(helper, 0); |
| 52 | + fn.range(helper, 1); |
| 53 | + fn.range(helper, 2); |
| 54 | + }); |
| 55 | + assertEquals(results, [[], [0], [0, 1]]); |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +test({ |
| 60 | + mode: "any", |
| 61 | + name: |
| 62 | + "batch() sequentially execute 'helper.call()' as batch process (async).", |
| 63 | + fn: async (denops) => { |
| 64 | + const results = await batch(denops, async (helper) => { |
| 65 | + assertEquals(await helper.call("range", 0), undefined); |
| 66 | + assertEquals(await helper.call("range", 1), undefined); |
| 67 | + assertEquals(await helper.call("range", 2), undefined); |
| 68 | + }); |
| 69 | + assertEquals(results, [[], [0], [0, 1]]); |
| 70 | + }, |
| 71 | +}); |
| 72 | +test({ |
| 73 | + mode: "any", |
| 74 | + name: "batch() sequentially execute 'helper.cmd()' as batch process (async).", |
| 75 | + fn: async (denops) => { |
| 76 | + await denops.cmd("let g:denops_batch_test = 0"); |
| 77 | + await denops.cmd("command! DenopsBatchTest let g:denops_batch_test += 1"); |
| 78 | + const results = await batch(denops, async (helper) => { |
| 79 | + assertEquals(await helper.cmd("DenopsBatchTest"), undefined); |
| 80 | + assertEquals(await helper.cmd("DenopsBatchTest"), undefined); |
| 81 | + assertEquals(await helper.cmd("DenopsBatchTest"), undefined); |
| 82 | + }); |
| 83 | + assertEquals(results, [0, 0, 0]); |
| 84 | + assertEquals(await denops.eval("g:denops_batch_test") as number, 3); |
| 85 | + }, |
| 86 | +}); |
| 87 | +test({ |
| 88 | + mode: "any", |
| 89 | + name: |
| 90 | + "batch() sequentially execute 'helper.eval()' as batch process (async).", |
| 91 | + fn: async (denops) => { |
| 92 | + await denops.cmd("let g:denops_batch_test = 10"); |
| 93 | + const results = await batch(denops, async (helper) => { |
| 94 | + assertEquals(await helper.eval("g:denops_batch_test + 1"), undefined); |
| 95 | + assertEquals(await helper.eval("g:denops_batch_test - 1"), undefined); |
| 96 | + assertEquals(await helper.eval("g:denops_batch_test * 10"), undefined); |
| 97 | + }); |
| 98 | + assertEquals(results, [11, 9, 100]); |
| 99 | + }, |
| 100 | +}); |
| 101 | +test({ |
| 102 | + mode: "any", |
| 103 | + name: |
| 104 | + "batch() sequentially execute 'fn.XXX(helper, ...)' as batch process (async).", |
| 105 | + fn: async (denops) => { |
| 106 | + const results = await batch(denops, async (helper) => { |
| 107 | + assertEquals(await fn.range(helper, 0), undefined); |
| 108 | + assertEquals(await fn.range(helper, 1), undefined); |
| 109 | + assertEquals(await fn.range(helper, 2), undefined); |
| 110 | + }); |
| 111 | + assertEquals(results, [[], [0], [0, 1]]); |
| 112 | + }, |
| 113 | +}); |
0 commit comments