Skip to content

Commit

Permalink
Merge pull request #215 from vim-denops/new-unknownutil
Browse files Browse the repository at this point in the history
📦 Upgrade dependencies and follow up `unknownutil` v3
  • Loading branch information
lambdalisue committed Jun 21, 2023
2 parents db7ac3f + ef32620 commit 4a598a6
Show file tree
Hide file tree
Showing 42 changed files with 109 additions and 121 deletions.
2 changes: 1 addition & 1 deletion denops_std/argument/flags_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { parseFlags } from "./flags.ts";

Deno.test("parseFlags", () => {
Expand Down
2 changes: 1 addition & 1 deletion denops_std/argument/mod_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { parse } from "./mod.ts";

Deno.test("parse", () => {
Expand Down
2 changes: 1 addition & 1 deletion denops_std/argument/opts_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { parseOpts } from "./opts.ts";

Deno.test("parseOpts", () => {
Expand Down
4 changes: 2 additions & 2 deletions denops_std/autocmd/common_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import { globals } from "../variable/mod.ts";
import { define, emit, emitAll, list, remove } from "./common.ts";

Expand Down
4 changes: 2 additions & 2 deletions denops_std/autocmd/group_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import { globals } from "../variable/mod.ts";
import { group } from "./group.ts";

Expand Down
6 changes: 3 additions & 3 deletions denops_std/batch/batch_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import {
assertSpyCall,
assertSpyCalls,
spy,
} from "https://deno.land/std@0.188.0/testing/mock.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
} from "https://deno.land/std@0.192.0/testing/mock.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import { batch, BatchHelper } from "./batch.ts";

test({
Expand Down
4 changes: 2 additions & 2 deletions denops_std/batch/collect_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
assertEquals,
assertRejects,
} from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
} from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import type { Denops } from "https://deno.land/x/denops_core@v5.0.0/mod.ts";
import { collect } from "./collect.ts";

Expand Down
4 changes: 2 additions & 2 deletions denops_std/buffer/buffer_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
assertEquals,
assertRejects,
} from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
} from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import { default as Encoding } from "https://cdn.skypack.dev/encoding-japanese@2.0.0/";
import * as fn from "../function/mod.ts";
import {
Expand Down
4 changes: 2 additions & 2 deletions denops_std/buffer/decoration_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import * as fn from "../function/mod.ts";
import * as vimFn from "../function/vim/mod.ts";
import * as nvimFn from "../function/nvim/mod.ts";
Expand Down
2 changes: 1 addition & 1 deletion denops_std/buffer/fileencoding_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { default as Encoding } from "https://cdn.skypack.dev/encoding-japanese@2.0.0/";
import { tryDecode } from "./fileencoding.ts";

Expand Down
4 changes: 2 additions & 2 deletions denops_std/buffer/fileformat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as unknownutil from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
import { is } from "https://deno.land/x/unknownutil@v3.0.0/mod.ts#^";

export type FileFormat = "unix" | "dos" | "mac";

Expand All @@ -9,7 +9,7 @@ const fileFormatDelimiters = {
};

export function isFileFormat(v: unknown): v is FileFormat {
return unknownutil.isString(v) && v in fileFormatDelimiters;
return is.String(v) && v in fileFormatDelimiters;
}

export function assertFileFormat(v: unknown): asserts v is FileFormat {
Expand Down
2 changes: 1 addition & 1 deletion denops_std/buffer/fileformat_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { FileFormat, findFileFormat, splitText } from "./fileformat.ts";

Deno.test("splitText", async (t) => {
Expand Down
8 changes: 4 additions & 4 deletions denops_std/bufname/bufname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const exprPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
* percent-encoded characters. It's required to distinguish `params` and or `fragment`.
*
* ```typescript
* import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
* import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
* import { format } from "../bufname/mod.ts";
*
* assertEquals(
Expand Down Expand Up @@ -130,7 +130,7 @@ const exprPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
* constructing a buffer name from a real path. For example
*
* ```typescript
* import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
* import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
* import * as path from "https://deno.land/std/path/mod.ts";
* import { format } from "../bufname/mod.ts";
*
Expand Down Expand Up @@ -170,7 +170,7 @@ export function format(
* For example, if it contains unusable characters ("<>|?*).
*
* ```typescript
* import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
* import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
* import { parse } from "../bufname/mod.ts";
*
* assertEquals(
Expand Down Expand Up @@ -224,7 +224,7 @@ export function format(
* was constructed from a real path. For example
*
* ```typescript
* import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
* import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
* import * as path from "https://deno.land/std/path/mod.ts";
* import { parse } from "../bufname/mod.ts";
*
Expand Down
4 changes: 2 additions & 2 deletions denops_std/bufname/bufname_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
assertEquals,
assertThrows,
} from "https://deno.land/std@0.188.0/testing/asserts.ts";
import * as path from "https://deno.land/std@0.188.0/path/mod.ts";
} from "https://deno.land/std@0.192.0/testing/asserts.ts";
import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
import { format, parse } from "./bufname.ts";

Deno.test("format throws exception when 'scheme' contains unusable characters", () => {
Expand Down
2 changes: 1 addition & 1 deletion denops_std/bufname/utils_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { decode, encode } from "./utils.ts";

Deno.test("encode does nothing on alphabet characters", () => {
Expand Down
11 changes: 4 additions & 7 deletions denops_std/function/buffer_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import {
assertArray,
isObject,
} from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.0.0/mod.ts#^";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import { BufInfo } from "./types.ts";
import * as buffer from "./buffer.ts";

Expand All @@ -23,7 +20,7 @@ test({
await denops.cmd("bunload!");

const actual = await buffer.getbufinfo(denops);
assertArray(actual, (x): x is BufInfo => isObject(x));
assert(actual, is.ArrayOf((x): x is BufInfo => is.Record(x)));
assertEquals(actual.length, 4);
assertEquals(
actual.map(({ changed, hidden, listed, loaded }) => (
Expand Down
40 changes: 21 additions & 19 deletions denops_std/function/cursor_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { assertNumber } from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.0.0/mod.ts#^";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import * as cursor from "./cursor.ts";
import { assertPosition, assertScreenPos, isScreenPos } from "./types.ts";

Expand All @@ -15,7 +15,7 @@ test({
await denops.call("setline", 1, "abcdef");
await denops.cmd("norm gg4|mx6|mY2|");

assertNumber(await cursor.col(denops, "."));
assert(await cursor.col(denops, "."), is.Number);
assertEquals(await cursor.col(denops, "."), 2);
assertEquals(await cursor.col(denops, [1, 2]), 2);
assertEquals(await cursor.col(denops, [1, "$"]), 7);
Expand All @@ -28,7 +28,7 @@ test({
await denops.cmd("enew!");
await denops.call("setline", 1, "\tab");

assertNumber(await cursor.virtcol(denops, "."));
assert(await cursor.virtcol(denops, "."), is.Number);
assertEquals(await cursor.virtcol(denops, "."), 8);
assertEquals(await cursor.virtcol(denops, [1, 1]), 8);
assertEquals(await cursor.virtcol(denops, [1, "$"]), 11);
Expand All @@ -45,10 +45,10 @@ test({
const winid = await denops.call("bufwinid", "%") as number;
await denops.call("setline", 1, ["a", "b", "c"]);

assertNumber(await cursor.line(denops, "."));
assert(await cursor.line(denops, "."), is.Number);
assertEquals(await cursor.line(denops, "."), 1);
assertEquals(await cursor.line(denops, "$"), 3);
assertNumber(await cursor.line(denops, ".", winid));
assert(await cursor.line(denops, ".", winid), is.Number);
assertEquals(await cursor.line(denops, ".", winid), 1);
},
});
Expand All @@ -57,26 +57,26 @@ test({
name: "wincol()",
fn: async () => {
await denops.cmd("enew!");
assertNumber(await cursor.wincol(denops));
assert(await cursor.wincol(denops), is.Number);
},
});

await t.step({
name: "winline()",
fn: async () => {
await denops.cmd("enew!");
assertNumber(await cursor.winline(denops));
assert(await cursor.winline(denops), is.Number);
},
});

await t.step({
name: "cursor()",
fn: async () => {
await denops.cmd("enew!");
assertNumber(await cursor.cursor(denops, 1, 2));
assertNumber(await cursor.cursor(denops, 1, 2, 3));
assertNumber(await cursor.cursor(denops, [1, 2, 3]));
assertNumber(await cursor.cursor(denops, [1, 2, 3, 4]));
assert(await cursor.cursor(denops, 1, 2), is.Number);
assert(await cursor.cursor(denops, 1, 2, 3), is.Number);
assert(await cursor.cursor(denops, [1, 2, 3]), is.Number);
assert(await cursor.cursor(denops, [1, 2, 3, 4]), is.Number);
},
});

Expand Down Expand Up @@ -123,11 +123,13 @@ test({
name: "setpos",
fn: async () => {
await denops.cmd("enew!");
assertNumber(
assert(
await cursor.setpos(denops, "'b", await cursor.getpos(denops, "'a")),
is.Number,
);
assertNumber(
assert(
await cursor.setpos(denops, "'b", await cursor.getcurpos(denops)),
is.Number,
);
},
});
Expand All @@ -136,24 +138,24 @@ test({
name: "byte2line",
fn: async () => {
await denops.cmd("enew!");
assertNumber(await cursor.byte2line(denops, 1));
assert(await cursor.byte2line(denops, 1), is.Number);
},
});

await t.step({
name: "line2byte",
fn: async () => {
await denops.cmd("enew!");
assertNumber(await cursor.line2byte(denops, 1));
assert(await cursor.line2byte(denops, 1), is.Number);
},
});

await t.step({
name: "diff_filler()",
fn: async () => {
await denops.cmd("enew!");
assertNumber(await cursor.diff_filler(denops, 1));
assertNumber(await cursor.diff_filler(denops, "."));
assert(await cursor.diff_filler(denops, 1), is.Number);
assert(await cursor.diff_filler(denops, "."), is.Number);
},
});
},
Expand Down
2 changes: 1 addition & 1 deletion denops_std/function/getreginfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Denops } from "https://deno.land/x/denops_core@v5.0.0/mod.ts";
import { lt } from "https://deno.land/std@0.188.0/semver/mod.ts";
import { lt } from "https://deno.land/std@0.192.0/semver/mod.ts";
import { execute } from "../helper/mod.ts";
import { generateUniqueString } from "../util.ts";

Expand Down
4 changes: 2 additions & 2 deletions denops_std/function/input_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
assertEquals,
assertRejects,
} from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
} from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import { input, inputlist, inputsecret } from "./input.ts";
import * as autocmd from "../autocmd/mod.ts";
import { execute } from "../helper/execute.ts";
Expand Down
38 changes: 15 additions & 23 deletions denops_std/function/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
AssertError,
isLike,
} from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
import { assert, is } from "https://deno.land/x/unknownutil@v3.0.0/mod.ts#^";

/**
* Type of `screenpos()` result.
Expand All @@ -13,30 +10,24 @@ export type ScreenPos = {
curscol: number;
};

/**
* Reference ScreenPos struct for isLike.
*/
const refScreenPos: ScreenPos = {
row: 0,
col: 0,
endcol: 0,
curscol: 0,
};

/**
* Return true if the value is ScreenPos.
*/
export function isScreenPos(x: unknown): x is ScreenPos {
return isLike(refScreenPos, x);
const predObj = {
row: is.Number,
col: is.Number,
endcol: is.Number,
curscol: is.Number,
};
return is.ObjectOf(predObj)(x);
}

/**
* Assert if `x` is ScreenPos by raising an `AssertError` when it's not.
*/
export function assertScreenPos(x: unknown): asserts x is ScreenPos {
if (!isScreenPos(x)) {
throw new AssertError("The value must be ScreenPos");
}
assert(x, isScreenPos, { message: "The value must be ScreenPos" });
}

/**
Expand All @@ -54,17 +45,18 @@ export type Position = [
* Return true if the value is Position.
*/
export function isPosition(x: unknown): x is Position {
return Array.isArray(x) && (x.length === 4 || x.length === 5) &&
x.every((x) => typeof x === "number");
const pred = is.OneOf([
is.TupleOf([is.Number, is.Number, is.Number, is.Number]),
is.TupleOf([is.Number, is.Number, is.Number, is.Number, is.Number]),
]);
return pred(x);
}

/**
* Assert if `x` is Position by raising an `AssertError` when it's not.
*/
export function assertPosition(x: unknown): asserts x is Position {
if (!isPosition(x)) {
throw new AssertError("The value must be Position");
}
assert(x, isPosition, { message: "The value must be Position" });
}

const validBuiltinCompletions = [
Expand Down
4 changes: 2 additions & 2 deletions denops_std/function/various_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from "https://deno.land/std@0.188.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.3.1/mod.ts";
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
import * as various from "./various.ts";

test({
Expand Down

0 comments on commit 4a598a6

Please sign in to comment.