track-cli 4.0.3-rc1 → 4.1.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/_dnt.shims.d.ts +1 -1
- package/esm/_dnt.test_shims.d.ts +20 -0
- package/esm/_dnt.test_shims.js +77 -0
- package/esm/deps/deno.land/std@0.195.0/_util/diff.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/_util/diff.js +311 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_constants.d.ts +1 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_constants.js +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_format.d.ts +1 -0
- package/esm/deps/deno.land/std@0.195.0/assert/_format.js +23 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_almost_equals.d.ts +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_almost_equals.js +32 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_array_includes.d.ts +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_array_includes.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_equals.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_equals.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_exists.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_exists.js +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_false.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_false.js +7 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_instance_of.d.ts +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_instance_of.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_is_error.d.ts +7 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_is_error.js +26 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_match.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_match.js +13 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_equals.d.ts +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_equals.js +37 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_instance_of.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_instance_of.js +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_match.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_match.js +14 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_strict_equals.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_not_strict_equals.js +20 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_object_match.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_object_match.js +78 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_rejects.d.ts +64 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_rejects.js +50 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_strict_equals.d.ts +23 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_strict_equals.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_string_includes.d.ts +5 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_string_includes.js +13 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_throws.d.ts +54 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert_throws.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/assert/equal.d.ts +6 -0
- package/esm/deps/deno.land/std@0.195.0/assert/equal.js +102 -0
- package/esm/deps/deno.land/std@0.195.0/assert/fail.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/fail.js +9 -0
- package/esm/deps/deno.land/std@0.195.0/assert/mod.d.ts +32 -0
- package/esm/deps/deno.land/std@0.195.0/assert/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unimplemented.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unimplemented.js +7 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unreachable.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/unreachable.js +6 -0
- package/esm/deps/deno.land/std@0.195.0/testing/_test_suite.d.ts +70 -0
- package/esm/deps/deno.land/std@0.195.0/testing/_test_suite.js +321 -0
- package/esm/deps/deno.land/std@0.195.0/testing/asserts.d.ts +329 -0
- package/esm/deps/deno.land/std@0.195.0/testing/asserts.js +330 -0
- package/esm/deps/deno.land/std@0.195.0/testing/bdd.d.ts +440 -0
- package/esm/deps/deno.land/std@0.195.0/testing/bdd.js +215 -0
- package/esm/deps/deno.land/std@0.195.0/testing/mock.d.ts +110 -0
- package/esm/deps/deno.land/std@0.195.0/testing/mock.js +746 -0
- package/esm/src/action/clone.js +4 -3
- package/esm/src/action/frontend-template-switch.d.ts +1 -0
- package/esm/src/action/frontend-template-switch.js +56 -0
- package/esm/src/action/frontend-template.d.ts +2 -0
- package/esm/src/action/frontend-template.js +12 -0
- package/esm/src/main.js +9 -2
- package/esm/src/meta.d.ts +1 -1
- package/esm/src/meta.js +108 -25
- package/esm/src/orca/client.js +1 -1
- package/esm/src/shared/config.d.ts +1 -0
- package/esm/src/shared/file.d.ts +1 -0
- package/esm/src/shared/file.js +32 -0
- package/esm/src/shared/mod.d.ts +1 -1
- package/esm/src/shared/mod.js +10 -2
- package/esm/src/shared/types.d.ts +15 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +4 -1
- package/esm/src/track/test.d.ts +5 -2
- package/esm/src/track/test.js +18 -2
- package/esm/src/track/training.d.ts +4 -1
- package/esm/src/track/training.js +9 -0
- package/esm/test/shared/config_test.d.ts +1 -0
- package/esm/test/shared/config_test.js +57 -0
- package/esm/test/shared/file_test.d.ts +1 -0
- package/esm/test/shared/file_test.js +265 -0
- package/esm/test/shared/mod_test.d.ts +1 -0
- package/esm/test/shared/mod_test.js +353 -0
- package/package.json +2 -1
- package/test_runner.js +186 -0
package/esm/_dnt.shims.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { fetch, File, FormData, Headers, Request, Response } from "undici";
|
|
|
5
5
|
export { fetch, File, FormData, Headers, Request, Response, type BodyInit, type HeadersInit, type RequestInit, type ResponseInit } from "undici";
|
|
6
6
|
import { alert, confirm, prompt } from "./shim/prompts.js";
|
|
7
7
|
export { alert, confirm, prompt } from "./shim/prompts.js";
|
|
8
|
-
export declare const dntGlobalThis: Omit<typeof globalThis, "fetch" | "
|
|
8
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "fetch" | "FormData" | "Headers" | "Request" | "Response" | "File" | "crypto" | "Deno" | "alert" | "confirm" | "prompt"> & {
|
|
9
9
|
Deno: typeof Deno;
|
|
10
10
|
crypto: import("@deno/shim-crypto").Crypto;
|
|
11
11
|
fetch: typeof fetch;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
4
|
+
import { fetch, File, FormData, Headers, Request, Response } from "undici";
|
|
5
|
+
export { fetch, File, FormData, Headers, Request, Response, type BodyInit, type HeadersInit, type RequestInit, type ResponseInit } from "undici";
|
|
6
|
+
import { alert, confirm, prompt } from "./shim/prompts.js";
|
|
7
|
+
export { alert, confirm, prompt } from "./shim/prompts.js";
|
|
8
|
+
export declare const dntGlobalThis: Omit<typeof globalThis, "fetch" | "FormData" | "Headers" | "Request" | "Response" | "File" | "crypto" | "Deno" | "alert" | "confirm" | "prompt"> & {
|
|
9
|
+
Deno: typeof Deno;
|
|
10
|
+
crypto: import("@deno/shim-crypto").Crypto;
|
|
11
|
+
fetch: typeof fetch;
|
|
12
|
+
File: typeof File;
|
|
13
|
+
FormData: typeof FormData;
|
|
14
|
+
Headers: typeof Headers;
|
|
15
|
+
Request: typeof Request;
|
|
16
|
+
Response: typeof Response;
|
|
17
|
+
alert: typeof alert;
|
|
18
|
+
confirm: typeof confirm;
|
|
19
|
+
prompt: typeof prompt;
|
|
20
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Deno } from "@deno/shim-deno";
|
|
2
|
+
export { Deno } from "@deno/shim-deno";
|
|
3
|
+
import { crypto } from "@deno/shim-crypto";
|
|
4
|
+
export { crypto } from "@deno/shim-crypto";
|
|
5
|
+
import { fetch, File, FormData, Headers, Request, Response } from "undici";
|
|
6
|
+
export { fetch, File, FormData, Headers, Request, Response } from "undici";
|
|
7
|
+
import { alert, confirm, prompt } from "./shim/prompts.js";
|
|
8
|
+
export { alert, confirm, prompt } from "./shim/prompts.js";
|
|
9
|
+
const dntGlobals = {
|
|
10
|
+
Deno,
|
|
11
|
+
crypto,
|
|
12
|
+
fetch,
|
|
13
|
+
File,
|
|
14
|
+
FormData,
|
|
15
|
+
Headers,
|
|
16
|
+
Request,
|
|
17
|
+
Response,
|
|
18
|
+
alert,
|
|
19
|
+
confirm,
|
|
20
|
+
prompt,
|
|
21
|
+
};
|
|
22
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
23
|
+
function createMergeProxy(baseObj, extObj) {
|
|
24
|
+
return new Proxy(baseObj, {
|
|
25
|
+
get(_target, prop, _receiver) {
|
|
26
|
+
if (prop in extObj) {
|
|
27
|
+
return extObj[prop];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return baseObj[prop];
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
set(_target, prop, value) {
|
|
34
|
+
if (prop in extObj) {
|
|
35
|
+
delete extObj[prop];
|
|
36
|
+
}
|
|
37
|
+
baseObj[prop] = value;
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
deleteProperty(_target, prop) {
|
|
41
|
+
let success = false;
|
|
42
|
+
if (prop in extObj) {
|
|
43
|
+
delete extObj[prop];
|
|
44
|
+
success = true;
|
|
45
|
+
}
|
|
46
|
+
if (prop in baseObj) {
|
|
47
|
+
delete baseObj[prop];
|
|
48
|
+
success = true;
|
|
49
|
+
}
|
|
50
|
+
return success;
|
|
51
|
+
},
|
|
52
|
+
ownKeys(_target) {
|
|
53
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
54
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
55
|
+
const extKeysSet = new Set(extKeys);
|
|
56
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
57
|
+
},
|
|
58
|
+
defineProperty(_target, prop, desc) {
|
|
59
|
+
if (prop in extObj) {
|
|
60
|
+
delete extObj[prop];
|
|
61
|
+
}
|
|
62
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
65
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
66
|
+
if (prop in extObj) {
|
|
67
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
has(_target, prop) {
|
|
74
|
+
return prop in extObj || prop in baseObj;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum DiffType {
|
|
2
|
+
removed = "removed",
|
|
3
|
+
common = "common",
|
|
4
|
+
added = "added"
|
|
5
|
+
}
|
|
6
|
+
export interface DiffResult<T> {
|
|
7
|
+
type: DiffType;
|
|
8
|
+
value: T;
|
|
9
|
+
details?: Array<DiffResult<T>>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders the differences between the actual and expected values
|
|
13
|
+
* @param A Actual value
|
|
14
|
+
* @param B Expected value
|
|
15
|
+
*/
|
|
16
|
+
export declare function diff<T>(A: T[], B: T[]): Array<DiffResult<T>>;
|
|
17
|
+
/**
|
|
18
|
+
* Renders the differences between the actual and expected strings
|
|
19
|
+
* Partially inspired from https://github.com/kpdecker/jsdiff
|
|
20
|
+
* @param A Actual string
|
|
21
|
+
* @param B Expected string
|
|
22
|
+
*/
|
|
23
|
+
export declare function diffstr(A: string, B: string): DiffResult<string>[];
|
|
24
|
+
export declare function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>, { stringDiff }?: {
|
|
25
|
+
stringDiff?: boolean | undefined;
|
|
26
|
+
}): string[];
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { bgGreen, bgRed, bold, gray, green, red, white, } from "../fmt/colors.js";
|
|
4
|
+
export var DiffType;
|
|
5
|
+
(function (DiffType) {
|
|
6
|
+
DiffType["removed"] = "removed";
|
|
7
|
+
DiffType["common"] = "common";
|
|
8
|
+
DiffType["added"] = "added";
|
|
9
|
+
})(DiffType || (DiffType = {}));
|
|
10
|
+
const REMOVED = 1;
|
|
11
|
+
const COMMON = 2;
|
|
12
|
+
const ADDED = 3;
|
|
13
|
+
function createCommon(A, B, reverse) {
|
|
14
|
+
const common = [];
|
|
15
|
+
if (A.length === 0 || B.length === 0)
|
|
16
|
+
return [];
|
|
17
|
+
for (let i = 0; i < Math.min(A.length, B.length); i += 1) {
|
|
18
|
+
if (A[reverse ? A.length - i - 1 : i] === B[reverse ? B.length - i - 1 : i]) {
|
|
19
|
+
common.push(A[reverse ? A.length - i - 1 : i]);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return common;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return common;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Renders the differences between the actual and expected values
|
|
29
|
+
* @param A Actual value
|
|
30
|
+
* @param B Expected value
|
|
31
|
+
*/
|
|
32
|
+
export function diff(A, B) {
|
|
33
|
+
const prefixCommon = createCommon(A, B);
|
|
34
|
+
const suffixCommon = createCommon(A.slice(prefixCommon.length), B.slice(prefixCommon.length), true).reverse();
|
|
35
|
+
A = suffixCommon.length
|
|
36
|
+
? A.slice(prefixCommon.length, -suffixCommon.length)
|
|
37
|
+
: A.slice(prefixCommon.length);
|
|
38
|
+
B = suffixCommon.length
|
|
39
|
+
? B.slice(prefixCommon.length, -suffixCommon.length)
|
|
40
|
+
: B.slice(prefixCommon.length);
|
|
41
|
+
const swapped = B.length > A.length;
|
|
42
|
+
[A, B] = swapped ? [B, A] : [A, B];
|
|
43
|
+
const M = A.length;
|
|
44
|
+
const N = B.length;
|
|
45
|
+
if (!M && !N && !suffixCommon.length && !prefixCommon.length)
|
|
46
|
+
return [];
|
|
47
|
+
if (!N) {
|
|
48
|
+
return [
|
|
49
|
+
...prefixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
|
50
|
+
...A.map((a) => ({
|
|
51
|
+
type: swapped ? DiffType.added : DiffType.removed,
|
|
52
|
+
value: a,
|
|
53
|
+
})),
|
|
54
|
+
...suffixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
const offset = N;
|
|
58
|
+
const delta = M - N;
|
|
59
|
+
const size = M + N + 1;
|
|
60
|
+
const fp = Array.from({ length: size }, () => ({ y: -1, id: -1 }));
|
|
61
|
+
/**
|
|
62
|
+
* INFO:
|
|
63
|
+
* This buffer is used to save memory and improve performance.
|
|
64
|
+
* The first half is used to save route and last half is used to save diff
|
|
65
|
+
* type.
|
|
66
|
+
* This is because, when I kept new uint8array area to save type,performance
|
|
67
|
+
* worsened.
|
|
68
|
+
*/
|
|
69
|
+
const routes = new Uint32Array((M * N + size + 1) * 2);
|
|
70
|
+
const diffTypesPtrOffset = routes.length / 2;
|
|
71
|
+
let ptr = 0;
|
|
72
|
+
let p = -1;
|
|
73
|
+
function backTrace(A, B, current, swapped) {
|
|
74
|
+
const M = A.length;
|
|
75
|
+
const N = B.length;
|
|
76
|
+
const result = [];
|
|
77
|
+
let a = M - 1;
|
|
78
|
+
let b = N - 1;
|
|
79
|
+
let j = routes[current.id];
|
|
80
|
+
let type = routes[current.id + diffTypesPtrOffset];
|
|
81
|
+
while (true) {
|
|
82
|
+
if (!j && !type)
|
|
83
|
+
break;
|
|
84
|
+
const prev = j;
|
|
85
|
+
if (type === REMOVED) {
|
|
86
|
+
result.unshift({
|
|
87
|
+
type: swapped ? DiffType.removed : DiffType.added,
|
|
88
|
+
value: B[b],
|
|
89
|
+
});
|
|
90
|
+
b -= 1;
|
|
91
|
+
}
|
|
92
|
+
else if (type === ADDED) {
|
|
93
|
+
result.unshift({
|
|
94
|
+
type: swapped ? DiffType.added : DiffType.removed,
|
|
95
|
+
value: A[a],
|
|
96
|
+
});
|
|
97
|
+
a -= 1;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
result.unshift({ type: DiffType.common, value: A[a] });
|
|
101
|
+
a -= 1;
|
|
102
|
+
b -= 1;
|
|
103
|
+
}
|
|
104
|
+
j = routes[prev];
|
|
105
|
+
type = routes[prev + diffTypesPtrOffset];
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
function createFP(slide, down, k, M) {
|
|
110
|
+
if (slide && slide.y === -1 && down && down.y === -1) {
|
|
111
|
+
return { y: 0, id: 0 };
|
|
112
|
+
}
|
|
113
|
+
if ((down && down.y === -1) ||
|
|
114
|
+
k === M ||
|
|
115
|
+
(slide && slide.y) > (down && down.y) + 1) {
|
|
116
|
+
const prev = slide.id;
|
|
117
|
+
ptr++;
|
|
118
|
+
routes[ptr] = prev;
|
|
119
|
+
routes[ptr + diffTypesPtrOffset] = ADDED;
|
|
120
|
+
return { y: slide.y, id: ptr };
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const prev = down.id;
|
|
124
|
+
ptr++;
|
|
125
|
+
routes[ptr] = prev;
|
|
126
|
+
routes[ptr + diffTypesPtrOffset] = REMOVED;
|
|
127
|
+
return { y: down.y + 1, id: ptr };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function snake(k, slide, down, _offset, A, B) {
|
|
131
|
+
const M = A.length;
|
|
132
|
+
const N = B.length;
|
|
133
|
+
if (k < -N || M < k)
|
|
134
|
+
return { y: -1, id: -1 };
|
|
135
|
+
const fp = createFP(slide, down, k, M);
|
|
136
|
+
while (fp.y + k < M && fp.y < N && A[fp.y + k] === B[fp.y]) {
|
|
137
|
+
const prev = fp.id;
|
|
138
|
+
ptr++;
|
|
139
|
+
fp.id = ptr;
|
|
140
|
+
fp.y += 1;
|
|
141
|
+
routes[ptr] = prev;
|
|
142
|
+
routes[ptr + diffTypesPtrOffset] = COMMON;
|
|
143
|
+
}
|
|
144
|
+
return fp;
|
|
145
|
+
}
|
|
146
|
+
while (fp[delta + offset].y < N) {
|
|
147
|
+
p = p + 1;
|
|
148
|
+
for (let k = -p; k < delta; ++k) {
|
|
149
|
+
fp[k + offset] = snake(k, fp[k - 1 + offset], fp[k + 1 + offset], offset, A, B);
|
|
150
|
+
}
|
|
151
|
+
for (let k = delta + p; k > delta; --k) {
|
|
152
|
+
fp[k + offset] = snake(k, fp[k - 1 + offset], fp[k + 1 + offset], offset, A, B);
|
|
153
|
+
}
|
|
154
|
+
fp[delta + offset] = snake(delta, fp[delta - 1 + offset], fp[delta + 1 + offset], offset, A, B);
|
|
155
|
+
}
|
|
156
|
+
return [
|
|
157
|
+
...prefixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
|
158
|
+
...backTrace(A, B, fp[delta + offset], swapped),
|
|
159
|
+
...suffixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Renders the differences between the actual and expected strings
|
|
164
|
+
* Partially inspired from https://github.com/kpdecker/jsdiff
|
|
165
|
+
* @param A Actual string
|
|
166
|
+
* @param B Expected string
|
|
167
|
+
*/
|
|
168
|
+
export function diffstr(A, B) {
|
|
169
|
+
function unescape(string) {
|
|
170
|
+
// unescape invisible characters.
|
|
171
|
+
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#escape_sequences
|
|
172
|
+
return string
|
|
173
|
+
.replaceAll("\b", "\\b")
|
|
174
|
+
.replaceAll("\f", "\\f")
|
|
175
|
+
.replaceAll("\t", "\\t")
|
|
176
|
+
.replaceAll("\v", "\\v")
|
|
177
|
+
.replaceAll(// does not remove line breaks
|
|
178
|
+
/\r\n|\r|\n/g, (str) => str === "\r" ? "\\r" : str === "\n" ? "\\n\n" : "\\r\\n\r\n");
|
|
179
|
+
}
|
|
180
|
+
function tokenize(string, { wordDiff = false } = {}) {
|
|
181
|
+
if (wordDiff) {
|
|
182
|
+
// Split string on whitespace symbols
|
|
183
|
+
const tokens = string.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/);
|
|
184
|
+
// Extended Latin character set
|
|
185
|
+
const words = /^[a-zA-Z\u{C0}-\u{FF}\u{D8}-\u{F6}\u{F8}-\u{2C6}\u{2C8}-\u{2D7}\u{2DE}-\u{2FF}\u{1E00}-\u{1EFF}]+$/u;
|
|
186
|
+
// Join boundary splits that we do not consider to be boundaries and merge empty strings surrounded by word chars
|
|
187
|
+
for (let i = 0; i < tokens.length - 1; i++) {
|
|
188
|
+
if (!tokens[i + 1] && tokens[i + 2] && words.test(tokens[i]) &&
|
|
189
|
+
words.test(tokens[i + 2])) {
|
|
190
|
+
tokens[i] += tokens[i + 2];
|
|
191
|
+
tokens.splice(i + 1, 2);
|
|
192
|
+
i--;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return tokens.filter((token) => token);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Split string on new lines symbols
|
|
199
|
+
const tokens = [], lines = string.split(/(\n|\r\n)/);
|
|
200
|
+
// Ignore final empty token when text ends with a newline
|
|
201
|
+
if (!lines[lines.length - 1]) {
|
|
202
|
+
lines.pop();
|
|
203
|
+
}
|
|
204
|
+
// Merge the content and line separators into single tokens
|
|
205
|
+
for (let i = 0; i < lines.length; i++) {
|
|
206
|
+
if (i % 2) {
|
|
207
|
+
tokens[tokens.length - 1] += lines[i];
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
tokens.push(lines[i]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return tokens;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Create details by filtering relevant word-diff for current line
|
|
217
|
+
// and merge "space-diff" if surrounded by word-diff for cleaner displays
|
|
218
|
+
function createDetails(line, tokens) {
|
|
219
|
+
return tokens.filter(({ type }) => type === line.type || type === DiffType.common).map((result, i, t) => {
|
|
220
|
+
if ((result.type === DiffType.common) && (t[i - 1]) &&
|
|
221
|
+
(t[i - 1]?.type === t[i + 1]?.type) && /\s+/.test(result.value)) {
|
|
222
|
+
return {
|
|
223
|
+
...result,
|
|
224
|
+
type: t[i - 1].type,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
// Compute multi-line diff
|
|
231
|
+
const diffResult = diff(tokenize(`${unescape(A)}\n`), tokenize(`${unescape(B)}\n`));
|
|
232
|
+
const added = [], removed = [];
|
|
233
|
+
for (const result of diffResult) {
|
|
234
|
+
if (result.type === DiffType.added) {
|
|
235
|
+
added.push(result);
|
|
236
|
+
}
|
|
237
|
+
if (result.type === DiffType.removed) {
|
|
238
|
+
removed.push(result);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Compute word-diff
|
|
242
|
+
const aLines = added.length < removed.length ? added : removed;
|
|
243
|
+
const bLines = aLines === removed ? added : removed;
|
|
244
|
+
for (const a of aLines) {
|
|
245
|
+
let tokens = [], b;
|
|
246
|
+
// Search another diff line with at least one common token
|
|
247
|
+
while (bLines.length) {
|
|
248
|
+
b = bLines.shift();
|
|
249
|
+
tokens = diff(tokenize(a.value, { wordDiff: true }), tokenize(b?.value ?? "", { wordDiff: true }));
|
|
250
|
+
if (tokens.some(({ type, value }) => type === DiffType.common && value.trim().length)) {
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// Register word-diff details
|
|
255
|
+
a.details = createDetails(a, tokens);
|
|
256
|
+
if (b) {
|
|
257
|
+
b.details = createDetails(b, tokens);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return diffResult;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Colors the output of assertion diffs
|
|
264
|
+
* @param diffType Difference type, either added or removed
|
|
265
|
+
*/
|
|
266
|
+
function createColor(diffType, { background = false } = {}) {
|
|
267
|
+
// TODO(@littledivy): Remove this when we can detect
|
|
268
|
+
// true color terminals.
|
|
269
|
+
// https://github.com/denoland/deno_std/issues/2575
|
|
270
|
+
background = false;
|
|
271
|
+
switch (diffType) {
|
|
272
|
+
case DiffType.added:
|
|
273
|
+
return (s) => background ? bgGreen(white(s)) : green(bold(s));
|
|
274
|
+
case DiffType.removed:
|
|
275
|
+
return (s) => background ? bgRed(white(s)) : red(bold(s));
|
|
276
|
+
default:
|
|
277
|
+
return white;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Prefixes `+` or `-` in diff output
|
|
282
|
+
* @param diffType Difference type, either added or removed
|
|
283
|
+
*/
|
|
284
|
+
function createSign(diffType) {
|
|
285
|
+
switch (diffType) {
|
|
286
|
+
case DiffType.added:
|
|
287
|
+
return "+ ";
|
|
288
|
+
case DiffType.removed:
|
|
289
|
+
return "- ";
|
|
290
|
+
default:
|
|
291
|
+
return " ";
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
export function buildMessage(diffResult, { stringDiff = false } = {}) {
|
|
295
|
+
const messages = [], diffMessages = [];
|
|
296
|
+
messages.push("");
|
|
297
|
+
messages.push("");
|
|
298
|
+
messages.push(` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${green(bold("Expected"))}`);
|
|
299
|
+
messages.push("");
|
|
300
|
+
messages.push("");
|
|
301
|
+
diffResult.forEach((result) => {
|
|
302
|
+
const c = createColor(result.type);
|
|
303
|
+
const line = result.details?.map((detail) => detail.type !== DiffType.common
|
|
304
|
+
? createColor(detail.type, { background: true })(detail.value)
|
|
305
|
+
: detail.value).join("") ?? result.value;
|
|
306
|
+
diffMessages.push(c(`${createSign(result.type)}${line}`));
|
|
307
|
+
});
|
|
308
|
+
messages.push(...(stringDiff ? [diffMessages.join("")] : diffMessages));
|
|
309
|
+
messages.push("");
|
|
310
|
+
return messages;
|
|
311
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CAN_NOT_DISPLAY = "[Cannot display]";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function format(v: unknown): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
|
5
|
+
* make tests less flaky
|
|
6
|
+
* @param v Value to be formatted
|
|
7
|
+
*/
|
|
8
|
+
import * as dntShim from "../../../../_dnt.test_shims.js";
|
|
9
|
+
export function format(v) {
|
|
10
|
+
// deno-lint-ignore no-explicit-any
|
|
11
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
12
|
+
return typeof Deno?.inspect === "function"
|
|
13
|
+
? Deno.inspect(v, {
|
|
14
|
+
depth: Infinity,
|
|
15
|
+
sorted: true,
|
|
16
|
+
trailingComma: true,
|
|
17
|
+
compact: false,
|
|
18
|
+
iterableLimit: Infinity,
|
|
19
|
+
// getters should be true in assertEquals.
|
|
20
|
+
getters: true,
|
|
21
|
+
})
|
|
22
|
+
: `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make an assertion that `actual` and `expected` are almost equal numbers through
|
|
3
|
+
* a given tolerance. It can be used to take into account IEEE-754 double-precision
|
|
4
|
+
* floating-point representation limitations.
|
|
5
|
+
* If the values are not almost equal then throw.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
|
|
10
|
+
*
|
|
11
|
+
* assertAlmostEquals(0.1, 0.2);
|
|
12
|
+
*
|
|
13
|
+
* // Using a custom tolerance value
|
|
14
|
+
* assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
|
|
15
|
+
* assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertAlmostEquals(actual: number, expected: number, tolerance?: number, msg?: string): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import { AssertionError } from "./assertion_error.js";
|
|
3
|
+
/**
|
|
4
|
+
* Make an assertion that `actual` and `expected` are almost equal numbers through
|
|
5
|
+
* a given tolerance. It can be used to take into account IEEE-754 double-precision
|
|
6
|
+
* floating-point representation limitations.
|
|
7
|
+
* If the values are not almost equal then throw.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/assert/mod.ts";
|
|
12
|
+
*
|
|
13
|
+
* assertAlmostEquals(0.1, 0.2);
|
|
14
|
+
*
|
|
15
|
+
* // Using a custom tolerance value
|
|
16
|
+
* assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
|
|
17
|
+
* assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function assertAlmostEquals(actual, expected, tolerance = 1e-7, msg) {
|
|
21
|
+
if (Object.is(actual, expected)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const delta = Math.abs(expected - actual);
|
|
25
|
+
if (delta <= tolerance) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
29
|
+
const f = (n) => Number.isInteger(n) ? n : n.toExponential();
|
|
30
|
+
throw new AssertionError(`Expected actual: "${f(actual)}" to be close to "${f(expected)}": \
|
|
31
|
+
delta "${f(delta)}" is greater than "${f(tolerance)}"${msgSuffix}`);
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make an assertion that `actual` includes the `expected` values.
|
|
3
|
+
* If not then an error will be thrown.
|
|
4
|
+
*
|
|
5
|
+
* Type parameter can be specified to ensure values under comparison have the same type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/assert/assert_array_includes.ts";
|
|
10
|
+
*
|
|
11
|
+
* assertArrayIncludes<number>([1, 2], [2])
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function assertArrayIncludes<T>(actual: ArrayLike<T>, expected: ArrayLike<T>, msg?: string): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import { equal } from "./equal.js";
|
|
3
|
+
import { format } from "./_format.js";
|
|
4
|
+
import { AssertionError } from "./assertion_error.js";
|
|
5
|
+
/**
|
|
6
|
+
* Make an assertion that `actual` includes the `expected` values.
|
|
7
|
+
* If not then an error will be thrown.
|
|
8
|
+
*
|
|
9
|
+
* Type parameter can be specified to ensure values under comparison have the same type.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/assert/assert_array_includes.ts";
|
|
14
|
+
*
|
|
15
|
+
* assertArrayIncludes<number>([1, 2], [2])
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function assertArrayIncludes(actual, expected, msg) {
|
|
19
|
+
const missing = [];
|
|
20
|
+
for (let i = 0; i < expected.length; i++) {
|
|
21
|
+
let found = false;
|
|
22
|
+
for (let j = 0; j < actual.length; j++) {
|
|
23
|
+
if (equal(expected[i], actual[j])) {
|
|
24
|
+
found = true;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!found) {
|
|
29
|
+
missing.push(expected[i]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (missing.length === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
36
|
+
msg = `Expected actual: "${format(actual)}" to include: "${format(expected)}"${msgSuffix}\nmissing: ${format(missing)}`;
|
|
37
|
+
throw new AssertionError(msg);
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make an assertion that `actual` and `expected` are equal, deeply. If not
|
|
3
|
+
* deeply equal, then throw.
|
|
4
|
+
*
|
|
5
|
+
* Type parameter can be specified to ensure values under comparison have the same type.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts";
|
|
10
|
+
*
|
|
11
|
+
* Deno.test("example", function (): void {
|
|
12
|
+
* assertEquals("world", "world");
|
|
13
|
+
* assertEquals({ hello: "world" }, { hello: "world" });
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertEquals<T>(actual: T, expected: T, msg?: string): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import { equal } from "./equal.js";
|
|
3
|
+
import { format } from "./_format.js";
|
|
4
|
+
import { AssertionError } from "./assertion_error.js";
|
|
5
|
+
import { red } from "../fmt/colors.js";
|
|
6
|
+
import { buildMessage, diff, diffstr } from "../_util/diff.js";
|
|
7
|
+
import { CAN_NOT_DISPLAY } from "./_constants.js";
|
|
8
|
+
/**
|
|
9
|
+
* Make an assertion that `actual` and `expected` are equal, deeply. If not
|
|
10
|
+
* deeply equal, then throw.
|
|
11
|
+
*
|
|
12
|
+
* Type parameter can be specified to ensure values under comparison have the same type.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts";
|
|
17
|
+
*
|
|
18
|
+
* Deno.test("example", function (): void {
|
|
19
|
+
* assertEquals("world", "world");
|
|
20
|
+
* assertEquals({ hello: "world" }, { hello: "world" });
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function assertEquals(actual, expected, msg) {
|
|
25
|
+
if (equal(actual, expected)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
29
|
+
let message = `Values are not equal${msgSuffix}`;
|
|
30
|
+
const actualString = format(actual);
|
|
31
|
+
const expectedString = format(expected);
|
|
32
|
+
try {
|
|
33
|
+
const stringDiff = (typeof actual === "string") &&
|
|
34
|
+
(typeof expected === "string");
|
|
35
|
+
const diffResult = stringDiff
|
|
36
|
+
? diffstr(actual, expected)
|
|
37
|
+
: diff(actualString.split("\n"), expectedString.split("\n"));
|
|
38
|
+
const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
|
|
39
|
+
message = `${message}\n${diffMsg}`;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
message = `${message}\n${red(CAN_NOT_DISPLAY)} + \n\n`;
|
|
43
|
+
}
|
|
44
|
+
throw new AssertionError(message);
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
import { AssertionError } from "./assertion_error.js";
|
|
3
|
+
/**
|
|
4
|
+
* Make an assertion that actual is not null or undefined.
|
|
5
|
+
* If not then throw.
|
|
6
|
+
*/
|
|
7
|
+
export function assertExists(actual, msg) {
|
|
8
|
+
if (actual === undefined || actual === null) {
|
|
9
|
+
const msgSuffix = msg ? `: ${msg}` : ".";
|
|
10
|
+
msg =
|
|
11
|
+
`Expected actual: "${actual}" to not be null or undefined${msgSuffix}`;
|
|
12
|
+
throw new AssertionError(msg);
|
|
13
|
+
}
|
|
14
|
+
}
|