warpo 3.2.0 → 3.2.2
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/assemblyscript/std/README.md +5 -0
- package/assemblyscript/std/assembly/array.ts +542 -0
- package/assemblyscript/std/assembly/arraybuffer.ts +72 -0
- package/assemblyscript/std/assembly/builtins.ts +2312 -0
- package/assemblyscript/std/assembly/compat.ts +2 -0
- package/assemblyscript/std/assembly/dataview.ts +144 -0
- package/assemblyscript/std/assembly/date.ts +383 -0
- package/assemblyscript/std/assembly/diagnostics.ts +11 -0
- package/assemblyscript/std/assembly/error.ts +39 -0
- package/assemblyscript/std/assembly/function.ts +44 -0
- package/assemblyscript/std/assembly/iterator.ts +24 -0
- package/assemblyscript/std/assembly/map.ts +304 -0
- package/assemblyscript/std/assembly/math.ts +3401 -0
- package/assemblyscript/std/assembly/memory.ts +110 -0
- package/assemblyscript/std/assembly/number.ts +388 -0
- package/assemblyscript/std/assembly/object.ts +30 -0
- package/assemblyscript/std/assembly/polyfills.ts +24 -0
- package/assemblyscript/std/assembly/process.ts +7 -0
- package/assemblyscript/std/assembly/promise.ts +172 -0
- package/assemblyscript/std/assembly/reference.ts +48 -0
- package/assemblyscript/std/assembly/regexp.ts +16 -0
- package/assemblyscript/std/assembly/rt/common.ts +79 -0
- package/assemblyscript/std/assembly/rt/index-incremental.ts +4 -0
- package/assemblyscript/std/assembly/rt/index-radical.ts +4 -0
- package/assemblyscript/std/assembly/rt/index.d.ts +37 -0
- package/assemblyscript/std/assembly/rt/itcms.ts +415 -0
- package/assemblyscript/std/assembly/rt/tcms.ts +276 -0
- package/assemblyscript/std/assembly/rt/tlsf.ts +564 -0
- package/assemblyscript/std/assembly/rt.ts +71 -0
- package/assemblyscript/std/assembly/set.ts +261 -0
- package/assemblyscript/std/assembly/shared/feature.ts +69 -0
- package/assemblyscript/std/assembly/shared/host.ts +12 -0
- package/assemblyscript/std/assembly/shared/runtime.ts +9 -0
- package/assemblyscript/std/assembly/shared/target.ts +9 -0
- package/assemblyscript/std/assembly/shared/tsconfig.json +9 -0
- package/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
- package/assemblyscript/std/assembly/staticarray.ts +446 -0
- package/assemblyscript/std/assembly/string.ts +892 -0
- package/assemblyscript/std/assembly/symbol.ts +61 -0
- package/assemblyscript/std/assembly/table.ts +15 -0
- package/assemblyscript/std/assembly/tsconfig.json +4 -0
- package/assemblyscript/std/assembly/tuple.ts +36 -0
- package/assemblyscript/std/assembly/typedarray.ts +2000 -0
- package/assemblyscript/std/assembly/uri.ts +17 -0
- package/assemblyscript/std/assembly/util/bytes.ts +90 -0
- package/assemblyscript/std/assembly/util/casemap.ts +264 -0
- package/assemblyscript/std/assembly/util/error.ts +54 -0
- package/assemblyscript/std/assembly/util/hash.ts +117 -0
- package/assemblyscript/std/assembly/util/math.ts +1922 -0
- package/assemblyscript/std/assembly/util/memory.ts +309 -0
- package/assemblyscript/std/assembly/util/number.ts +884 -0
- package/assemblyscript/std/assembly/util/sort.ts +282 -0
- package/assemblyscript/std/assembly/util/string.ts +1075 -0
- package/assemblyscript/std/assembly/util/uri.ts +251 -0
- package/assemblyscript/std/assembly/vector.ts +3 -0
- package/dist/debug_server/debugSession.d.ts +1 -0
- package/dist/debug_server/debugSession.js +15 -6
- package/dist/debug_server/debugSession.js.map +1 -1
- package/dist/debug_server/debuggerWasmModule.d.ts +3 -0
- package/dist/debug_server/debuggerWasmModule.js +47 -2
- package/dist/debug_server/debuggerWasmModule.js.map +1 -1
- package/dist/debug_server/tests/debugSession.test.js +96 -0
- package/dist/debug_server/tests/debugSession.test.js.map +1 -1
- package/dist/debug_server/tests/testModule/debugger_closure_stepping.d.ts +1 -0
- package/dist/debug_server/tests/testModule/debugger_closure_stepping.js +12 -0
- package/dist/debug_server/tests/testModule/debugger_closure_stepping.js.map +1 -0
- package/dist/debug_server/tests/testModule/debugger_std_array.d.ts +1 -0
- package/dist/debug_server/tests/testModule/debugger_std_array.js +6 -0
- package/dist/debug_server/tests/testModule/debugger_std_array.js.map +1 -0
- package/dist/debug_server/tests/testModule/debugger_string_stepping.d.ts +1 -0
- package/dist/debug_server/tests/testModule/debugger_string_stepping.js +9 -0
- package/dist/debug_server/tests/testModule/debugger_string_stepping.js.map +1 -0
- package/package.json +7 -7
- package/warpo_extension/std/tsconfig.json +4 -0
- package/warpo_extension/std/warpo/ffi.ts +16 -0
- package/warpo_extension/std/warpo/test/comparison.ts +122 -0
- package/warpo_extension/std/warpo/test/env.ts +33 -0
- package/warpo_extension/std/warpo/test/expect.ts +101 -0
- package/warpo_extension/std/warpo/test/formatPrint.ts +99 -0
- package/warpo_extension/std/warpo/test/implement.ts +41 -0
- package/warpo_extension/std/warpo/test/index.d.ts +0 -0
- package/warpo_extension/std/warpo/test/index.ts +39 -0
- package/warpo_extension/std/warpo/test/mockInstrument.ts +26 -0
- package/warpo_extension/std/warpo/utf8/const_str.ts +17 -0
- package/warpo_extension/std/wasi_snapshot_preview1/LICENSE +202 -0
- package/warpo_extension/std/wasi_snapshot_preview1/README.md +1 -0
- package/warpo_extension/std/wasi_snapshot_preview1/bindings/wasi_snapshot_preview1.ts +1731 -0
- package/warpo_extension/std/wasi_snapshot_preview1/wasi_console.ts +96 -0
- package/warpo_extension/std/wasi_snapshot_preview1/wasi_crypto.ts +8 -0
- package/warpo_extension/std/wasi_snapshot_preview1/wasi_date.ts +13 -0
- package/warpo_extension/std/wasi_snapshot_preview1/wasi_internal.ts +119 -0
- package/warpo_extension/std/wasi_snapshot_preview1/wasi_performance.ts +11 -0
- package/warpo_extension/std/wasi_snapshot_preview1/wasi_process.ts +191 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Copyright (C) 2025 wasm-ecosystem
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export function isNull<T>(a: T): bool {
|
|
5
|
+
if (!isReference<T>(a)) {
|
|
6
|
+
ERROR("parameter of isNull should be a reference type");
|
|
7
|
+
}
|
|
8
|
+
if (!isNullable<T>(a)) {
|
|
9
|
+
ERROR("parameter of isNull should be nullable");
|
|
10
|
+
}
|
|
11
|
+
return a == null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function includes<T>(set: T[], value: T): bool {
|
|
15
|
+
for (let i = 0; i < set.length; i++) {
|
|
16
|
+
if (equal<T>(set[i], value)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function equalArrayBuffer<T>(a: T, b: T): bool {
|
|
24
|
+
if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (a.byteLength != b.byteLength) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const aRef = changetype<i32>(a);
|
|
31
|
+
const bRef = changetype<i32>(b);
|
|
32
|
+
const wordSize = a.byteLength / 4;
|
|
33
|
+
const remainder = a.byteLength % 4;
|
|
34
|
+
for (let i = 0; i < wordSize; i++) {
|
|
35
|
+
if (load<u32>(aRef + i * 4) != load<u32>(bRef + i * 4)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < remainder; i++) {
|
|
40
|
+
if (load<u8>(aRef + wordSize * 4 + i) != load<u8>(bRef + wordSize * 4 + i)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function equalArrayLike<T>(a: T, b: T): bool {
|
|
48
|
+
if (!isArrayLike<T>(a) || !isArrayLike<T>(b)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (a.length != b.length) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (let i = 0; i < a.length; i++) {
|
|
55
|
+
if (!equal(a[i], b[i])) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function equalMap<T, U>(a: Map<T, U>, b: Map<T, U>): bool {
|
|
63
|
+
const a_key: T[] = a.keys();
|
|
64
|
+
const b_key: T[] = b.keys();
|
|
65
|
+
if (a_key.length != b_key.length) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
for (let i = 0; i < a_key.length; i++) {
|
|
69
|
+
const k: T = a_key[i];
|
|
70
|
+
if (!includes(b_key, k)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!equal(a.get(k), b.get(k))) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function equalSet<T>(a: Set<T>, b: Set<T>): bool {
|
|
81
|
+
if (a.size != b.size) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const va: T[] = a.values();
|
|
85
|
+
const vb: T[] = b.values();
|
|
86
|
+
for (let i = 0; i < va.length; i++) {
|
|
87
|
+
if (!includes(vb, va[i])) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function equal<T>(a: T, b: T): bool {
|
|
95
|
+
if (!isReference<T>() || isString<T>()) {
|
|
96
|
+
return a == b;
|
|
97
|
+
}
|
|
98
|
+
if (isNullable(a) || isNullable(b)) {
|
|
99
|
+
if (isNull(a) && isNull(b)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if ((isNull(a) && !isNull(b)) || (!isNull(a) && isNull(b))) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const nonnull_a = <NonNullable<T>>a;
|
|
107
|
+
const nonnull_b = <NonNullable<T>>b;
|
|
108
|
+
if (nonnull_a instanceof ArrayBuffer && nonnull_b instanceof ArrayBuffer) {
|
|
109
|
+
return equalArrayBuffer<NonNullable<T>>(nonnull_a, nonnull_b);
|
|
110
|
+
}
|
|
111
|
+
if (isArrayLike<T>(nonnull_a) && isArrayLike<T>(nonnull_b)) {
|
|
112
|
+
return equalArrayLike<NonNullable<T>>(nonnull_a, nonnull_b);
|
|
113
|
+
}
|
|
114
|
+
if (nonnull_a instanceof Map && nonnull_b instanceof Map) {
|
|
115
|
+
return equalMap(nonnull_a, nonnull_b);
|
|
116
|
+
}
|
|
117
|
+
if (nonnull_a instanceof Set && nonnull_b instanceof Set) {
|
|
118
|
+
return equalSet(nonnull_a, nonnull_b);
|
|
119
|
+
}
|
|
120
|
+
ERROR("type is not supported for equality, hint: cannot compare user-defined objects");
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (C) 2025 wasm-ecosystem
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export namespace assertResult {
|
|
5
|
+
// @ts-ignore: decorators
|
|
6
|
+
@external("__unittest_framework_env","addDescription")
|
|
7
|
+
export declare function addDescription(description: string): void;
|
|
8
|
+
|
|
9
|
+
// @ts-ignore: decorators
|
|
10
|
+
@external("__unittest_framework_env","removeDescription")
|
|
11
|
+
export declare function removeDescription(): void;
|
|
12
|
+
|
|
13
|
+
// @ts-ignore: decorators
|
|
14
|
+
@external("__unittest_framework_env","registerTestFunction")
|
|
15
|
+
export declare function registerTestFunction(index: u32): void;
|
|
16
|
+
|
|
17
|
+
// @ts-ignore: decorators
|
|
18
|
+
@external("__unittest_framework_env","registerBeforeEachFunction")
|
|
19
|
+
export declare function registerBeforeEachFunction(index: u32): boolean;
|
|
20
|
+
|
|
21
|
+
// @ts-ignore: decorators
|
|
22
|
+
@external("__unittest_framework_env","registerAfterEachFunction")
|
|
23
|
+
export declare function registerAfterEachFunction(index: u32): boolean;
|
|
24
|
+
|
|
25
|
+
// @ts-ignore: decorators
|
|
26
|
+
@external("__unittest_framework_env","collectCheckResult")
|
|
27
|
+
export declare function collectCheckResult(
|
|
28
|
+
result: bool,
|
|
29
|
+
codeInfoIndex: number,
|
|
30
|
+
actualValue: string,
|
|
31
|
+
expectValue: string
|
|
32
|
+
): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { equal, isNull } from "./comparison";
|
|
2
|
+
import { assertResult } from "./env";
|
|
3
|
+
import { toJson } from "./formatPrint";
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
@inline
|
|
7
|
+
const EXPECT_MAX_INDEX = 2147483647;
|
|
8
|
+
|
|
9
|
+
export class Value<T> {
|
|
10
|
+
reversed: bool = false;
|
|
11
|
+
data: T;
|
|
12
|
+
constructor(_data: T) {
|
|
13
|
+
this.data = _data;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private collect(result: bool, codeInfoIndex: number, actualValue: string, expectValue: string): void {
|
|
17
|
+
assertResult.collectCheckResult(this.reversed ? !result : result, codeInfoIndex, actualValue, expectValue);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get not(): Value<T> {
|
|
21
|
+
this.reversed = !this.reversed;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isNull(codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
26
|
+
this.collect(isNull<T>(this.data), codeInfoIndex, toJson(this.data), "to be null");
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
notNull(codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
30
|
+
this.collect(!isNull<T>(this.data), codeInfoIndex, toJson(this.data), "notNull");
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
equal(checkValue: T, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
35
|
+
this.collect(equal<T>(this.data, checkValue), codeInfoIndex, toJson(this.data), "= " + toJson(checkValue));
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
notEqual(checkValue: T, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
39
|
+
this.collect(!equal<T>(this.data, checkValue), codeInfoIndex, toJson(this.data), " != " + toJson(checkValue));
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
greaterThan(checkValue: T, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
44
|
+
this.collect(this.data > checkValue, codeInfoIndex, toJson(this.data), " > " + toJson(checkValue));
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
greaterThanOrEqual(checkValue: T, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
48
|
+
this.collect(this.data >= checkValue, codeInfoIndex, toJson(this.data), " >= " + toJson(checkValue));
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
lessThan(checkValue: T, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
52
|
+
this.collect(this.data < checkValue, codeInfoIndex, toJson(this.data), " < " + toJson(checkValue));
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
lessThanOrEqual(checkValue: T, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
56
|
+
this.collect(this.data <= checkValue, codeInfoIndex, toJson(this.data), " <= " + toJson(checkValue));
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
closeTo(checkValue: T, delta: number, codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
61
|
+
const data = this.data;
|
|
62
|
+
if (isFloat<T>(checkValue) && isFloat<T>(data)) {
|
|
63
|
+
this.collect(abs(data - checkValue) < delta, codeInfoIndex, toJson(this.data), " closeTo " + toJson(checkValue));
|
|
64
|
+
} else {
|
|
65
|
+
ERROR("closeTo should only be used in f32 | f64");
|
|
66
|
+
}
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
isa<ExpectType>(codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
71
|
+
if (isNullable<T>()) {
|
|
72
|
+
if (this.data == null) {
|
|
73
|
+
this.collect(false, codeInfoIndex, `<<null>>`, `RTID<${idof<ExpectType>()}>`);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
assert(this.data != null, "data should not be null here");
|
|
78
|
+
this.collect(
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
this.data instanceof ExpectType,
|
|
81
|
+
codeInfoIndex,
|
|
82
|
+
// TODO: need extend chain information
|
|
83
|
+
`RTID<${load<u32>(changetype<usize>(this.data) - 8)}>`,
|
|
84
|
+
`RTID<${idof<ExpectType>()}>`
|
|
85
|
+
);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
isExactly<ExpectType>(codeInfoIndex: u32 = EXPECT_MAX_INDEX): Value<T> {
|
|
90
|
+
if (isNullable<T>()) {
|
|
91
|
+
if (this.data == null) {
|
|
92
|
+
this.collect(false, codeInfoIndex, `<<null>>`, `RTID<${idof<ExpectType>()}>`);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
assert(this.data != null, "data should not be null here");
|
|
97
|
+
const rtid = load<u32>(changetype<usize>(this.data) - 8);
|
|
98
|
+
this.collect(rtid == idof<ExpectType>(), codeInfoIndex, `RTID<${rtid}>`, `RTID<${idof<ExpectType>()}>`);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright (C) 2025 wasm-ecosystem
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export function toJson<T>(v: T): string {
|
|
5
|
+
if (isNullable(v) && v == null) {
|
|
6
|
+
return "null";
|
|
7
|
+
}
|
|
8
|
+
if (isBoolean<T>(v)) {
|
|
9
|
+
return v ? "true" : "false";
|
|
10
|
+
}
|
|
11
|
+
if (isInteger<T>(v) || isFloat<T>(v) || isFunction<T>(v)) {
|
|
12
|
+
return v.toString();
|
|
13
|
+
}
|
|
14
|
+
if (isString<T>(v)) {
|
|
15
|
+
const str: string = v.toString();
|
|
16
|
+
const jsonChars: string[] = [];
|
|
17
|
+
for (let i = 0; i < str.length; i++) {
|
|
18
|
+
const charCode = str.charCodeAt(i);
|
|
19
|
+
if (
|
|
20
|
+
(charCode >= 0x20 && charCode <= 0x21) ||
|
|
21
|
+
(charCode >= 0x23 && charCode <= 0x5b) ||
|
|
22
|
+
(charCode >= 0x5d && charCode <= 0xffff)
|
|
23
|
+
) {
|
|
24
|
+
jsonChars.push(str.charAt(i));
|
|
25
|
+
} else {
|
|
26
|
+
switch (charCode) {
|
|
27
|
+
case 0x00:
|
|
28
|
+
jsonChars.push("\\0");
|
|
29
|
+
break;
|
|
30
|
+
case 0x07:
|
|
31
|
+
jsonChars.push("\\a");
|
|
32
|
+
break;
|
|
33
|
+
case 0x08:
|
|
34
|
+
jsonChars.push("\\b");
|
|
35
|
+
break;
|
|
36
|
+
case 0x09:
|
|
37
|
+
jsonChars.push("\\t");
|
|
38
|
+
break;
|
|
39
|
+
case 0x0a:
|
|
40
|
+
jsonChars.push("\\n");
|
|
41
|
+
break;
|
|
42
|
+
case 0x0b:
|
|
43
|
+
jsonChars.push("\\v");
|
|
44
|
+
break;
|
|
45
|
+
case 0x0c:
|
|
46
|
+
jsonChars.push("\\f");
|
|
47
|
+
break;
|
|
48
|
+
case 0x0d:
|
|
49
|
+
jsonChars.push("\\r");
|
|
50
|
+
break;
|
|
51
|
+
case 0x22:
|
|
52
|
+
jsonChars.push('\\"');
|
|
53
|
+
break;
|
|
54
|
+
case 0x5c:
|
|
55
|
+
jsonChars.push("\\\\");
|
|
56
|
+
break;
|
|
57
|
+
default: {
|
|
58
|
+
// unknown control code
|
|
59
|
+
const charCodeStr = charCode.toString();
|
|
60
|
+
jsonChars.push("\\u");
|
|
61
|
+
for (let i = charCodeStr.length; i < 4; i++) {
|
|
62
|
+
jsonChars.push("0");
|
|
63
|
+
}
|
|
64
|
+
jsonChars.push(charCodeStr);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return '"' + jsonChars.join("") + '"';
|
|
70
|
+
}
|
|
71
|
+
if (v instanceof ArrayBuffer) {
|
|
72
|
+
const tmpArray = Uint8Array.wrap(v);
|
|
73
|
+
const tmpStrArray = new Array<string>(tmpArray.length);
|
|
74
|
+
for (let i = 0; i < tmpArray.length; i++) {
|
|
75
|
+
tmpStrArray[i] = tmpArray[i].toString();
|
|
76
|
+
}
|
|
77
|
+
return `[${tmpStrArray.join(", ")}]`;
|
|
78
|
+
}
|
|
79
|
+
if (isArray<T>(v) || isArrayLike<T>(v)) {
|
|
80
|
+
const tempStrArray = new Array<string>(v.length);
|
|
81
|
+
for (let i = 0, k = v.length; i < k; i++) {
|
|
82
|
+
tempStrArray[i] = toJson(v[i]);
|
|
83
|
+
}
|
|
84
|
+
return `[${tempStrArray.join(", ")}]`;
|
|
85
|
+
}
|
|
86
|
+
if (v instanceof Set) {
|
|
87
|
+
return toJson(v.values());
|
|
88
|
+
}
|
|
89
|
+
if (v instanceof Map) {
|
|
90
|
+
const key = v.keys();
|
|
91
|
+
const value = v.values();
|
|
92
|
+
const tempStrArray = new Array<string>();
|
|
93
|
+
for (let i = 0; i < key.length; i++) {
|
|
94
|
+
tempStrArray[i] = toJson(key[i]) + " : " + toJson(value[i]);
|
|
95
|
+
}
|
|
96
|
+
return `{ ${tempStrArray.join(", ")} }`;
|
|
97
|
+
}
|
|
98
|
+
return "[Object " + nameof<T>(v) + "]";
|
|
99
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (C) 2025 wasm-ecosystem
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { assertResult } from "./env";
|
|
5
|
+
import { MockFn, mockFunctionStatus } from "./mockInstrument";
|
|
6
|
+
|
|
7
|
+
export function describeImpl(description: string, testsFunction: () => void): void {
|
|
8
|
+
assertResult.addDescription(description);
|
|
9
|
+
testsFunction();
|
|
10
|
+
assertResult.removeDescription();
|
|
11
|
+
}
|
|
12
|
+
export function testImpl(name: string, testFunction: () => void): void {
|
|
13
|
+
assertResult.addDescription(name);
|
|
14
|
+
assertResult.registerTestFunction(testFunction.index);
|
|
15
|
+
assertResult.removeDescription();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function beforeEachImpl(func: () => void): void {
|
|
19
|
+
const result = assertResult.registerBeforeEachFunction(func.index);
|
|
20
|
+
assert(result, "register setup function failed");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function afterEachImpl(func: () => void): void {
|
|
24
|
+
const result = assertResult.registerAfterEachFunction(func.index);
|
|
25
|
+
assert(result, "register teardown function failed");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function mockImpl<T extends Function>(originalFunction: T, mockFunction: T): MockFn {
|
|
29
|
+
if (!isFunction<T>(originalFunction) || !isFunction<T>(mockFunction)) {
|
|
30
|
+
ERROR("mock parameter must receive a function");
|
|
31
|
+
}
|
|
32
|
+
const mockFn = new MockFn(originalFunction.index, mockFunction.index);
|
|
33
|
+
mockFunctionStatus.setMockFunction(originalFunction.index, mockFunction.index);
|
|
34
|
+
return mockFn;
|
|
35
|
+
}
|
|
36
|
+
export function unmockImpl<T extends Function>(originalFunction: T): void {
|
|
37
|
+
mockFunctionStatus.setMockedFunctionIgnore(originalFunction.index, true);
|
|
38
|
+
}
|
|
39
|
+
export function remockImpl<T extends Function>(originalFunction: T): void {
|
|
40
|
+
mockFunctionStatus.setMockedFunctionIgnore(originalFunction.index, false);
|
|
41
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (C) 2025 wasm-ecosystem
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Value } from "./expect";
|
|
5
|
+
import { afterEachImpl, beforeEachImpl, describeImpl, mockImpl, remockImpl, testImpl, unmockImpl } from "./implement";
|
|
6
|
+
import { MockFn } from "./mockInstrument";
|
|
7
|
+
export { MockFn } from "./mockInstrument";
|
|
8
|
+
|
|
9
|
+
export function describe(description: string, testsFunction: () => void): void {
|
|
10
|
+
describeImpl(description, testsFunction);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function test(name: string, testFunction: () => void): void {
|
|
14
|
+
testImpl(name, testFunction);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function beforeEach(func: () => void): void {
|
|
18
|
+
beforeEachImpl(func);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function afterEach(func: () => void): void {
|
|
22
|
+
afterEachImpl(func);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function mock<T extends Function>(originalFunction: T, mockFunction: T): MockFn {
|
|
26
|
+
return mockImpl<T>(originalFunction, mockFunction);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function unmock<T extends Function>(originalFunction: T): void {
|
|
30
|
+
unmockImpl(originalFunction);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function remock<T extends Function>(originalFunction: T): void {
|
|
34
|
+
remockImpl(originalFunction);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function expect<T>(value: T): Value<T> {
|
|
38
|
+
return new Value<T>(value);
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (C) 2025 wasm-ecosystem
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export namespace mockFunctionStatus {
|
|
5
|
+
// @ts-ignore: decorators
|
|
6
|
+
@external("__unittest_framework_env","setMockFunction")
|
|
7
|
+
export declare function setMockFunction(originalFunctionIndex: u32, mockFunctionIndex: u32): void;
|
|
8
|
+
|
|
9
|
+
// @ts-ignore: decorators
|
|
10
|
+
@external("__unittest_framework_env","getMockedFunctionCalls")
|
|
11
|
+
export declare function getMockedFunctionCalls(originalFunctionIndex: u32, mockFunctionIndex: u32): u32;
|
|
12
|
+
|
|
13
|
+
// @ts-ignore: decorators
|
|
14
|
+
@external("__unittest_framework_env","setMockedFunctionIgnore")
|
|
15
|
+
export declare function setMockedFunctionIgnore(originalFunctionIndex: u32, ignore: bool): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class MockFn {
|
|
19
|
+
get calls(): u32 {
|
|
20
|
+
return mockFunctionStatus.getMockedFunctionCalls(this.originalFunctionIndex, this.mockFunctionIndex);
|
|
21
|
+
}
|
|
22
|
+
constructor(
|
|
23
|
+
public originalFunctionIndex: u32,
|
|
24
|
+
public mockFunctionIndex: u32
|
|
25
|
+
) {}
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
@unmanaged
|
|
3
|
+
export class ConstStr {
|
|
4
|
+
toString(): string {
|
|
5
|
+
return String.UTF8.decodeUnsafe(this.addr, this.size, true);
|
|
6
|
+
}
|
|
7
|
+
get addr(): usize {
|
|
8
|
+
return changetype<usize>(this);
|
|
9
|
+
}
|
|
10
|
+
get size(): u32 {
|
|
11
|
+
return load<u32>(this.addr - 4);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// @ts-ignore: decorator
|
|
16
|
+
@builtin
|
|
17
|
+
export declare function build(x: string): ConstStr;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|