Migrate from Ava test framework to node:test
This commit is contained in:
1 parent
0c9c027a77
commit
ddb240d542
12 files changed
+146
-4572
No files matched your search
Generated
-4434
File diff suppressed because it is too large.
Load diff
+1
-2
@@ -47,7 +47,6 @@
|
|||||||
"@types/seedrandom": "^3.0.8",
|
"@types/seedrandom": "^3.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
||||||
"@typescript-eslint/parser": "^6.14.0",
|
"@typescript-eslint/parser": "^6.14.0",
|
||||||
"ava": "^3.15.0",
|
|
||||||
"codemirror": "^5.65.16",
|
"codemirror": "^5.65.16",
|
||||||
"esbuild": "^0.19.9",
|
"esbuild": "^0.19.9",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.56.0",
|
||||||
@@ -63,7 +62,7 @@
|
|||||||
"node": ">=12.13.0"
|
"node": ">=12.13.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "esbuild --log-level=warning --bundle --platform=node --target=node12 --packages=external --outdir=test test/*.ts && ava --verbose --color && rm test/*.js",
|
"test": "esbuild --log-level=warning --bundle --platform=node --target=node18 --packages=external --outdir=test test/*.ts && node --test test/*.js && rm test/*.js",
|
||||||
"lint": "esbuild build/lint.ts --bundle --platform=node --target=node16 --packages=external | node",
|
"lint": "esbuild build/lint.ts --bundle --platform=node --target=node16 --packages=external | node",
|
||||||
"build": "esbuild build/build.ts --bundle --platform=node --target=node12 --packages=external | node"
|
"build": "esbuild build/build.ts --bundle --platform=node --target=node12 --packages=external | node"
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -1,8 +1,9 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import { randomBytes } from "crypto";
|
import { randomBytes } from "crypto";
|
||||||
import * as auth from "../lib/auth";
|
import * as auth from "../lib/auth";
|
||||||
|
|
||||||
ava("digest", (t) => {
|
void test("digest", () => {
|
||||||
const username = "test";
|
const username = "test";
|
||||||
const password = "test";
|
const password = "test";
|
||||||
const uri = "/";
|
const uri = "/";
|
||||||
@@ -17,8 +18,6 @@ ava("digest", (t) => {
|
|||||||
`Digest realm="${realm}",nonce="${nonce}",qop="auth-int"`,
|
`Digest realm="${realm}",nonce="${nonce}",qop="auth-int"`,
|
||||||
];
|
];
|
||||||
|
|
||||||
t.plan(challenges.length);
|
|
||||||
|
|
||||||
for (const challenge of challenges) {
|
for (const challenge of challenges) {
|
||||||
const wwwAuthHeader = auth.parseWwwAuthenticateHeader(challenge);
|
const wwwAuthHeader = auth.parseWwwAuthenticateHeader(challenge);
|
||||||
const solution = auth.solveDigest(
|
const solution = auth.solveDigest(
|
||||||
@@ -30,7 +29,7 @@ ava("digest", (t) => {
|
|||||||
wwwAuthHeader,
|
wwwAuthHeader,
|
||||||
);
|
);
|
||||||
const authHeader = auth.parseAuthorizationHeader(solution);
|
const authHeader = auth.parseAuthorizationHeader(solution);
|
||||||
t.is(
|
assert.strictEqual(
|
||||||
authHeader["response"],
|
authHeader["response"],
|
||||||
auth.digest(
|
auth.digest(
|
||||||
username,
|
username,
|
||||||
|
|||||||
+14
-15
@@ -1,11 +1,12 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import { EJSON } from "bson";
|
import { EJSON } from "bson";
|
||||||
import { Filter } from "mongodb";
|
import { Filter } from "mongodb";
|
||||||
import { stringify, parse } from "../lib/common/expression/parser";
|
import { stringify, parse } from "../lib/common/expression/parser";
|
||||||
import { convertOldPrecondition } from "../lib/db/util";
|
import { convertOldPrecondition } from "../lib/db/util";
|
||||||
import { toMongoQuery } from "../lib/db/synth";
|
import { toMongoQuery } from "../lib/db/synth";
|
||||||
|
|
||||||
ava("convertOldPrecondition", (t) => {
|
void test("convertOldPrecondition", () => {
|
||||||
const tests = [
|
const tests = [
|
||||||
[{}, "true"],
|
[{}, "true"],
|
||||||
[{ test: "test" }, 'test = "test"'],
|
[{ test: "test" }, 'test = "test"'],
|
||||||
@@ -49,26 +50,24 @@ ava("convertOldPrecondition", (t) => {
|
|||||||
[{ _tags: [] }, "Invalid type"],
|
[{ _tags: [] }, "Invalid type"],
|
||||||
[{ _tags: { $gt: "test" } }, "Invalid tag query"],
|
[{ _tags: { $gt: "test" } }, "Invalid tag query"],
|
||||||
[{ $nor: [] }, "Operator $nor not supported"],
|
[{ $nor: [] }, "Operator $nor not supported"],
|
||||||
];
|
] as [Filter<unknown>, string][];
|
||||||
|
|
||||||
t.plan(tests.length + 2 * shouldFailTests.length);
|
for (const t of tests) {
|
||||||
for (const test of tests) {
|
assert.strictEqual(
|
||||||
t.is(
|
stringify(convertOldPrecondition(t[0] as Record<string, unknown>)),
|
||||||
stringify(convertOldPrecondition(test[0] as Record<string, unknown>)),
|
t[1],
|
||||||
test[1],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const test of shouldFailTests) {
|
for (const t of shouldFailTests) {
|
||||||
const func = (): void => {
|
const func = (): void => {
|
||||||
convertOldPrecondition(test[0] as Record<string, unknown>);
|
convertOldPrecondition(t[0]);
|
||||||
};
|
};
|
||||||
const error = t.throws(func, { instanceOf: Error });
|
assert.throws(func, new Error(t[1]));
|
||||||
t.is(error.message, test[1]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("toMongoQuery", async (t) => {
|
void test("toMongoQuery", async () => {
|
||||||
const queries: [string, Filter<unknown> | false][] = [
|
const queries: [string, Filter<unknown> | false][] = [
|
||||||
["true", {}],
|
["true", {}],
|
||||||
["Tags.tag1 = true", { _tags: { $eq: "tag1" } }],
|
["Tags.tag1 = true", { _tags: { $eq: "tag1" } }],
|
||||||
@@ -150,7 +149,7 @@ ava("toMongoQuery", async (t) => {
|
|||||||
const exp = parse(expStr);
|
const exp = parse(expStr);
|
||||||
let query = toMongoQuery(exp, "devices");
|
let query = toMongoQuery(exp, "devices");
|
||||||
if (query) query = EJSON.serialize(query);
|
if (query) query = EJSON.serialize(query);
|
||||||
t.deepEqual(query, expect);
|
assert.deepStrictEqual(query, expect);
|
||||||
}
|
}
|
||||||
|
|
||||||
const failQueries: [any, string][] = [
|
const failQueries: [any, string][] = [
|
||||||
@@ -162,7 +161,7 @@ ava("toMongoQuery", async (t) => {
|
|||||||
|
|
||||||
for (const [expStr, err] of failQueries) {
|
for (const [expStr, err] of failQueries) {
|
||||||
const exp = parse(expStr);
|
const exp = parse(expStr);
|
||||||
t.throws(() => toMongoQuery(exp, "devices"), {
|
assert.throws(() => toMongoQuery(exp, "devices"), {
|
||||||
message: err,
|
message: err,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -1,28 +1,28 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import Path from "../lib/common/path";
|
import Path from "../lib/common/path";
|
||||||
import * as device from "../lib/device";
|
import * as device from "../lib/device";
|
||||||
import PathSet from "../lib/common/path-set";
|
import PathSet from "../lib/common/path-set";
|
||||||
import VersionedMap from "../lib/versioned-map";
|
import VersionedMap from "../lib/versioned-map";
|
||||||
import { Attributes } from "../lib/types";
|
import { Attributes } from "../lib/types";
|
||||||
|
|
||||||
ava("getAliasDeclarations", (t) => {
|
void test("getAliasDeclarations", () => {
|
||||||
const path = Path.parse("a.[aa:10,bb.[aaa:100].cc:1].b");
|
const path = Path.parse("a.[aa:10,bb.[aaa:100].cc:1].b");
|
||||||
const decs = device.getAliasDeclarations(path, 99);
|
const decs = device.getAliasDeclarations(path, 99);
|
||||||
|
|
||||||
const expected = ["a.*.b", "a.*.aa", "a.*.bb.*.cc", "a.*.bb.*.aaa"];
|
const expected = ["a.*.b", "a.*.aa", "a.*.bb.*.cc", "a.*.bb.*.aaa"];
|
||||||
|
|
||||||
t.plan(24);
|
|
||||||
for (const [i, d] of decs.entries()) {
|
for (const [i, d] of decs.entries()) {
|
||||||
t.is(d.path.toString(), expected[i]);
|
assert.strictEqual(d.path.toString(), expected[i]);
|
||||||
t.is(d.pathGet, 99);
|
assert.strictEqual(d.pathGet, 99);
|
||||||
t.is(d.pathSet, null);
|
assert.strictEqual(d.pathSet, null);
|
||||||
t.deepEqual(d.attrGet, i ? { value: 99 } : null);
|
assert.deepStrictEqual(d.attrGet, i ? { value: 99 } : null);
|
||||||
t.is(d.attrSet, null);
|
assert.strictEqual(d.attrSet, null);
|
||||||
t.is(d.defer, true);
|
assert.strictEqual(d.defer, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("unpack", (t) => {
|
void test("unpack", () => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const deviceData = {
|
const deviceData = {
|
||||||
paths: new PathSet(),
|
paths: new PathSet(),
|
||||||
@@ -87,11 +87,11 @@ ava("unpack", (t) => {
|
|||||||
deviceData,
|
deviceData,
|
||||||
Path.parse("a.[b:b,c:c].a.[b:b1,c:c1].a"),
|
Path.parse("a.[b:b,c:c].a.[b:b1,c:c1].a"),
|
||||||
);
|
);
|
||||||
t.is(unpacked.length, 2);
|
assert.strictEqual(unpacked.length, 2);
|
||||||
t.is(unpacked[0].toString(), "a.1.a.1.a");
|
assert.strictEqual(unpacked[0].toString(), "a.1.a.1.a");
|
||||||
t.is(unpacked[1].toString(), "a.2.a.1.a");
|
assert.strictEqual(unpacked[1].toString(), "a.2.a.1.a");
|
||||||
|
|
||||||
unpacked = device.unpack(deviceData, Path.parse("a.*.a.[b:c1,c:b1].a"));
|
unpacked = device.unpack(deviceData, Path.parse("a.*.a.[b:c1,c:b1].a"));
|
||||||
t.is(unpacked.length, 1);
|
assert.strictEqual(unpacked.length, 1);
|
||||||
t.is(unpacked[0].toString(), "a.2.a.2.a");
|
assert.strictEqual(unpacked[0].toString(), "a.2.a.2.a");
|
||||||
});
|
});
|
||||||
+18
-17
@@ -1,34 +1,35 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import Path from "../lib/common/path";
|
import Path from "../lib/common/path";
|
||||||
import PathSet from "../lib/common/path-set";
|
import PathSet from "../lib/common/path-set";
|
||||||
|
|
||||||
ava("depth", (t) => {
|
void test("depth", () => {
|
||||||
const pathSet = new PathSet();
|
const pathSet = new PathSet();
|
||||||
t.is(pathSet.depth, 0);
|
assert.strictEqual(pathSet.depth, 0);
|
||||||
pathSet.add(Path.parse(""));
|
pathSet.add(Path.parse(""));
|
||||||
t.is(pathSet.depth, 1);
|
assert.strictEqual(pathSet.depth, 1);
|
||||||
pathSet.add(Path.parse("a"));
|
pathSet.add(Path.parse("a"));
|
||||||
t.is(pathSet.depth, 2);
|
assert.strictEqual(pathSet.depth, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("add", (t) => {
|
void test("add", () => {
|
||||||
const pathSet = new PathSet();
|
const pathSet = new PathSet();
|
||||||
pathSet.add(Path.parse("a"));
|
pathSet.add(Path.parse("a"));
|
||||||
pathSet.add(Path.parse("a"));
|
pathSet.add(Path.parse("a"));
|
||||||
t.is(pathSet.find(Path.parse("a"), true, true, 99).length, 1);
|
assert.strictEqual(pathSet.find(Path.parse("a"), true, true, 99).length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("get", (t) => {
|
void test("get", () => {
|
||||||
const pathSet = new PathSet();
|
const pathSet = new PathSet();
|
||||||
pathSet.add(Path.parse("a.*"));
|
pathSet.add(Path.parse("a.*"));
|
||||||
pathSet.add(Path.parse("a.a"));
|
pathSet.add(Path.parse("a.a"));
|
||||||
pathSet.add(Path.parse("*.*"));
|
pathSet.add(Path.parse("*.*"));
|
||||||
|
|
||||||
t.is(pathSet.get(Path.parse("a.*")).toString(), "a.*");
|
assert.strictEqual(pathSet.get(Path.parse("a.*")).toString(), "a.*");
|
||||||
t.is(pathSet.get(Path.parse("*.a")), null);
|
assert.strictEqual(pathSet.get(Path.parse("*.a")), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("find", (t) => {
|
void test("find", () => {
|
||||||
const pathSet = new PathSet();
|
const pathSet = new PathSet();
|
||||||
pathSet.add(Path.parse("a"));
|
pathSet.add(Path.parse("a"));
|
||||||
pathSet.add(Path.parse("a.*"));
|
pathSet.add(Path.parse("a.*"));
|
||||||
@@ -36,32 +37,32 @@ ava("find", (t) => {
|
|||||||
pathSet.add(Path.parse("*.a"));
|
pathSet.add(Path.parse("*.a"));
|
||||||
pathSet.add(Path.parse("*.*"));
|
pathSet.add(Path.parse("*.*"));
|
||||||
|
|
||||||
t.deepEqual(
|
assert.deepStrictEqual(
|
||||||
pathSet.find(Path.parse(""), true, true, 1).map((p) => p.toString()),
|
pathSet.find(Path.parse(""), true, true, 1).map((p) => p.toString()),
|
||||||
["a"],
|
["a"],
|
||||||
);
|
);
|
||||||
|
|
||||||
t.deepEqual(
|
assert.deepStrictEqual(
|
||||||
pathSet.find(Path.parse(""), false, false, 2).map((p) => p.toString()),
|
pathSet.find(Path.parse(""), false, false, 2).map((p) => p.toString()),
|
||||||
["a", "a.*", "a.a", "*.a", "*.*"],
|
["a", "a.*", "a.a", "*.a", "*.*"],
|
||||||
);
|
);
|
||||||
|
|
||||||
t.deepEqual(
|
assert.deepStrictEqual(
|
||||||
pathSet.find(Path.parse("a.*"), false, false).map((p) => p.toString()),
|
pathSet.find(Path.parse("a.*"), false, false).map((p) => p.toString()),
|
||||||
["a.*"],
|
["a.*"],
|
||||||
);
|
);
|
||||||
|
|
||||||
t.deepEqual(
|
assert.deepStrictEqual(
|
||||||
pathSet.find(Path.parse("a.*"), false, true).map((p) => p.toString()),
|
pathSet.find(Path.parse("a.*"), false, true).map((p) => p.toString()),
|
||||||
["a.*", "a.a"],
|
["a.*", "a.a"],
|
||||||
);
|
);
|
||||||
|
|
||||||
t.deepEqual(
|
assert.deepStrictEqual(
|
||||||
pathSet.find(Path.parse("a.*"), true, false).map((p) => p.toString()),
|
pathSet.find(Path.parse("a.*"), true, false).map((p) => p.toString()),
|
||||||
["a.*", "*.*"],
|
["a.*", "*.*"],
|
||||||
);
|
);
|
||||||
|
|
||||||
t.deepEqual(
|
assert.deepStrictEqual(
|
||||||
pathSet.find(Path.parse("a.*"), true, true).map((p) => p.toString()),
|
pathSet.find(Path.parse("a.*"), true, true).map((p) => p.toString()),
|
||||||
["a.*", "a.a", "*.a", "*.*"],
|
["a.*", "a.a", "*.a", "*.*"],
|
||||||
);
|
);
|
||||||
|
|||||||
+29
-28
@@ -1,44 +1,45 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import Path from "../lib/common/path";
|
import Path from "../lib/common/path";
|
||||||
|
|
||||||
ava("parse", (t) => {
|
void test("parse", () => {
|
||||||
t.throws(() => Path.parse("."));
|
assert.throws(() => Path.parse("."));
|
||||||
t.throws(() => Path.parse("a "));
|
assert.throws(() => Path.parse("a "));
|
||||||
t.throws(() => Path.parse(".a"));
|
assert.throws(() => Path.parse(".a"));
|
||||||
t.throws(() => Path.parse("a."));
|
assert.throws(() => Path.parse("a."));
|
||||||
t.throws(() => Path.parse("a..b"));
|
assert.throws(() => Path.parse("a..b"));
|
||||||
t.throws(() => Path.parse("b*"));
|
assert.throws(() => Path.parse("b*"));
|
||||||
t.throws(() => Path.parse("*b"));
|
assert.throws(() => Path.parse("*b"));
|
||||||
t.throws(() => Path.parse("a.b c.d"));
|
assert.throws(() => Path.parse("a.b c.d"));
|
||||||
t.throws(() => Path.parse("a["));
|
assert.throws(() => Path.parse("a["));
|
||||||
t.throws(() => Path.parse("a[b"));
|
assert.throws(() => Path.parse("a[b"));
|
||||||
t.throws(() => Path.parse("a[b:"));
|
assert.throws(() => Path.parse("a[b:"));
|
||||||
t.throws(() => Path.parse('a[b:"waef]'));
|
assert.throws(() => Path.parse('a[b:"waef]'));
|
||||||
t.notThrows(() => Path.parse("[]"));
|
assert.doesNotThrow(() => Path.parse("[]"));
|
||||||
t.notThrows(() => Path.parse("[a:]"));
|
assert.doesNotThrow(() => Path.parse("[a:]"));
|
||||||
t.notThrows(() => Path.parse("*"));
|
assert.doesNotThrow(() => Path.parse("*"));
|
||||||
t.notThrows(() => Path.parse(""));
|
assert.doesNotThrow(() => Path.parse(""));
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("toString", (t) => {
|
void test("toString", () => {
|
||||||
const path1 = Path.parse('abc.[ abc : 123 , 123 : abc , 123: " abc "].123');
|
const path1 = Path.parse('abc.[ abc : 123 , 123 : abc , 123: " abc "].123');
|
||||||
const path2 = Path.parse('abc.[123: " abc ",abc:123,123:abc].123');
|
const path2 = Path.parse('abc.[123: " abc ",abc:123,123:abc].123');
|
||||||
t.is(path1.toString(), path2.toString());
|
assert.strictEqual(path1.toString(), path2.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("slice", (t) => {
|
void test("slice", () => {
|
||||||
const path = Path.parse("a.*.b.[x:y].c");
|
const path = Path.parse("a.*.b.[x:y].c");
|
||||||
const sliced = path.slice(1, -1);
|
const sliced = path.slice(1, -1);
|
||||||
t.is(sliced.toString(), '*.b.[x:"y"]');
|
assert.strictEqual(sliced.toString(), '*.b.[x:"y"]');
|
||||||
t.is(sliced.alias, 0b100);
|
assert.strictEqual(sliced.alias, 0b100);
|
||||||
t.is(sliced.wildcard, 0b1);
|
assert.strictEqual(sliced.wildcard, 0b1);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("concat", (t) => {
|
void test("concat", () => {
|
||||||
const path1 = Path.parse("a");
|
const path1 = Path.parse("a");
|
||||||
const path2 = Path.parse("*.[a:b]");
|
const path2 = Path.parse("*.[a:b]");
|
||||||
const concat = path1.concat(path2);
|
const concat = path1.concat(path2);
|
||||||
t.is(concat.toString(), 'a.*.[a:"b"]');
|
assert.strictEqual(concat.toString(), 'a.*.[a:"b"]');
|
||||||
t.is(concat.alias, 0b100);
|
assert.strictEqual(concat.alias, 0b100);
|
||||||
t.is(concat.wildcard, 0b10);
|
assert.strictEqual(concat.wildcard, 0b10);
|
||||||
});
|
});
|
||||||
+6
-5
@@ -1,7 +1,8 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import { parsePing } from "../lib/ping";
|
import { parsePing } from "../lib/ping";
|
||||||
|
|
||||||
ava("linux Case-1", (t) => {
|
void test("linux Case-1", () => {
|
||||||
const platform = "linux";
|
const platform = "linux";
|
||||||
const stdout =
|
const stdout =
|
||||||
"PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data\n64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=6.66 ms\n64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=6.50 ms\n64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=6.38 ms\n\n--- 8.8.8.8 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 402ms\nrtt min/avg/max/mdev = 6.381/6.511/6.656/0.112 ms";
|
"PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data\n64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=6.66 ms\n64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=6.50 ms\n64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=6.38 ms\n\n--- 8.8.8.8 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 402ms\nrtt min/avg/max/mdev = 6.381/6.511/6.656/0.112 ms";
|
||||||
@@ -15,10 +16,10 @@ ava("linux Case-1", (t) => {
|
|||||||
mdev: 0.112,
|
mdev: 0.112,
|
||||||
};
|
};
|
||||||
const parsed = parsePing(platform, stdout);
|
const parsed = parsePing(platform, stdout);
|
||||||
t.deepEqual(parsedResult, parsed);
|
assert.deepStrictEqual(parsedResult, parsed);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("linux Case-2", (t) => {
|
void test("linux Case-2", () => {
|
||||||
const platform = "linux";
|
const platform = "linux";
|
||||||
const stdout =
|
const stdout =
|
||||||
"PING 10.251.9.108 (10.251.9.108): 56 data bytes\n64 bytes from 10.251.9.108: icmp_seq=0 ttl=57 time=36.758 ms\n64 bytes from 10.251.9.108: icmp_seq=1 ttl=57 time=69.094 ms\n64 bytes from 10.251.9.108: icmp_seq=2 ttl=57 time=28.868 ms\n--- 10.251.9.108 ping statistics ---3 packets transmitted, 3 packets received, 0% packet loss\nround-trip min/avg/max/stddev = 28.868/44.907/69.094/17.404 ms";
|
"PING 10.251.9.108 (10.251.9.108): 56 data bytes\n64 bytes from 10.251.9.108: icmp_seq=0 ttl=57 time=36.758 ms\n64 bytes from 10.251.9.108: icmp_seq=1 ttl=57 time=69.094 ms\n64 bytes from 10.251.9.108: icmp_seq=2 ttl=57 time=28.868 ms\n--- 10.251.9.108 ping statistics ---3 packets transmitted, 3 packets received, 0% packet loss\nround-trip min/avg/max/stddev = 28.868/44.907/69.094/17.404 ms";
|
||||||
@@ -32,5 +33,5 @@ ava("linux Case-2", (t) => {
|
|||||||
mdev: 17.404,
|
mdev: 17.404,
|
||||||
};
|
};
|
||||||
const parsed = parsePing(platform, stdout);
|
const parsed = parsePing(platform, stdout);
|
||||||
t.deepEqual(parsedResult, parsed);
|
assert.deepStrictEqual(parsedResult, parsed);
|
||||||
});
|
});
|
||||||
+34
-35
@@ -1,38 +1,37 @@
|
|||||||
import ava, { TestInterface } from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import { minimize, unionDiff } from "../lib/common/expression/synth";
|
import { minimize, unionDiff } from "../lib/common/expression/synth";
|
||||||
import { parse, stringify } from "../lib/common/expression/parser";
|
import { parse, stringify } from "../lib/common/expression/parser";
|
||||||
import initSqlJs from "sql.js/dist/sql-asm.js";
|
import initSqlJs from "sql.js/dist/sql-asm.js";
|
||||||
|
|
||||||
const test = ava as TestInterface<{
|
|
||||||
query: (filter: string) => Promise<Set<number>>;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
const STRING_VALUES = [null, "", "a", "ab", "ab10", "ab-10"];
|
const STRING_VALUES = [null, "", "a", "ab", "ab10", "ab-10"];
|
||||||
const DECIMAL_VALUES = [null, 0, -10, 10];
|
const DECIMAL_VALUES = [null, 0, -10, 10];
|
||||||
|
|
||||||
test.before(async (t) => {
|
let db;
|
||||||
const sql = await initSqlJs();
|
|
||||||
const db = new sql.Database();
|
|
||||||
|
|
||||||
t.context.query = async (filter: string): Promise<Set<number>> => {
|
async function query(filter: string): Promise<Set<number>> {
|
||||||
const res = db.exec(`SELECT id FROM test WHERE ${filter}`);
|
if (!db) {
|
||||||
if (!res.length) return new Set();
|
const sql = await initSqlJs();
|
||||||
return new Set(res[0].values.flat());
|
db = new sql.Database();
|
||||||
};
|
|
||||||
|
|
||||||
db.run(
|
db.run(
|
||||||
"CREATE TABLE test (id INTEGER PRIMARY KEY, string STRING, decimal DECIMAL(4,2))",
|
"CREATE TABLE test (id INTEGER PRIMARY KEY, string STRING, decimal DECIMAL(4,2))",
|
||||||
);
|
);
|
||||||
|
|
||||||
const stmt = db.prepare("INSERT INTO test (string, decimal) VALUES (?, ?)");
|
const stmt = db.prepare("INSERT INTO test (string, decimal) VALUES (?, ?)");
|
||||||
const count = STRING_VALUES.length * DECIMAL_VALUES.length;
|
const count = STRING_VALUES.length * DECIMAL_VALUES.length;
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count; ++i) {
|
||||||
const str = i % STRING_VALUES.length;
|
const str = i % STRING_VALUES.length;
|
||||||
const dec = Math.trunc(i / STRING_VALUES.length) % DECIMAL_VALUES.length;
|
const dec = Math.trunc(i / STRING_VALUES.length) % DECIMAL_VALUES.length;
|
||||||
stmt.run([STRING_VALUES[str], DECIMAL_VALUES[dec]]);
|
stmt.run([STRING_VALUES[str], DECIMAL_VALUES[dec]]);
|
||||||
|
}
|
||||||
|
stmt.free();
|
||||||
}
|
}
|
||||||
stmt.free();
|
|
||||||
});
|
const res = db.exec(`SELECT id FROM test WHERE ${filter}`);
|
||||||
|
if (!res.length) return new Set();
|
||||||
|
return new Set(res[0].values.flat());
|
||||||
|
}
|
||||||
|
|
||||||
function setsEqual(set1: Set<number>, set2: Set<number>): boolean {
|
function setsEqual(set1: Set<number>, set2: Set<number>): boolean {
|
||||||
if (set1.size !== set2.size) return false;
|
if (set1.size !== set2.size) return false;
|
||||||
@@ -56,7 +55,7 @@ function getPermutations(...arrs: any[][]): any[][] {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
test("minimize", async (t) => {
|
void test("minimize", async () => {
|
||||||
const cases: string[] = [];
|
const cases: string[] = [];
|
||||||
|
|
||||||
cases.push("null");
|
cases.push("null");
|
||||||
@@ -86,14 +85,14 @@ test("minimize", async (t) => {
|
|||||||
cases.push(`string > "${s1}" AND string < '${s2}'`);
|
cases.push(`string > "${s1}" AND string < '${s2}'`);
|
||||||
|
|
||||||
for (const c of cases) {
|
for (const c of cases) {
|
||||||
const res1 = await t.context.query(c);
|
const res1 = await query(c);
|
||||||
const min = stringify(minimize(parse(c), true));
|
const min = stringify(minimize(parse(c), true));
|
||||||
const res2 = await t.context.query(min);
|
const res2 = await query(min);
|
||||||
t.true(setsEqual(res1, res2));
|
assert.strictEqual(setsEqual(res1, res2), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("unionDiff", async (t) => {
|
void test("unionDiff", async () => {
|
||||||
const cases = [
|
const cases = [
|
||||||
"true",
|
"true",
|
||||||
"decimal > 0",
|
"decimal > 0",
|
||||||
@@ -103,16 +102,16 @@ test("unionDiff", async (t) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (const [c1, c2] of getPermutations(cases, cases)) {
|
for (const [c1, c2] of getPermutations(cases, cases)) {
|
||||||
const res1 = await t.context.query(c1);
|
const res1 = await query(c1);
|
||||||
const res2 = await t.context.query(c2);
|
const res2 = await query(c2);
|
||||||
const [union, diff] = unionDiff(parse(c1), parse(c2));
|
const [union, diff] = unionDiff(parse(c1), parse(c2));
|
||||||
const res3 = await t.context.query(stringify(union));
|
const res3 = await query(stringify(union));
|
||||||
const res4 = await t.context.query(stringify(diff));
|
const res4 = await query(stringify(diff));
|
||||||
|
|
||||||
const unionSet = new Set([...res1, ...res2]);
|
const unionSet = new Set([...res1, ...res2]);
|
||||||
const diffSet = new Set(Array.from(res2).filter((r) => !res1.has(r)));
|
const diffSet = new Set(Array.from(res2).filter((r) => !res1.has(r)));
|
||||||
|
|
||||||
t.true(setsEqual(res3, unionSet));
|
assert.strictEqual(setsEqual(res3, unionSet), true);
|
||||||
t.true(setsEqual(res4, diffSet));
|
assert.strictEqual(setsEqual(res4, diffSet), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
+10
-6
@@ -1,7 +1,8 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import * as common from "../lib/util";
|
import * as common from "../lib/util";
|
||||||
|
|
||||||
ava("generateDeviceId", (t) => {
|
void test("generateDeviceId", () => {
|
||||||
const space = [" ", "%20"];
|
const space = [" ", "%20"];
|
||||||
const special = [";", "%3B"];
|
const special = [";", "%3B"];
|
||||||
const cases = [
|
const cases = [
|
||||||
@@ -28,13 +29,16 @@ ava("generateDeviceId", (t) => {
|
|||||||
`TestOUIWith${space[1]}_${special[1]}2912-TestSerialNumberWith${space[1]}_${special[1]}2912`,
|
`TestOUIWith${space[1]}_${special[1]}2912-TestSerialNumberWith${space[1]}_${special[1]}2912`,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
t.plan(cases.length);
|
|
||||||
for (const c of cases)
|
for (const c of cases)
|
||||||
t.is(common.generateDeviceId(c[0] as Record<string, string>), c[1]);
|
assert.strictEqual(
|
||||||
|
common.generateDeviceId(c[0] as Record<string, string>),
|
||||||
|
c[1],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("escapeRegExp", (t) => {
|
void test("escapeRegExp", () => {
|
||||||
t.is(
|
assert.strictEqual(
|
||||||
common.escapeRegExp("\\ ^ $ * + ? . ( ) | { } [ ]"),
|
common.escapeRegExp("\\ ^ $ * + ? . ( ) | { } [ ]"),
|
||||||
"\\\\ \\^ \\$ \\* \\+ \\? \\. \\( \\) \\| \\{ \\} \\[ \\]",
|
"\\\\ \\^ \\$ \\* \\+ \\? \\. \\( \\) \\| \\{ \\} \\[ \\]",
|
||||||
);
|
);
|
||||||
|
|||||||
+8
-7
@@ -1,16 +1,17 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import {
|
import {
|
||||||
parseXmlDeclaration,
|
parseXmlDeclaration,
|
||||||
decodeEntities,
|
decodeEntities,
|
||||||
parseXml,
|
parseXml,
|
||||||
} from "../lib/xml-parser";
|
} from "../lib/xml-parser";
|
||||||
|
|
||||||
ava("parseXmlDeclaration", (t) => {
|
void test("parseXmlDeclaration", () => {
|
||||||
const buf = Buffer.from(
|
const buf = Buffer.from(
|
||||||
'<?xml version="1.0" encoding="UTF-8"?>\n<soap-env:Envelope />',
|
'<?xml version="1.0" encoding="UTF-8"?>\n<soap-env:Envelope />',
|
||||||
);
|
);
|
||||||
const attrs = parseXmlDeclaration(buf);
|
const attrs = parseXmlDeclaration(buf);
|
||||||
t.deepEqual(attrs, [
|
assert.deepStrictEqual(attrs, [
|
||||||
{
|
{
|
||||||
name: "version",
|
name: "version",
|
||||||
namespace: "",
|
namespace: "",
|
||||||
@@ -26,18 +27,18 @@ ava("parseXmlDeclaration", (t) => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("decodeEntities", (t) => {
|
void test("decodeEntities", () => {
|
||||||
t.is(
|
assert.strictEqual(
|
||||||
decodeEntities("&&<>"'>§��;"),
|
decodeEntities("&&<>"'>§��;"),
|
||||||
"&&<>\"'>§𠮷;",
|
"&&<>\"'>§𠮷;",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
ava("parse", (t) => {
|
void test("parse", () => {
|
||||||
const xml =
|
const xml =
|
||||||
'<?xml version="1.0"?>\n<a-b:c><d f="1<g>"/><!-- comment --><h >i</h></a-b:c>';
|
'<?xml version="1.0"?>\n<a-b:c><d f="1<g>"/><!-- comment --><h >i</h></a-b:c>';
|
||||||
const parsed = parseXml(xml);
|
const parsed = parseXml(xml);
|
||||||
t.deepEqual(parsed, {
|
assert.deepStrictEqual(parsed, {
|
||||||
name: "root",
|
name: "root",
|
||||||
namespace: "",
|
namespace: "",
|
||||||
localName: "root",
|
localName: "root",
|
||||||
|
|||||||
+7
-3
@@ -1,14 +1,18 @@
|
|||||||
import ava from "ava";
|
import test from "node:test";
|
||||||
|
import assert from "node:assert";
|
||||||
import * as yaml from "yaml";
|
import * as yaml from "yaml";
|
||||||
import { stringify } from "../lib/common/yaml";
|
import { stringify } from "../lib/common/yaml";
|
||||||
|
|
||||||
import testCases from "./yaml-tests.json";
|
import testCases from "./yaml-tests.json";
|
||||||
|
|
||||||
ava("stringify", (t) => {
|
void test("stringify", () => {
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
let str = stringify(testCase);
|
let str = stringify(testCase);
|
||||||
if (str.startsWith(">2")) str = ">3" + str.slice(2);
|
if (str.startsWith(">2")) str = ">3" + str.slice(2);
|
||||||
if (str.startsWith("|2")) str = "|3" + str.slice(2);
|
if (str.startsWith("|2")) str = "|3" + str.slice(2);
|
||||||
t.deepEqual(yaml.parse(yaml.stringify(testCase)), yaml.parse(str));
|
assert.deepStrictEqual(
|
||||||
|
yaml.parse(yaml.stringify(testCase)),
|
||||||
|
yaml.parse(str),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user