mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-04-04 14:29:47 +00:00
chore: Update deps
This commit is contained in:
501
lib/script/deps/deno.land/std@0.97.0/fmt/colors.js
Normal file
501
lib/script/deps/deno.land/std@0.97.0/fmt/colors.js
Normal file
@@ -0,0 +1,501 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.stripColor = exports.bgRgb24 = exports.rgb24 = exports.bgRgb8 = exports.rgb8 = exports.bgBrightWhite = exports.bgBrightCyan = exports.bgBrightMagenta = exports.bgBrightBlue = exports.bgBrightYellow = exports.bgBrightGreen = exports.bgBrightRed = exports.bgBrightBlack = exports.bgWhite = exports.bgCyan = exports.bgMagenta = exports.bgBlue = exports.bgYellow = exports.bgGreen = exports.bgRed = exports.bgBlack = exports.brightWhite = exports.brightCyan = exports.brightMagenta = exports.brightBlue = exports.brightYellow = exports.brightGreen = exports.brightRed = exports.brightBlack = exports.gray = exports.white = exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = exports.black = exports.strikethrough = exports.hidden = exports.inverse = exports.underline = exports.italic = exports.dim = exports.bold = exports.reset = exports.getColorEnabled = exports.setColorEnabled = void 0;
|
||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
// A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
|
||||
// on npm.
|
||||
//
|
||||
// ```
|
||||
// import { bgBlue, red, bold } from "https://deno.land/std/fmt/colors.ts";
|
||||
// console.log(bgBlue(red(bold("Hello world!"))));
|
||||
// ```
|
||||
//
|
||||
// This module supports `NO_COLOR` environmental variable disabling any coloring
|
||||
// if `NO_COLOR` is set.
|
||||
//
|
||||
// This module is browser compatible.
|
||||
const dntShim = __importStar(require("../../../../_dnt.test_shims.js"));
|
||||
const noColor = dntShim.dntGlobalThis.Deno?.noColor ?? true;
|
||||
let enabled = !noColor;
|
||||
/**
|
||||
* Set changing text color to enabled or disabled
|
||||
* @param value
|
||||
*/
|
||||
function setColorEnabled(value) {
|
||||
if (noColor) {
|
||||
return;
|
||||
}
|
||||
enabled = value;
|
||||
}
|
||||
exports.setColorEnabled = setColorEnabled;
|
||||
/** Get whether text color change is enabled or disabled. */
|
||||
function getColorEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
exports.getColorEnabled = getColorEnabled;
|
||||
/**
|
||||
* Builds color code
|
||||
* @param open
|
||||
* @param close
|
||||
*/
|
||||
function code(open, close) {
|
||||
return {
|
||||
open: `\x1b[${open.join(";")}m`,
|
||||
close: `\x1b[${close}m`,
|
||||
regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Applies color and background based on color code and its associated text
|
||||
* @param str text to apply color settings to
|
||||
* @param code color code to apply
|
||||
*/
|
||||
function run(str, code) {
|
||||
return enabled
|
||||
? `${code.open}${str.replace(code.regexp, code.open)}${code.close}`
|
||||
: str;
|
||||
}
|
||||
/**
|
||||
* Reset the text modified
|
||||
* @param str text to reset
|
||||
*/
|
||||
function reset(str) {
|
||||
return run(str, code([0], 0));
|
||||
}
|
||||
exports.reset = reset;
|
||||
/**
|
||||
* Make the text bold.
|
||||
* @param str text to make bold
|
||||
*/
|
||||
function bold(str) {
|
||||
return run(str, code([1], 22));
|
||||
}
|
||||
exports.bold = bold;
|
||||
/**
|
||||
* The text emits only a small amount of light.
|
||||
* @param str text to dim
|
||||
*/
|
||||
function dim(str) {
|
||||
return run(str, code([2], 22));
|
||||
}
|
||||
exports.dim = dim;
|
||||
/**
|
||||
* Make the text italic.
|
||||
* @param str text to make italic
|
||||
*/
|
||||
function italic(str) {
|
||||
return run(str, code([3], 23));
|
||||
}
|
||||
exports.italic = italic;
|
||||
/**
|
||||
* Make the text underline.
|
||||
* @param str text to underline
|
||||
*/
|
||||
function underline(str) {
|
||||
return run(str, code([4], 24));
|
||||
}
|
||||
exports.underline = underline;
|
||||
/**
|
||||
* Invert background color and text color.
|
||||
* @param str text to invert its color
|
||||
*/
|
||||
function inverse(str) {
|
||||
return run(str, code([7], 27));
|
||||
}
|
||||
exports.inverse = inverse;
|
||||
/**
|
||||
* Make the text hidden.
|
||||
* @param str text to hide
|
||||
*/
|
||||
function hidden(str) {
|
||||
return run(str, code([8], 28));
|
||||
}
|
||||
exports.hidden = hidden;
|
||||
/**
|
||||
* Put horizontal line through the center of the text.
|
||||
* @param str text to strike through
|
||||
*/
|
||||
function strikethrough(str) {
|
||||
return run(str, code([9], 29));
|
||||
}
|
||||
exports.strikethrough = strikethrough;
|
||||
/**
|
||||
* Set text color to black.
|
||||
* @param str text to make black
|
||||
*/
|
||||
function black(str) {
|
||||
return run(str, code([30], 39));
|
||||
}
|
||||
exports.black = black;
|
||||
/**
|
||||
* Set text color to red.
|
||||
* @param str text to make red
|
||||
*/
|
||||
function red(str) {
|
||||
return run(str, code([31], 39));
|
||||
}
|
||||
exports.red = red;
|
||||
/**
|
||||
* Set text color to green.
|
||||
* @param str text to make green
|
||||
*/
|
||||
function green(str) {
|
||||
return run(str, code([32], 39));
|
||||
}
|
||||
exports.green = green;
|
||||
/**
|
||||
* Set text color to yellow.
|
||||
* @param str text to make yellow
|
||||
*/
|
||||
function yellow(str) {
|
||||
return run(str, code([33], 39));
|
||||
}
|
||||
exports.yellow = yellow;
|
||||
/**
|
||||
* Set text color to blue.
|
||||
* @param str text to make blue
|
||||
*/
|
||||
function blue(str) {
|
||||
return run(str, code([34], 39));
|
||||
}
|
||||
exports.blue = blue;
|
||||
/**
|
||||
* Set text color to magenta.
|
||||
* @param str text to make magenta
|
||||
*/
|
||||
function magenta(str) {
|
||||
return run(str, code([35], 39));
|
||||
}
|
||||
exports.magenta = magenta;
|
||||
/**
|
||||
* Set text color to cyan.
|
||||
* @param str text to make cyan
|
||||
*/
|
||||
function cyan(str) {
|
||||
return run(str, code([36], 39));
|
||||
}
|
||||
exports.cyan = cyan;
|
||||
/**
|
||||
* Set text color to white.
|
||||
* @param str text to make white
|
||||
*/
|
||||
function white(str) {
|
||||
return run(str, code([37], 39));
|
||||
}
|
||||
exports.white = white;
|
||||
/**
|
||||
* Set text color to gray.
|
||||
* @param str text to make gray
|
||||
*/
|
||||
function gray(str) {
|
||||
return brightBlack(str);
|
||||
}
|
||||
exports.gray = gray;
|
||||
/**
|
||||
* Set text color to bright black.
|
||||
* @param str text to make bright-black
|
||||
*/
|
||||
function brightBlack(str) {
|
||||
return run(str, code([90], 39));
|
||||
}
|
||||
exports.brightBlack = brightBlack;
|
||||
/**
|
||||
* Set text color to bright red.
|
||||
* @param str text to make bright-red
|
||||
*/
|
||||
function brightRed(str) {
|
||||
return run(str, code([91], 39));
|
||||
}
|
||||
exports.brightRed = brightRed;
|
||||
/**
|
||||
* Set text color to bright green.
|
||||
* @param str text to make bright-green
|
||||
*/
|
||||
function brightGreen(str) {
|
||||
return run(str, code([92], 39));
|
||||
}
|
||||
exports.brightGreen = brightGreen;
|
||||
/**
|
||||
* Set text color to bright yellow.
|
||||
* @param str text to make bright-yellow
|
||||
*/
|
||||
function brightYellow(str) {
|
||||
return run(str, code([93], 39));
|
||||
}
|
||||
exports.brightYellow = brightYellow;
|
||||
/**
|
||||
* Set text color to bright blue.
|
||||
* @param str text to make bright-blue
|
||||
*/
|
||||
function brightBlue(str) {
|
||||
return run(str, code([94], 39));
|
||||
}
|
||||
exports.brightBlue = brightBlue;
|
||||
/**
|
||||
* Set text color to bright magenta.
|
||||
* @param str text to make bright-magenta
|
||||
*/
|
||||
function brightMagenta(str) {
|
||||
return run(str, code([95], 39));
|
||||
}
|
||||
exports.brightMagenta = brightMagenta;
|
||||
/**
|
||||
* Set text color to bright cyan.
|
||||
* @param str text to make bright-cyan
|
||||
*/
|
||||
function brightCyan(str) {
|
||||
return run(str, code([96], 39));
|
||||
}
|
||||
exports.brightCyan = brightCyan;
|
||||
/**
|
||||
* Set text color to bright white.
|
||||
* @param str text to make bright-white
|
||||
*/
|
||||
function brightWhite(str) {
|
||||
return run(str, code([97], 39));
|
||||
}
|
||||
exports.brightWhite = brightWhite;
|
||||
/**
|
||||
* Set background color to black.
|
||||
* @param str text to make its background black
|
||||
*/
|
||||
function bgBlack(str) {
|
||||
return run(str, code([40], 49));
|
||||
}
|
||||
exports.bgBlack = bgBlack;
|
||||
/**
|
||||
* Set background color to red.
|
||||
* @param str text to make its background red
|
||||
*/
|
||||
function bgRed(str) {
|
||||
return run(str, code([41], 49));
|
||||
}
|
||||
exports.bgRed = bgRed;
|
||||
/**
|
||||
* Set background color to green.
|
||||
* @param str text to make its background green
|
||||
*/
|
||||
function bgGreen(str) {
|
||||
return run(str, code([42], 49));
|
||||
}
|
||||
exports.bgGreen = bgGreen;
|
||||
/**
|
||||
* Set background color to yellow.
|
||||
* @param str text to make its background yellow
|
||||
*/
|
||||
function bgYellow(str) {
|
||||
return run(str, code([43], 49));
|
||||
}
|
||||
exports.bgYellow = bgYellow;
|
||||
/**
|
||||
* Set background color to blue.
|
||||
* @param str text to make its background blue
|
||||
*/
|
||||
function bgBlue(str) {
|
||||
return run(str, code([44], 49));
|
||||
}
|
||||
exports.bgBlue = bgBlue;
|
||||
/**
|
||||
* Set background color to magenta.
|
||||
* @param str text to make its background magenta
|
||||
*/
|
||||
function bgMagenta(str) {
|
||||
return run(str, code([45], 49));
|
||||
}
|
||||
exports.bgMagenta = bgMagenta;
|
||||
/**
|
||||
* Set background color to cyan.
|
||||
* @param str text to make its background cyan
|
||||
*/
|
||||
function bgCyan(str) {
|
||||
return run(str, code([46], 49));
|
||||
}
|
||||
exports.bgCyan = bgCyan;
|
||||
/**
|
||||
* Set background color to white.
|
||||
* @param str text to make its background white
|
||||
*/
|
||||
function bgWhite(str) {
|
||||
return run(str, code([47], 49));
|
||||
}
|
||||
exports.bgWhite = bgWhite;
|
||||
/**
|
||||
* Set background color to bright black.
|
||||
* @param str text to make its background bright-black
|
||||
*/
|
||||
function bgBrightBlack(str) {
|
||||
return run(str, code([100], 49));
|
||||
}
|
||||
exports.bgBrightBlack = bgBrightBlack;
|
||||
/**
|
||||
* Set background color to bright red.
|
||||
* @param str text to make its background bright-red
|
||||
*/
|
||||
function bgBrightRed(str) {
|
||||
return run(str, code([101], 49));
|
||||
}
|
||||
exports.bgBrightRed = bgBrightRed;
|
||||
/**
|
||||
* Set background color to bright green.
|
||||
* @param str text to make its background bright-green
|
||||
*/
|
||||
function bgBrightGreen(str) {
|
||||
return run(str, code([102], 49));
|
||||
}
|
||||
exports.bgBrightGreen = bgBrightGreen;
|
||||
/**
|
||||
* Set background color to bright yellow.
|
||||
* @param str text to make its background bright-yellow
|
||||
*/
|
||||
function bgBrightYellow(str) {
|
||||
return run(str, code([103], 49));
|
||||
}
|
||||
exports.bgBrightYellow = bgBrightYellow;
|
||||
/**
|
||||
* Set background color to bright blue.
|
||||
* @param str text to make its background bright-blue
|
||||
*/
|
||||
function bgBrightBlue(str) {
|
||||
return run(str, code([104], 49));
|
||||
}
|
||||
exports.bgBrightBlue = bgBrightBlue;
|
||||
/**
|
||||
* Set background color to bright magenta.
|
||||
* @param str text to make its background bright-magenta
|
||||
*/
|
||||
function bgBrightMagenta(str) {
|
||||
return run(str, code([105], 49));
|
||||
}
|
||||
exports.bgBrightMagenta = bgBrightMagenta;
|
||||
/**
|
||||
* Set background color to bright cyan.
|
||||
* @param str text to make its background bright-cyan
|
||||
*/
|
||||
function bgBrightCyan(str) {
|
||||
return run(str, code([106], 49));
|
||||
}
|
||||
exports.bgBrightCyan = bgBrightCyan;
|
||||
/**
|
||||
* Set background color to bright white.
|
||||
* @param str text to make its background bright-white
|
||||
*/
|
||||
function bgBrightWhite(str) {
|
||||
return run(str, code([107], 49));
|
||||
}
|
||||
exports.bgBrightWhite = bgBrightWhite;
|
||||
/* Special Color Sequences */
|
||||
/**
|
||||
* Clam and truncate color codes
|
||||
* @param n
|
||||
* @param max number to truncate to
|
||||
* @param min number to truncate from
|
||||
*/
|
||||
function clampAndTruncate(n, max = 255, min = 0) {
|
||||
return Math.trunc(Math.max(Math.min(n, max), min));
|
||||
}
|
||||
/**
|
||||
* Set text color using paletted 8bit colors.
|
||||
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
||||
* @param str text color to apply paletted 8bit colors to
|
||||
* @param color code
|
||||
*/
|
||||
function rgb8(str, color) {
|
||||
return run(str, code([38, 5, clampAndTruncate(color)], 39));
|
||||
}
|
||||
exports.rgb8 = rgb8;
|
||||
/**
|
||||
* Set background color using paletted 8bit colors.
|
||||
* https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
||||
* @param str text color to apply paletted 8bit background colors to
|
||||
* @param color code
|
||||
*/
|
||||
function bgRgb8(str, color) {
|
||||
return run(str, code([48, 5, clampAndTruncate(color)], 49));
|
||||
}
|
||||
exports.bgRgb8 = bgRgb8;
|
||||
/**
|
||||
* Set text color using 24bit rgb.
|
||||
* `color` can be a number in range `0x000000` to `0xffffff` or
|
||||
* an `Rgb`.
|
||||
*
|
||||
* To produce the color magenta:
|
||||
*
|
||||
* rgb24("foo", 0xff00ff);
|
||||
* rgb24("foo", {r: 255, g: 0, b: 255});
|
||||
* @param str text color to apply 24bit rgb to
|
||||
* @param color code
|
||||
*/
|
||||
function rgb24(str, color) {
|
||||
if (typeof color === "number") {
|
||||
return run(str, code([38, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 39));
|
||||
}
|
||||
return run(str, code([
|
||||
38,
|
||||
2,
|
||||
clampAndTruncate(color.r),
|
||||
clampAndTruncate(color.g),
|
||||
clampAndTruncate(color.b),
|
||||
], 39));
|
||||
}
|
||||
exports.rgb24 = rgb24;
|
||||
/**
|
||||
* Set background color using 24bit rgb.
|
||||
* `color` can be a number in range `0x000000` to `0xffffff` or
|
||||
* an `Rgb`.
|
||||
*
|
||||
* To produce the color magenta:
|
||||
*
|
||||
* bgRgb24("foo", 0xff00ff);
|
||||
* bgRgb24("foo", {r: 255, g: 0, b: 255});
|
||||
* @param str text color to apply 24bit rgb to
|
||||
* @param color code
|
||||
*/
|
||||
function bgRgb24(str, color) {
|
||||
if (typeof color === "number") {
|
||||
return run(str, code([48, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 49));
|
||||
}
|
||||
return run(str, code([
|
||||
48,
|
||||
2,
|
||||
clampAndTruncate(color.r),
|
||||
clampAndTruncate(color.g),
|
||||
clampAndTruncate(color.b),
|
||||
], 49));
|
||||
}
|
||||
exports.bgRgb24 = bgRgb24;
|
||||
// https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js
|
||||
const ANSI_PATTERN = new RegExp([
|
||||
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
||||
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
||||
].join("|"), "g");
|
||||
/**
|
||||
* Remove ANSI escape codes from the string.
|
||||
* @param string to remove ANSI escape codes from
|
||||
*/
|
||||
function stripColor(string) {
|
||||
return string.replace(ANSI_PATTERN, "");
|
||||
}
|
||||
exports.stripColor = stripColor;
|
||||
164
lib/script/deps/deno.land/std@0.97.0/testing/_diff.js
Normal file
164
lib/script/deps/deno.land/std@0.97.0/testing/_diff.js
Normal file
@@ -0,0 +1,164 @@
|
||||
"use strict";
|
||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
// This module is browser compatible.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.diff = exports.DiffType = void 0;
|
||||
var DiffType;
|
||||
(function (DiffType) {
|
||||
DiffType["removed"] = "removed";
|
||||
DiffType["common"] = "common";
|
||||
DiffType["added"] = "added";
|
||||
})(DiffType = exports.DiffType || (exports.DiffType = {}));
|
||||
const REMOVED = 1;
|
||||
const COMMON = 2;
|
||||
const ADDED = 3;
|
||||
function createCommon(A, B, reverse) {
|
||||
const common = [];
|
||||
if (A.length === 0 || B.length === 0)
|
||||
return [];
|
||||
for (let i = 0; i < Math.min(A.length, B.length); i += 1) {
|
||||
if (A[reverse ? A.length - i - 1 : i] === B[reverse ? B.length - i - 1 : i]) {
|
||||
common.push(A[reverse ? A.length - i - 1 : i]);
|
||||
}
|
||||
else {
|
||||
return common;
|
||||
}
|
||||
}
|
||||
return common;
|
||||
}
|
||||
/**
|
||||
* Renders the differences between the actual and expected values
|
||||
* @param A Actual value
|
||||
* @param B Expected value
|
||||
*/
|
||||
function diff(A, B) {
|
||||
const prefixCommon = createCommon(A, B);
|
||||
const suffixCommon = createCommon(A.slice(prefixCommon.length), B.slice(prefixCommon.length), true).reverse();
|
||||
A = suffixCommon.length
|
||||
? A.slice(prefixCommon.length, -suffixCommon.length)
|
||||
: A.slice(prefixCommon.length);
|
||||
B = suffixCommon.length
|
||||
? B.slice(prefixCommon.length, -suffixCommon.length)
|
||||
: B.slice(prefixCommon.length);
|
||||
const swapped = B.length > A.length;
|
||||
[A, B] = swapped ? [B, A] : [A, B];
|
||||
const M = A.length;
|
||||
const N = B.length;
|
||||
if (!M && !N && !suffixCommon.length && !prefixCommon.length)
|
||||
return [];
|
||||
if (!N) {
|
||||
return [
|
||||
...prefixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
||||
...A.map((a) => ({
|
||||
type: swapped ? DiffType.added : DiffType.removed,
|
||||
value: a,
|
||||
})),
|
||||
...suffixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
||||
];
|
||||
}
|
||||
const offset = N;
|
||||
const delta = M - N;
|
||||
const size = M + N + 1;
|
||||
const fp = new Array(size).fill({ y: -1 });
|
||||
/**
|
||||
* INFO:
|
||||
* This buffer is used to save memory and improve performance.
|
||||
* The first half is used to save route and last half is used to save diff
|
||||
* type.
|
||||
* This is because, when I kept new uint8array area to save type,performance
|
||||
* worsened.
|
||||
*/
|
||||
const routes = new Uint32Array((M * N + size + 1) * 2);
|
||||
const diffTypesPtrOffset = routes.length / 2;
|
||||
let ptr = 0;
|
||||
let p = -1;
|
||||
function backTrace(A, B, current, swapped) {
|
||||
const M = A.length;
|
||||
const N = B.length;
|
||||
const result = [];
|
||||
let a = M - 1;
|
||||
let b = N - 1;
|
||||
let j = routes[current.id];
|
||||
let type = routes[current.id + diffTypesPtrOffset];
|
||||
while (true) {
|
||||
if (!j && !type)
|
||||
break;
|
||||
const prev = j;
|
||||
if (type === REMOVED) {
|
||||
result.unshift({
|
||||
type: swapped ? DiffType.removed : DiffType.added,
|
||||
value: B[b],
|
||||
});
|
||||
b -= 1;
|
||||
}
|
||||
else if (type === ADDED) {
|
||||
result.unshift({
|
||||
type: swapped ? DiffType.added : DiffType.removed,
|
||||
value: A[a],
|
||||
});
|
||||
a -= 1;
|
||||
}
|
||||
else {
|
||||
result.unshift({ type: DiffType.common, value: A[a] });
|
||||
a -= 1;
|
||||
b -= 1;
|
||||
}
|
||||
j = routes[prev];
|
||||
type = routes[prev + diffTypesPtrOffset];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function createFP(slide, down, k, M) {
|
||||
if (slide && slide.y === -1 && down && down.y === -1) {
|
||||
return { y: 0, id: 0 };
|
||||
}
|
||||
if ((down && down.y === -1) ||
|
||||
k === M ||
|
||||
(slide && slide.y) > (down && down.y) + 1) {
|
||||
const prev = slide.id;
|
||||
ptr++;
|
||||
routes[ptr] = prev;
|
||||
routes[ptr + diffTypesPtrOffset] = ADDED;
|
||||
return { y: slide.y, id: ptr };
|
||||
}
|
||||
else {
|
||||
const prev = down.id;
|
||||
ptr++;
|
||||
routes[ptr] = prev;
|
||||
routes[ptr + diffTypesPtrOffset] = REMOVED;
|
||||
return { y: down.y + 1, id: ptr };
|
||||
}
|
||||
}
|
||||
function snake(k, slide, down, _offset, A, B) {
|
||||
const M = A.length;
|
||||
const N = B.length;
|
||||
if (k < -N || M < k)
|
||||
return { y: -1, id: -1 };
|
||||
const fp = createFP(slide, down, k, M);
|
||||
while (fp.y + k < M && fp.y < N && A[fp.y + k] === B[fp.y]) {
|
||||
const prev = fp.id;
|
||||
ptr++;
|
||||
fp.id = ptr;
|
||||
fp.y += 1;
|
||||
routes[ptr] = prev;
|
||||
routes[ptr + diffTypesPtrOffset] = COMMON;
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
while (fp[delta + offset].y < N) {
|
||||
p = p + 1;
|
||||
for (let k = -p; k < delta; ++k) {
|
||||
fp[k + offset] = snake(k, fp[k - 1 + offset], fp[k + 1 + offset], offset, A, B);
|
||||
}
|
||||
for (let k = delta + p; k > delta; --k) {
|
||||
fp[k + offset] = snake(k, fp[k - 1 + offset], fp[k + 1 + offset], offset, A, B);
|
||||
}
|
||||
fp[delta + offset] = snake(delta, fp[delta - 1 + offset], fp[delta + 1 + offset], offset, A, B);
|
||||
}
|
||||
return [
|
||||
...prefixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
||||
...backTrace(A, B, fp[delta + offset], swapped),
|
||||
...suffixCommon.map((c) => ({ type: DiffType.common, value: c })),
|
||||
];
|
||||
}
|
||||
exports.diff = diff;
|
||||
484
lib/script/deps/deno.land/std@0.97.0/testing/asserts.js
Normal file
484
lib/script/deps/deno.land/std@0.97.0/testing/asserts.js
Normal file
@@ -0,0 +1,484 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unreachable = exports.unimplemented = exports.assertThrowsAsync = exports.assertThrows = exports.fail = exports.assertObjectMatch = exports.assertNotMatch = exports.assertMatch = exports.assertArrayIncludes = exports.assertStringIncludes = exports.assertExists = exports.assertNotStrictEquals = exports.assertStrictEquals = exports.assertNotEquals = exports.assertEquals = exports.assert = exports.equal = exports._format = exports.AssertionError = void 0;
|
||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
// This module is browser compatible. Do not rely on good formatting of values
|
||||
// for AssertionError messages in browsers.
|
||||
const dntShim = __importStar(require("../../../../_dnt.test_shims.js"));
|
||||
const colors_js_1 = require("../fmt/colors.js");
|
||||
const _diff_js_1 = require("./_diff.js");
|
||||
const CAN_NOT_DISPLAY = "[Cannot display]";
|
||||
class AssertionError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "AssertionError";
|
||||
}
|
||||
}
|
||||
exports.AssertionError = AssertionError;
|
||||
/**
|
||||
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
|
||||
* make tests less flaky
|
||||
* @param v Value to be formatted
|
||||
*/
|
||||
function _format(v) {
|
||||
return dntShim.dntGlobalThis.Deno
|
||||
? dntShim.Deno.inspect(v, {
|
||||
depth: Infinity,
|
||||
sorted: true,
|
||||
trailingComma: true,
|
||||
compact: false,
|
||||
iterableLimit: Infinity,
|
||||
})
|
||||
: `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
|
||||
}
|
||||
exports._format = _format;
|
||||
/**
|
||||
* Colors the output of assertion diffs
|
||||
* @param diffType Difference type, either added or removed
|
||||
*/
|
||||
function createColor(diffType) {
|
||||
switch (diffType) {
|
||||
case _diff_js_1.DiffType.added:
|
||||
return (s) => (0, colors_js_1.green)((0, colors_js_1.bold)(s));
|
||||
case _diff_js_1.DiffType.removed:
|
||||
return (s) => (0, colors_js_1.red)((0, colors_js_1.bold)(s));
|
||||
default:
|
||||
return colors_js_1.white;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Prefixes `+` or `-` in diff output
|
||||
* @param diffType Difference type, either added or removed
|
||||
*/
|
||||
function createSign(diffType) {
|
||||
switch (diffType) {
|
||||
case _diff_js_1.DiffType.added:
|
||||
return "+ ";
|
||||
case _diff_js_1.DiffType.removed:
|
||||
return "- ";
|
||||
default:
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
function buildMessage(diffResult) {
|
||||
const messages = [];
|
||||
messages.push("");
|
||||
messages.push("");
|
||||
messages.push(` ${(0, colors_js_1.gray)((0, colors_js_1.bold)("[Diff]"))} ${(0, colors_js_1.red)((0, colors_js_1.bold)("Actual"))} / ${(0, colors_js_1.green)((0, colors_js_1.bold)("Expected"))}`);
|
||||
messages.push("");
|
||||
messages.push("");
|
||||
diffResult.forEach((result) => {
|
||||
const c = createColor(result.type);
|
||||
messages.push(c(`${createSign(result.type)}${result.value}`));
|
||||
});
|
||||
messages.push("");
|
||||
return messages;
|
||||
}
|
||||
function isKeyedCollection(x) {
|
||||
return [Symbol.iterator, "size"].every((k) => k in x);
|
||||
}
|
||||
/**
|
||||
* Deep equality comparison used in assertions
|
||||
* @param c actual value
|
||||
* @param d expected value
|
||||
*/
|
||||
function equal(c, d) {
|
||||
const seen = new Map();
|
||||
return (function compare(a, b) {
|
||||
// Have to render RegExp & Date for string comparison
|
||||
// unless it's mistreated as object
|
||||
if (a &&
|
||||
b &&
|
||||
((a instanceof RegExp && b instanceof RegExp) ||
|
||||
(a instanceof URL && b instanceof URL))) {
|
||||
return String(a) === String(b);
|
||||
}
|
||||
if (a instanceof Date && b instanceof Date) {
|
||||
const aTime = a.getTime();
|
||||
const bTime = b.getTime();
|
||||
// Check for NaN equality manually since NaN is not
|
||||
// equal to itself.
|
||||
if (Number.isNaN(aTime) && Number.isNaN(bTime)) {
|
||||
return true;
|
||||
}
|
||||
return a.getTime() === b.getTime();
|
||||
}
|
||||
if (Object.is(a, b)) {
|
||||
return true;
|
||||
}
|
||||
if (a && typeof a === "object" && b && typeof b === "object") {
|
||||
if (seen.get(a) === b) {
|
||||
return true;
|
||||
}
|
||||
if (Object.keys(a || {}).length !== Object.keys(b || {}).length) {
|
||||
return false;
|
||||
}
|
||||
if (isKeyedCollection(a) && isKeyedCollection(b)) {
|
||||
if (a.size !== b.size) {
|
||||
return false;
|
||||
}
|
||||
let unmatchedEntries = a.size;
|
||||
for (const [aKey, aValue] of a.entries()) {
|
||||
for (const [bKey, bValue] of b.entries()) {
|
||||
/* Given that Map keys can be references, we need
|
||||
* to ensure that they are also deeply equal */
|
||||
if ((aKey === aValue && bKey === bValue && compare(aKey, bKey)) ||
|
||||
(compare(aKey, bKey) && compare(aValue, bValue))) {
|
||||
unmatchedEntries--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return unmatchedEntries === 0;
|
||||
}
|
||||
const merged = { ...a, ...b };
|
||||
for (const key of [
|
||||
...Object.getOwnPropertyNames(merged),
|
||||
...Object.getOwnPropertySymbols(merged),
|
||||
]) {
|
||||
if (!compare(a && a[key], b && b[key])) {
|
||||
return false;
|
||||
}
|
||||
if (((key in a) && (!(key in b))) || ((key in b) && (!(key in a)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
seen.set(a, b);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})(c, d);
|
||||
}
|
||||
exports.equal = equal;
|
||||
/** Make an assertion, error will be thrown if `expr` does not have truthy value. */
|
||||
function assert(expr, msg = "") {
|
||||
if (!expr) {
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
exports.assert = assert;
|
||||
function assertEquals(actual, expected, msg) {
|
||||
if (equal(actual, expected)) {
|
||||
return;
|
||||
}
|
||||
let message = "";
|
||||
const actualString = _format(actual);
|
||||
const expectedString = _format(expected);
|
||||
try {
|
||||
const diffResult = (0, _diff_js_1.diff)(actualString.split("\n"), expectedString.split("\n"));
|
||||
const diffMsg = buildMessage(diffResult).join("\n");
|
||||
message = `Values are not equal:\n${diffMsg}`;
|
||||
}
|
||||
catch {
|
||||
message = `\n${(0, colors_js_1.red)(CAN_NOT_DISPLAY)} + \n\n`;
|
||||
}
|
||||
if (msg) {
|
||||
message = msg;
|
||||
}
|
||||
throw new AssertionError(message);
|
||||
}
|
||||
exports.assertEquals = assertEquals;
|
||||
function assertNotEquals(actual, expected, msg) {
|
||||
if (!equal(actual, expected)) {
|
||||
return;
|
||||
}
|
||||
let actualString;
|
||||
let expectedString;
|
||||
try {
|
||||
actualString = String(actual);
|
||||
}
|
||||
catch {
|
||||
actualString = "[Cannot display]";
|
||||
}
|
||||
try {
|
||||
expectedString = String(expected);
|
||||
}
|
||||
catch {
|
||||
expectedString = "[Cannot display]";
|
||||
}
|
||||
if (!msg) {
|
||||
msg = `actual: ${actualString} expected: ${expectedString}`;
|
||||
}
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
exports.assertNotEquals = assertNotEquals;
|
||||
function assertStrictEquals(actual, expected, msg) {
|
||||
if (actual === expected) {
|
||||
return;
|
||||
}
|
||||
let message;
|
||||
if (msg) {
|
||||
message = msg;
|
||||
}
|
||||
else {
|
||||
const actualString = _format(actual);
|
||||
const expectedString = _format(expected);
|
||||
if (actualString === expectedString) {
|
||||
const withOffset = actualString
|
||||
.split("\n")
|
||||
.map((l) => ` ${l}`)
|
||||
.join("\n");
|
||||
message =
|
||||
`Values have the same structure but are not reference-equal:\n\n${(0, colors_js_1.red)(withOffset)}\n`;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
const diffResult = (0, _diff_js_1.diff)(actualString.split("\n"), expectedString.split("\n"));
|
||||
const diffMsg = buildMessage(diffResult).join("\n");
|
||||
message = `Values are not strictly equal:\n${diffMsg}`;
|
||||
}
|
||||
catch {
|
||||
message = `\n${(0, colors_js_1.red)(CAN_NOT_DISPLAY)} + \n\n`;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new AssertionError(message);
|
||||
}
|
||||
exports.assertStrictEquals = assertStrictEquals;
|
||||
function assertNotStrictEquals(actual, expected, msg) {
|
||||
if (actual !== expected) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError(msg ?? `Expected "actual" to be strictly unequal to: ${_format(actual)}\n`);
|
||||
}
|
||||
exports.assertNotStrictEquals = assertNotStrictEquals;
|
||||
/**
|
||||
* Make an assertion that actual is not null or undefined. If not
|
||||
* then thrown.
|
||||
*/
|
||||
function assertExists(actual, msg) {
|
||||
if (actual === undefined || actual === null) {
|
||||
if (!msg) {
|
||||
msg =
|
||||
`actual: "${actual}" expected to match anything but null or undefined`;
|
||||
}
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
exports.assertExists = assertExists;
|
||||
/**
|
||||
* Make an assertion that actual includes expected. If not
|
||||
* then thrown.
|
||||
*/
|
||||
function assertStringIncludes(actual, expected, msg) {
|
||||
if (!actual.includes(expected)) {
|
||||
if (!msg) {
|
||||
msg = `actual: "${actual}" expected to contain: "${expected}"`;
|
||||
}
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
exports.assertStringIncludes = assertStringIncludes;
|
||||
function assertArrayIncludes(actual, expected, msg) {
|
||||
const missing = [];
|
||||
for (let i = 0; i < expected.length; i++) {
|
||||
let found = false;
|
||||
for (let j = 0; j < actual.length; j++) {
|
||||
if (equal(expected[i], actual[j])) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
missing.push(expected[i]);
|
||||
}
|
||||
}
|
||||
if (missing.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (!msg) {
|
||||
msg = `actual: "${_format(actual)}" expected to include: "${_format(expected)}"\nmissing: ${_format(missing)}`;
|
||||
}
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
exports.assertArrayIncludes = assertArrayIncludes;
|
||||
/**
|
||||
* Make an assertion that `actual` match RegExp `expected`. If not
|
||||
* then thrown
|
||||
*/
|
||||
function assertMatch(actual, expected, msg) {
|
||||
if (!expected.test(actual)) {
|
||||
if (!msg) {
|
||||
msg = `actual: "${actual}" expected to match: "${expected}"`;
|
||||
}
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
exports.assertMatch = assertMatch;
|
||||
/**
|
||||
* Make an assertion that `actual` not match RegExp `expected`. If match
|
||||
* then thrown
|
||||
*/
|
||||
function assertNotMatch(actual, expected, msg) {
|
||||
if (expected.test(actual)) {
|
||||
if (!msg) {
|
||||
msg = `actual: "${actual}" expected to not match: "${expected}"`;
|
||||
}
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
}
|
||||
exports.assertNotMatch = assertNotMatch;
|
||||
/**
|
||||
* Make an assertion that `actual` object is a subset of `expected` object, deeply.
|
||||
* If not, then throw.
|
||||
*/
|
||||
function assertObjectMatch(
|
||||
// deno-lint-ignore no-explicit-any
|
||||
actual, expected) {
|
||||
const seen = new WeakMap();
|
||||
return assertEquals((function filter(a, b) {
|
||||
// Prevent infinite loop with circular references with same filter
|
||||
if ((seen.has(a)) && (seen.get(a) === b)) {
|
||||
return a;
|
||||
}
|
||||
seen.set(a, b);
|
||||
// Filter keys and symbols which are present in both actual and expected
|
||||
const filtered = {};
|
||||
const entries = [
|
||||
...Object.getOwnPropertyNames(a),
|
||||
...Object.getOwnPropertySymbols(a),
|
||||
]
|
||||
.filter((key) => key in b)
|
||||
.map((key) => [key, a[key]]);
|
||||
for (const [key, value] of entries) {
|
||||
// On array references, build a filtered array and filter nested objects inside
|
||||
if (Array.isArray(value)) {
|
||||
const subset = b[key];
|
||||
if (Array.isArray(subset)) {
|
||||
filtered[key] = value
|
||||
.slice(0, subset.length)
|
||||
.map((element, index) => {
|
||||
const subsetElement = subset[index];
|
||||
if ((typeof subsetElement === "object") && (subsetElement)) {
|
||||
return filter(element, subsetElement);
|
||||
}
|
||||
return element;
|
||||
});
|
||||
continue;
|
||||
}
|
||||
} // On nested objects references, build a filtered object recursively
|
||||
else if (typeof value === "object") {
|
||||
const subset = b[key];
|
||||
if ((typeof subset === "object") && (subset)) {
|
||||
filtered[key] = filter(value, subset);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
filtered[key] = value;
|
||||
}
|
||||
return filtered;
|
||||
})(actual, expected), expected);
|
||||
}
|
||||
exports.assertObjectMatch = assertObjectMatch;
|
||||
/**
|
||||
* Forcefully throws a failed assertion
|
||||
*/
|
||||
function fail(msg) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
assert(false, `Failed assertion${msg ? `: ${msg}` : "."}`);
|
||||
}
|
||||
exports.fail = fail;
|
||||
/**
|
||||
* Executes a function, expecting it to throw. If it does not, then it
|
||||
* throws. An error class and a string that should be included in the
|
||||
* error message can also be asserted.
|
||||
*/
|
||||
function assertThrows(fn, ErrorClass, msgIncludes = "", msg) {
|
||||
let doesThrow = false;
|
||||
let error = null;
|
||||
try {
|
||||
fn();
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof Error === false) {
|
||||
throw new AssertionError("A non-Error object was thrown.");
|
||||
}
|
||||
if (ErrorClass && !(e instanceof ErrorClass)) {
|
||||
msg =
|
||||
`Expected error to be instance of "${ErrorClass.name}", but was "${e.constructor.name}"${msg ? `: ${msg}` : "."}`;
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
if (msgIncludes &&
|
||||
!(0, colors_js_1.stripColor)(e.message).includes((0, colors_js_1.stripColor)(msgIncludes))) {
|
||||
msg =
|
||||
`Expected error message to include "${msgIncludes}", but got "${e.message}"${msg ? `: ${msg}` : "."}`;
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
doesThrow = true;
|
||||
error = e;
|
||||
}
|
||||
if (!doesThrow) {
|
||||
msg = `Expected function to throw${msg ? `: ${msg}` : "."}`;
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
exports.assertThrows = assertThrows;
|
||||
/**
|
||||
* Executes a function which returns a promise, expecting it to throw or reject.
|
||||
* If it does not, then it throws. An error class and a string that should be
|
||||
* included in the error message can also be asserted.
|
||||
*/
|
||||
async function assertThrowsAsync(fn, ErrorClass, msgIncludes = "", msg) {
|
||||
let doesThrow = false;
|
||||
let error = null;
|
||||
try {
|
||||
await fn();
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof Error === false) {
|
||||
throw new AssertionError("A non-Error object was thrown or rejected.");
|
||||
}
|
||||
if (ErrorClass && !(e instanceof ErrorClass)) {
|
||||
msg =
|
||||
`Expected error to be instance of "${ErrorClass.name}", but got "${e.name}"${msg ? `: ${msg}` : "."}`;
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
if (msgIncludes &&
|
||||
!(0, colors_js_1.stripColor)(e.message).includes((0, colors_js_1.stripColor)(msgIncludes))) {
|
||||
msg =
|
||||
`Expected error message to include "${msgIncludes}", but got "${e.message}"${msg ? `: ${msg}` : "."}`;
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
doesThrow = true;
|
||||
error = e;
|
||||
}
|
||||
if (!doesThrow) {
|
||||
msg = `Expected function to throw${msg ? `: ${msg}` : "."}`;
|
||||
throw new AssertionError(msg);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
exports.assertThrowsAsync = assertThrowsAsync;
|
||||
/** Use this to stub out methods that will throw when invoked. */
|
||||
function unimplemented(msg) {
|
||||
throw new AssertionError(msg || "unimplemented");
|
||||
}
|
||||
exports.unimplemented = unimplemented;
|
||||
/** Use this to assert unreachable code. */
|
||||
function unreachable() {
|
||||
throw new AssertionError("unreachable");
|
||||
}
|
||||
exports.unreachable = unreachable;
|
||||
Reference in New Issue
Block a user