Skip to content

Commit 747a1ee

Browse files
authored
Merge pull request #133 from jsr-core/testing
test: use IsExact of @std/testing
2 parents 6cf6aeb + 37a93cc commit 747a1ee

25 files changed

+108
-178
lines changed

_testutil.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { assertEquals } from "@std/assert";
2-
import type { IsExact } from "@std/testing/types";
32
import type { Predicate } from "./type.ts";
43

54
const examples = {
@@ -50,16 +49,6 @@ export async function testWithExamples<T>(
5049
}
5150
}
5251

53-
// It seems 'IsExact' in deno_std is false positive so use `Equal` in type-challenges
54-
// https://github.com/type-challenges/type-challenges/blob/e77262dba62e9254451f661cb4fe5517ffd1d933/utils/index.d.ts#L7-L9
55-
/** @deprecated use {@linkcode Equal} */
56-
export type TypeChallengesEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends
57-
(<T>() => T extends Y ? 1 : 2) ? true : false;
58-
59-
// `Equal` in type-challenges is false positive so combine `IsExact` + `Equal`.
60-
export type Equal<X, Y> = TypeChallengesEqual<X, Y> extends true ? IsExact<X, Y>
61-
: false;
62-
6352
export function stringify(x: unknown): string {
6453
if (x instanceof Date) return `Date(${x.valueOf()})`;
6554
if (x instanceof Promise) return "Promise";

_testutil_test.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

as/optional_test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assertEquals } from "@std/assert";
2-
import { assertType } from "@std/testing/types";
3-
import { type Equal, testWithExamples } from "../_testutil.ts";
2+
import { assertType, type IsExact } from "@std/testing/types";
3+
import { testWithExamples } from "../_testutil.ts";
44
import { is } from "../is/mod.ts";
55
import type { AsOptional } from "../_annotation.ts";
66
import { asOptional, asUnoptional, hasOptional } from "./optional.ts";
@@ -35,7 +35,7 @@ Deno.test("asOptional<T>", async (t) => {
3535
const v: unknown = undefined;
3636
if (pred(v)) {
3737
assertType<
38-
Equal<
38+
IsExact<
3939
typeof v,
4040
{ a: number; b?: number | undefined; c?: number | undefined }
4141
>
@@ -56,7 +56,7 @@ Deno.test("asOptional<T>", async (t) => {
5656
const v: unknown = undefined;
5757
if (pred(v)) {
5858
assertType<
59-
Equal<typeof v, [number, number | undefined, number | undefined]>
59+
IsExact<typeof v, [number, number | undefined, number | undefined]>
6060
>(
6161
true,
6262
);
@@ -76,7 +76,7 @@ Deno.test("asOptional<T>", async (t) => {
7676
const v: unknown = undefined;
7777
if (pred(v)) {
7878
assertType<
79-
Equal<
79+
IsExact<
8080
typeof v,
8181
[number, (number | undefined)?, (number | undefined)?]
8282
>
@@ -117,7 +117,7 @@ Deno.test("asUnoptional<T>", async (t) => {
117117
await t.step("predicated type is correct", () => {
118118
const v: unknown = undefined;
119119
if (pred(v)) {
120-
assertType<Equal<typeof v, { a: number; b: number; c: number }>>(
120+
assertType<IsExact<typeof v, { a: number; b: number; c: number }>>(
121121
true,
122122
);
123123
}
@@ -134,7 +134,7 @@ Deno.test("asUnoptional<T>", async (t) => {
134134
const v: unknown = undefined;
135135
if (pred(v)) {
136136
assertType<
137-
Equal<typeof v, [number, number, number]>
137+
IsExact<typeof v, [number, number, number]>
138138
>(
139139
true,
140140
);
@@ -154,7 +154,7 @@ Deno.test("asUnoptional<T>", async (t) => {
154154
const v: unknown = undefined;
155155
if (pred(v)) {
156156
assertType<
157-
Equal<typeof v, [number, number, number]>
157+
IsExact<typeof v, [number, number, number]>
158158
>(
159159
true,
160160
);
@@ -178,7 +178,7 @@ Deno.test("hasOptional<P>", async (t) => {
178178
const pred = asOptional(is.Number);
179179
type P = typeof pred;
180180
if (hasOptional(pred)) {
181-
assertType<Equal<typeof pred, P & AsOptional<number>>>(true);
181+
assertType<IsExact<typeof pred, P & AsOptional<number>>>(true);
182182
}
183183
});
184184
});

as/readonly_test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assertEquals } from "@std/assert";
2-
import { assertType } from "@std/testing/types";
3-
import { type Equal, testWithExamples } from "../_testutil.ts";
2+
import { assertType, type IsExact } from "@std/testing/types";
3+
import { testWithExamples } from "../_testutil.ts";
44
import { is } from "../is/mod.ts";
55
import type { AsReadonly } from "../_annotation.ts";
66
import { asReadonly, asUnreadonly, hasReadonly } from "./readonly.ts";
@@ -35,7 +35,10 @@ Deno.test("asReadonly<T>", async (t) => {
3535
const v: unknown = undefined;
3636
if (pred(v)) {
3737
assertType<
38-
Equal<typeof v, { a: number; readonly b: number; readonly c: number }>
38+
IsExact<
39+
typeof v,
40+
{ a: number; readonly b: number; readonly c: number }
41+
>
3942
>(
4043
true,
4144
);
@@ -53,7 +56,7 @@ Deno.test("asReadonly<T>", async (t) => {
5356
const v: unknown = undefined;
5457
if (pred(v)) {
5558
assertType<
56-
Equal<typeof v, [number, number, number]>
59+
IsExact<typeof v, [number, number, number]>
5760
>(
5861
true,
5962
);
@@ -73,7 +76,7 @@ Deno.test("asReadonly<T>", async (t) => {
7376
const v: unknown = undefined;
7477
if (pred(v)) {
7578
assertType<
76-
Equal<typeof v, [number, number, number]>
79+
IsExact<typeof v, [number, number, number]>
7780
>(
7881
true,
7982
);
@@ -111,7 +114,7 @@ Deno.test("asUnreadonly<T>", async (t) => {
111114
await t.step("predicated type is correct", () => {
112115
const v: unknown = undefined;
113116
if (pred(v)) {
114-
assertType<Equal<typeof v, { a: number; b: number; c: number }>>(
117+
assertType<IsExact<typeof v, { a: number; b: number; c: number }>>(
115118
true,
116119
);
117120
}
@@ -128,7 +131,7 @@ Deno.test("asUnreadonly<T>", async (t) => {
128131
const v: unknown = undefined;
129132
if (pred(v)) {
130133
assertType<
131-
Equal<typeof v, [number, number, number]>
134+
IsExact<typeof v, [number, number, number]>
132135
>(
133136
true,
134137
);
@@ -148,7 +151,7 @@ Deno.test("asUnreadonly<T>", async (t) => {
148151
const v: unknown = undefined;
149152
if (pred(v)) {
150153
assertType<
151-
Equal<typeof v, [number, number, number]>
154+
IsExact<typeof v, [number, number, number]>
152155
>(
153156
true,
154157
);
@@ -172,7 +175,7 @@ Deno.test("hasReadonly<P>", async (t) => {
172175
const pred = asReadonly(is.Number);
173176
type P = typeof pred;
174177
if (hasReadonly(pred)) {
175-
assertType<Equal<typeof pred, P & AsReadonly>>(true);
178+
assertType<IsExact<typeof pred, P & AsReadonly>>(true);
176179
}
177180
});
178181
});

deno.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@
7575
"@core/iterutil": "jsr:@core/iterutil@^0.3.0",
7676
"@core/unknownutil": "./mod.ts",
7777
"@deno/dnt": "jsr:@deno/dnt@^0.41.1",
78-
"@std/assert": "jsr:@std/assert@^0.221.0",
78+
"@std/assert": "jsr:@std/assert@^1.0.4",
7979
"@std/jsonc": "jsr:@std/jsonc@^1.0.0",
8080
"@std/path": "jsr:@std/path@^1.0.2",
81-
"@std/testing": "jsr:@std/testing@^0.221.0"
81+
"@std/testing": "jsr:@std/testing@^1.0.2"
8282
},
8383
"tasks": {
8484
"check": "deno check **/*.ts",

is/array_of_test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { assertEquals } from "@std/assert";
2-
import { assertType } from "@std/testing/types";
3-
import type { Equal } from "../_testutil.ts";
2+
import { assertType, type IsExact } from "@std/testing/types";
43
import { is } from "./mod.ts";
54
import { isArrayOf } from "./array_of.ts";
65

@@ -30,7 +29,7 @@ Deno.test("isArrayOf<T>", async (t) => {
3029
const a: unknown = undefined;
3130

3231
if (isArrayOf(is.Number)(a)) {
33-
assertType<Equal<typeof a, number[]>>(true);
32+
assertType<IsExact<typeof a, number[]>>(true);
3433
}
3534
});
3635
});

is/instance_of_test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { assertEquals } from "@std/assert";
2-
import { assertType } from "@std/testing/types";
3-
import type { Equal } from "../_testutil.ts";
2+
import { assertType, type IsExact } from "@std/testing/types";
43
import { isInstanceOf } from "./instance_of.ts";
54

65
Deno.test("isInstanceOf<T>", async (t) => {
@@ -29,15 +28,15 @@ Deno.test("isInstanceOf<T>", async (t) => {
2928
const a: unknown = undefined;
3029

3130
if (isInstanceOf(Cls)(a)) {
32-
assertType<Equal<typeof a, Cls>>(true);
31+
assertType<IsExact<typeof a, Cls>>(true);
3332
}
3433

3534
if (isInstanceOf(Date)(a)) {
36-
assertType<Equal<typeof a, Date>>(true);
35+
assertType<IsExact<typeof a, Date>>(true);
3736
}
3837

3938
if (isInstanceOf(Promise)(a)) {
40-
assertType<Equal<typeof a, Promise<unknown>>>(true);
39+
assertType<IsExact<typeof a, Promise<unknown>>>(true);
4140
}
4241
});
4342
});

is/intersection_of_test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { assertEquals } from "@std/assert";
22
import { assertSnapshot } from "@std/testing/snapshot";
3-
import { assertType } from "@std/testing/types";
4-
import type { Equal } from "../_testutil.ts";
3+
import { assertType, type IsExact } from "@std/testing/types";
54
import { is } from "./mod.ts";
65
import { isIntersectionOf } from "./intersection_of.ts";
76

@@ -40,16 +39,16 @@ Deno.test("isIntersectionOf<T>", async (t) => {
4039
const a: unknown = undefined;
4140

4241
if (isIntersectionOf([is.String])(a)) {
43-
assertType<Equal<typeof a, string>>(true);
42+
assertType<IsExact<typeof a, string>>(true);
4443
}
4544

4645
if (isIntersectionOf(objPreds)(a)) {
47-
assertType<Equal<typeof a, { a: number } & { b: string }>>(true);
46+
assertType<IsExact<typeof a, { a: number } & { b: string }>>(true);
4847
}
4948

5049
if (isIntersectionOf(mixPreds)(a)) {
5150
assertType<
52-
Equal<
51+
IsExact<
5352
typeof a,
5453
& ((...args: unknown[]) => unknown)
5554
& { b: string }
@@ -70,7 +69,7 @@ Deno.test("isIntersectionOf<T>", async (t) => {
7069

7170
if (pred(a)) {
7271
assertType<
73-
Equal<
72+
IsExact<
7473
typeof a,
7574
{ id: string } & ({ result: string } | { error: string })
7675
>
@@ -114,16 +113,16 @@ Deno.test("isIntersectionOf<T>", async (t) => {
114113
const a: unknown = undefined;
115114

116115
if (isIntersectionOf([is.String])(a)) {
117-
assertType<Equal<typeof a, string>>(true);
116+
assertType<IsExact<typeof a, string>>(true);
118117
}
119118

120119
if (isIntersectionOf(objPreds)(a)) {
121-
assertType<Equal<typeof a, { a: number } & { [b]: string }>>(true);
120+
assertType<IsExact<typeof a, { a: number } & { [b]: string }>>(true);
122121
}
123122

124123
if (isIntersectionOf(mixPreds)(a)) {
125124
assertType<
126-
Equal<
125+
IsExact<
127126
typeof a,
128127
& ((...args: unknown[]) => unknown)
129128
& { [b]: string }
@@ -144,7 +143,7 @@ Deno.test("isIntersectionOf<T>", async (t) => {
144143

145144
if (pred(a)) {
146145
assertType<
147-
Equal<
146+
IsExact<
148147
typeof a,
149148
{ id: string } & ({ result: string } | { error: string })
150149
>

is/literal_of_test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { assertEquals } from "@std/assert";
2-
import { assertType } from "@std/testing/types";
3-
import type { Equal } from "../_testutil.ts";
2+
import { assertType, type IsExact } from "@std/testing/types";
43
import { isLiteralOf } from "./literal_of.ts";
54

65
Deno.test("isLiteralOf<T>", async (t) => {
@@ -45,35 +44,35 @@ Deno.test("isLiteralOf<T>", async (t) => {
4544
const a: unknown = undefined;
4645

4746
if (isLiteralOf("hello")(a)) {
48-
assertType<Equal<typeof a, "hello">>(true);
47+
assertType<IsExact<typeof a, "hello">>(true);
4948
}
5049

5150
if (isLiteralOf(100)(a)) {
52-
assertType<Equal<typeof a, 100>>(true);
51+
assertType<IsExact<typeof a, 100>>(true);
5352
}
5453

5554
if (isLiteralOf(100n)(a)) {
56-
assertType<Equal<typeof a, 100n>>(true);
55+
assertType<IsExact<typeof a, 100n>>(true);
5756
}
5857

5958
if (isLiteralOf(true)(a)) {
60-
assertType<Equal<typeof a, true>>(true);
59+
assertType<IsExact<typeof a, true>>(true);
6160
}
6261

6362
if (isLiteralOf(false)(a)) {
64-
assertType<Equal<typeof a, false>>(true);
63+
assertType<IsExact<typeof a, false>>(true);
6564
}
6665

6766
if (isLiteralOf(null)(a)) {
68-
assertType<Equal<typeof a, null>>(true);
67+
assertType<IsExact<typeof a, null>>(true);
6968
}
7069

7170
if (isLiteralOf(undefined)(a)) {
72-
assertType<Equal<typeof a, undefined>>(true);
71+
assertType<IsExact<typeof a, undefined>>(true);
7372
}
7473

7574
if (isLiteralOf(s)(a)) {
76-
assertType<Equal<typeof a, typeof s>>(true);
75+
assertType<IsExact<typeof a, typeof s>>(true);
7776
}
7877
});
7978
});

0 commit comments

Comments
 (0)