xbintsc 0.3.14 → 0.3.16

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.
Files changed (201) hide show
  1. package/README.md +22 -22
  2. package/README.zh-CN.md +20 -19
  3. package/bin/xbintsc.js +1 -2
  4. package/dist/src/cli/main.js +8 -5
  5. package/dist/src/cli/main.js.map +1 -1
  6. package/dist/src/codegen/generator/state.js +8 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.d.ts +5 -6
  9. package/dist/src/codegen/generator/tables.js +13 -6
  10. package/dist/src/codegen/generator/tables.js.map +1 -1
  11. package/dist/src/driver/bundler/graph.d.ts +8 -0
  12. package/dist/src/driver/bundler/graph.js +85 -0
  13. package/dist/src/driver/bundler/graph.js.map +1 -0
  14. package/dist/src/driver/bundler/merge.d.ts +11 -0
  15. package/dist/src/driver/bundler/merge.js +288 -0
  16. package/dist/src/driver/bundler/merge.js.map +1 -0
  17. package/dist/src/driver/bundler/resolve.d.ts +12 -0
  18. package/dist/src/driver/bundler/resolve.js +246 -0
  19. package/dist/src/driver/bundler/resolve.js.map +1 -0
  20. package/dist/src/driver/bundler/symbols.d.ts +15 -0
  21. package/dist/src/driver/bundler/symbols.js +51 -0
  22. package/dist/src/driver/bundler/symbols.js.map +1 -0
  23. package/dist/src/driver/bundler/types.d.ts +36 -0
  24. package/dist/src/driver/bundler/types.js +5 -0
  25. package/dist/src/driver/bundler/types.js.map +1 -0
  26. package/dist/src/driver/index.d.ts +1 -2
  27. package/dist/src/driver/index.js +1 -2
  28. package/dist/src/driver/index.js.map +1 -1
  29. package/dist/src/driver/modules.d.ts +9 -16
  30. package/dist/src/driver/modules.js +8 -644
  31. package/dist/src/driver/modules.js.map +1 -1
  32. package/dist/src/driver/paths.d.ts +0 -9
  33. package/dist/src/driver/paths.js +0 -31
  34. package/dist/src/driver/paths.js.map +1 -1
  35. package/dist/src/driver/toolchain-provider.d.ts +10 -10
  36. package/dist/src/driver/toolchain-provider.js +9 -38
  37. package/dist/src/driver/toolchain-provider.js.map +1 -1
  38. package/dist/src/driver/toolchain.js +8 -2
  39. package/dist/src/driver/toolchain.js.map +1 -1
  40. package/dist/src/extensions/catalog.js +2 -1
  41. package/dist/src/extensions/catalog.js.map +1 -1
  42. package/dist/src/extensions/gui/index.d.ts +24 -0
  43. package/dist/src/extensions/gui/index.js +101 -0
  44. package/dist/src/extensions/gui/index.js.map +1 -0
  45. package/dist/src/extensions/native.d.ts +2 -3
  46. package/dist/src/extensions/native.js +2 -3
  47. package/dist/src/extensions/native.js.map +1 -1
  48. package/dist/tests/driver/paths.test.js +1 -9
  49. package/dist/tests/driver/paths.test.js.map +1 -1
  50. package/dist/tests/driver/toolchain-provider.test.js +12 -79
  51. package/dist/tests/driver/toolchain-provider.test.js.map +1 -1
  52. package/dist/tests/e2e/compile-basics.test.d.ts +4 -0
  53. package/dist/tests/e2e/compile-basics.test.js +134 -0
  54. package/dist/tests/e2e/compile-basics.test.js.map +1 -0
  55. package/dist/tests/e2e/compile-builtins.test.d.ts +4 -0
  56. package/dist/tests/e2e/compile-builtins.test.js +191 -0
  57. package/dist/tests/e2e/compile-builtins.test.js.map +1 -0
  58. package/dist/tests/e2e/compile-control-flow.test.d.ts +4 -0
  59. package/dist/tests/e2e/compile-control-flow.test.js +190 -0
  60. package/dist/tests/e2e/compile-control-flow.test.js.map +1 -0
  61. package/dist/tests/e2e/compile-modules.test.d.ts +4 -0
  62. package/dist/tests/e2e/compile-modules.test.js +48 -0
  63. package/dist/tests/e2e/compile-modules.test.js.map +1 -0
  64. package/dist/tests/e2e/compile-objects-classes.test.d.ts +4 -0
  65. package/dist/tests/e2e/compile-objects-classes.test.js +362 -0
  66. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -0
  67. package/dist/tests/e2e/differential-helpers.d.ts +12 -0
  68. package/dist/tests/e2e/differential-helpers.js +16 -0
  69. package/dist/tests/e2e/differential-helpers.js.map +1 -0
  70. package/dist/tests/e2e/differential-language.test.d.ts +4 -0
  71. package/dist/tests/e2e/{differential.test.js → differential-language.test.js} +5 -287
  72. package/dist/tests/e2e/differential-language.test.js.map +1 -0
  73. package/dist/tests/e2e/differential-symbols.test.d.ts +4 -0
  74. package/dist/tests/e2e/differential-symbols.test.js +92 -0
  75. package/dist/tests/e2e/differential-symbols.test.js.map +1 -0
  76. package/dist/tests/e2e/differential-values.test.d.ts +4 -0
  77. package/dist/tests/e2e/differential-values.test.js +197 -0
  78. package/dist/tests/e2e/differential-values.test.js.map +1 -0
  79. package/dist/tests/e2e/gui.test.d.ts +12 -0
  80. package/dist/tests/e2e/gui.test.js +493 -0
  81. package/dist/tests/e2e/gui.test.js.map +1 -0
  82. package/dist/tests/e2e/native-extensions.test.d.ts +4 -5
  83. package/dist/tests/e2e/native-extensions.test.js +6 -7
  84. package/dist/tests/e2e/native-extensions.test.js.map +1 -1
  85. package/dist/tests/e2e/runtime-coverage-buffer.test.d.ts +4 -0
  86. package/dist/tests/e2e/runtime-coverage-buffer.test.js +97 -0
  87. package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -0
  88. package/dist/tests/e2e/runtime-coverage-globals.test.d.ts +4 -0
  89. package/dist/tests/e2e/runtime-coverage-globals.test.js +149 -0
  90. package/dist/tests/e2e/runtime-coverage-globals.test.js.map +1 -0
  91. package/dist/tests/e2e/runtime-coverage-node-modules.test.d.ts +4 -0
  92. package/dist/tests/e2e/runtime-coverage-node-modules.test.js +177 -0
  93. package/dist/tests/e2e/runtime-coverage-node-modules.test.js.map +1 -0
  94. package/dist/tests/e2e/runtime-coverage-streams.test.d.ts +4 -0
  95. package/dist/tests/e2e/runtime-coverage-streams.test.js +161 -0
  96. package/dist/tests/e2e/runtime-coverage-streams.test.js.map +1 -0
  97. package/dist/tests/e2e/runtime-coverage-system.test.d.ts +4 -0
  98. package/dist/tests/e2e/runtime-coverage-system.test.js +91 -0
  99. package/dist/tests/e2e/runtime-coverage-system.test.js.map +1 -0
  100. package/dist/tests/e2e/timers.test.d.ts +7 -0
  101. package/dist/tests/e2e/timers.test.js +63 -0
  102. package/dist/tests/e2e/timers.test.js.map +1 -0
  103. package/package.json +2 -2
  104. package/runtime/ext_gui/css.cpp +743 -0
  105. package/runtime/ext_gui/css.h +98 -0
  106. package/runtime/ext_gui/document.cpp +264 -0
  107. package/runtime/ext_gui/document.h +89 -0
  108. package/runtime/ext_gui/dom.cpp +472 -0
  109. package/runtime/ext_gui/dom.h +71 -0
  110. package/runtime/ext_gui/gui.cpp +457 -0
  111. package/runtime/ext_gui/gui_engine.h +81 -0
  112. package/runtime/ext_gui/image.cpp +125 -0
  113. package/runtime/ext_gui/image.h +42 -0
  114. package/runtime/ext_gui/layout.cpp +748 -0
  115. package/runtime/ext_gui/layout.h +93 -0
  116. package/runtime/ext_gui/paint.cpp +137 -0
  117. package/runtime/ext_gui/paint.h +75 -0
  118. package/runtime/ext_gui/renderer.cpp +959 -0
  119. package/runtime/ext_gui/renderer.h +68 -0
  120. package/runtime/ext_gui/stb_image.h +7988 -0
  121. package/runtime/ext_gui/style.cpp +771 -0
  122. package/runtime/ext_gui/style.h +117 -0
  123. package/runtime/ext_gui/text.cpp +378 -0
  124. package/runtime/ext_gui/text.h +78 -0
  125. package/runtime/ext_gui/window.cpp +405 -0
  126. package/runtime/ext_node/fs/fs_common.h +13 -527
  127. package/runtime/ext_node/fs/meta_ops.c +3 -3
  128. package/runtime/ext_node/fs/parts/buffer-bridge.inc +6 -0
  129. package/runtime/ext_node/fs/parts/builtins.inc +69 -0
  130. package/runtime/ext_node/fs/parts/dir.inc +47 -0
  131. package/runtime/ext_node/fs/parts/encoding.inc +186 -0
  132. package/runtime/ext_node/fs/parts/errors.inc +66 -0
  133. package/runtime/ext_node/fs/parts/flags.inc +39 -0
  134. package/runtime/ext_node/fs/parts/platform.inc +86 -0
  135. package/runtime/ext_node/fs/parts/promisify.inc +15 -0
  136. package/runtime/ext_node/fs/parts/time.inc +9 -0
  137. package/runtime/rt.h +36 -4
  138. package/runtime/rt_internal.h +10 -23
  139. package/runtime/xt_builtins.c +4 -0
  140. package/runtime/xt_containers/access.inc +168 -0
  141. package/runtime/xt_containers/arrays.inc +108 -0
  142. package/runtime/xt_containers/boxes.inc +11 -0
  143. package/runtime/xt_containers/objects.inc +326 -0
  144. package/runtime/xt_containers.c +8 -618
  145. package/runtime/xt_ext.h +0 -1
  146. package/runtime/xt_io/base64.inc +87 -0
  147. package/runtime/xt_io/console.inc +119 -0
  148. package/runtime/xt_io/exception.inc +142 -0
  149. package/runtime/xt_io/inspect.inc +212 -0
  150. package/runtime/xt_io.c +11 -556
  151. package/runtime/xt_loop.c +262 -24
  152. package/runtime/xt_regex/api.inc +58 -0
  153. package/runtime/xt_regex/helpers.inc +68 -0
  154. package/runtime/xt_regex/matcher.inc +248 -0
  155. package/runtime/xt_regex/parser.inc +236 -0
  156. package/runtime/xt_regex/types.inc +58 -0
  157. package/runtime/xt_regex.h +9 -672
  158. package/runtime/xt_stdlib2/helpers.inc +2 -4
  159. package/runtime/xt_values/arithmetic.inc +150 -0
  160. package/runtime/xt_values/comparison.inc +112 -0
  161. package/runtime/xt_values/constructors.inc +41 -0
  162. package/runtime/xt_values/conversions.inc +115 -0
  163. package/runtime/xt_values/number-format.inc +180 -0
  164. package/runtime/xt_values/strings.inc +22 -0
  165. package/runtime/xt_values.c +10 -626
  166. package/scripts/build-gui.ts +317 -0
  167. package/scripts/build-runtime.ts +7 -8
  168. package/scripts/coverage-runtime.ts +4 -4
  169. package/scripts/package-release.ts +12 -84
  170. package/src/cli/main.ts +8 -4
  171. package/src/codegen/generator/state.ts +8 -0
  172. package/src/codegen/generator/tables.ts +13 -6
  173. package/src/driver/bundler/graph.ts +95 -0
  174. package/src/driver/bundler/merge.ts +312 -0
  175. package/src/driver/bundler/resolve.ts +240 -0
  176. package/src/driver/bundler/symbols.ts +55 -0
  177. package/src/driver/bundler/types.ts +37 -0
  178. package/src/driver/index.ts +1 -9
  179. package/src/driver/modules.ts +9 -693
  180. package/src/driver/paths.ts +0 -31
  181. package/src/driver/toolchain-provider.ts +12 -45
  182. package/src/driver/toolchain.ts +7 -2
  183. package/src/extensions/catalog.ts +2 -1
  184. package/src/extensions/gui/index.ts +107 -0
  185. package/src/extensions/native.ts +2 -3
  186. package/dist/src/driver/toolchain-download.d.ts +0 -50
  187. package/dist/src/driver/toolchain-download.js +0 -102
  188. package/dist/src/driver/toolchain-download.js.map +0 -1
  189. package/dist/tests/driver/toolchain-download.test.d.ts +0 -1
  190. package/dist/tests/driver/toolchain-download.test.js +0 -53
  191. package/dist/tests/driver/toolchain-download.test.js.map +0 -1
  192. package/dist/tests/e2e/compile.test.d.ts +0 -8
  193. package/dist/tests/e2e/compile.test.js +0 -893
  194. package/dist/tests/e2e/compile.test.js.map +0 -1
  195. package/dist/tests/e2e/differential.test.d.ts +0 -7
  196. package/dist/tests/e2e/differential.test.js.map +0 -1
  197. package/dist/tests/e2e/runtime-coverage.test.d.ts +0 -11
  198. package/dist/tests/e2e/runtime-coverage.test.js +0 -646
  199. package/dist/tests/e2e/runtime-coverage.test.js.map +0 -1
  200. package/scripts/fetch-toolchain.ts +0 -101
  201. package/src/driver/toolchain-download.ts +0 -135
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Runtime-coverage tests for the Buffer implementation.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: buffer", (h) => {
8
+ it("exercises the Buffer implementation", () => {
9
+ const source = `
10
+ const b = Buffer.from("hello");
11
+ console.log(b.toString(), b.length, Buffer.isBuffer(b));
12
+ console.log(Buffer.from([1, 2, 3]).toString("hex"));
13
+ console.log(Buffer.from("68656c6c6f", "hex").toString());
14
+ console.log(Buffer.from("aGVsbG8=", "base64").toString());
15
+ console.log(Buffer.from(b).toString());
16
+ console.log(Buffer.alloc(3).toString("hex"), Buffer.alloc(4, 65).toString(), Buffer.alloc(3, "ab").toString());
17
+ console.log(Buffer.alloc(0).length, Buffer.alloc(3, "").toString("hex"), Buffer.alloc(3, "61", "hex").toString("hex"));
18
+ console.log(Buffer.allocUnsafe(2).length, Buffer.allocUnsafeSlow(2).length);
19
+ console.log(Buffer.byteLength("hello"), Buffer.byteLength("68656c6c6f", "hex"), Buffer.byteLength("aGVsbG8=", "base64"), Buffer.byteLength(b));
20
+ console.log(Buffer.concat([Buffer.from("foo"), Buffer.from("bar")]).toString());
21
+ console.log(Buffer.concat([Buffer.from("foo"), Buffer.from("bar")], 4).toString());
22
+ console.log(Buffer.compare(Buffer.from("a"), Buffer.from("b")), Buffer.compare(Buffer.from("b"), Buffer.from("a")), Buffer.compare(Buffer.from("a"), Buffer.from("a")));
23
+ const n = new Buffer("hey");
24
+ console.log(n.toString(), Buffer.of().length, new Buffer(2).length);
25
+ const j = Buffer.from("hi").toJSON();
26
+ console.log(j.type, j.data.join(","));
27
+ console.log(b.slice(1, 3).toString(), b.slice(-3).toString(), b.subarray(0, 2).toString(), "[" + b.slice(3, 1).toString() + "]");
28
+ console.log(Buffer.from("abc").equals(Buffer.from("abc")), Buffer.from("abc").equals(Buffer.from("abd")), true);
29
+ console.log(Buffer.from("abc").compare(Buffer.from("abd")), Buffer.from("abd").compare(Buffer.from("abc")), Buffer.from("abc").compare(Buffer.from("abc")));
30
+ const target = Buffer.alloc(6);
31
+ const copied = Buffer.from("hello").copy(target, 1, 0, 3);
32
+ console.log(copied, target.toString("hex"));
33
+ const w = Buffer.alloc(8);
34
+ console.log(w.write("abc"), w.write("def", 4), w.toString("hex"));
35
+ console.log(w.write("6161", 0, 4, "hex"), w.toString("hex"));
36
+ console.log(Buffer.alloc(5).fill("a").toString(), Buffer.alloc(5, 1).fill(66, 1, 3).toString("hex"), Buffer.alloc(2).fill(0).toString("hex"));
37
+ console.log(Buffer.from("abc").reverse().toString());
38
+ console.log(b.toString("hex"));
39
+ console.log(Buffer.from("hello world").indexOf("world"), Buffer.from("hello world").indexOf("o"), Buffer.from("hello").indexOf(101), Buffer.from("hello").indexOf(Buffer.from("ll")));
40
+ console.log(Buffer.from("hello world").lastIndexOf("o"), Buffer.from("hello").lastIndexOf("l", 2), Buffer.from("abc").includes("bc"), Buffer.from("abc").includes("z"));
41
+ console.log(Buffer.from("hello").indexOf("z"), Buffer.from("hello").indexOf("toolong"), Buffer.from("hello").indexOf(""), Buffer.from("hello").indexOf("l", -10), Buffer.from("hello").indexOf("l", 100));
42
+ console.log(Buffer.from("hello").lastIndexOf("l", 100), Buffer.from("hello").lastIndexOf("l", -1), Buffer.from("hello").lastIndexOf("lo", 3), Buffer.from("hello").lastIndexOf(111));
43
+ console.log(Buffer.from("hello").indexOf("6c6c", 0, "hex"));
44
+ const io = Buffer.alloc(16);
45
+ console.log(io.writeUInt8(200, 0), io.writeInt8(-56, 1), io.readUInt8(0), io.readInt8(1));
46
+ io.writeUInt16LE(0x1234, 2);
47
+ io.writeUInt16BE(0x1234, 4);
48
+ io.writeUInt16LE(0xfffe, 6);
49
+ io.writeUInt16BE(0xfffe, 8);
50
+ console.log(io.readUInt16LE(2), io.readUInt16BE(4), io.readInt16LE(6), io.readInt16BE(8));
51
+ io.writeUInt32LE(0xffffffff, 0);
52
+ console.log(io.readUInt32LE(0), io.readInt32LE(0));
53
+ io.writeUInt32BE(0x12345678, 4);
54
+ console.log(io.readUInt32BE(4), io.readInt32BE(4));
55
+ console.log(Array.from(Buffer.from("abc").keys()).join(","), Array.from(Buffer.from("abc").values()).join(","));
56
+ console.log(b.toString("base64"), b.toString("hex", 1, 3), "[" + b.toString("utf8", 3, 1) + "]");
57
+ `;
58
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
59
+ expect(stdout.split("\n")).toEqual([
60
+ "hello 5 true",
61
+ "010203",
62
+ "hello",
63
+ "hello",
64
+ "hello",
65
+ "000000 AAAA aba",
66
+ "0 000000 616161",
67
+ "2 2",
68
+ "5 5 6 5",
69
+ "foobar",
70
+ "foob",
71
+ "-1 1 0",
72
+ "hey 0 2",
73
+ "Buffer 104,105",
74
+ "el llo he []",
75
+ "true false true",
76
+ "-1 1 0",
77
+ "3 0068656c0000",
78
+ "3 3 6162630064656600",
79
+ "2 6161630064656600",
80
+ "aaaaa 0142420101 0000",
81
+ "cba",
82
+ "68656c6c6f",
83
+ "6 4 1 2",
84
+ "7 2 true false",
85
+ "-1 -1 -1 2 -1",
86
+ "3 3 3 4",
87
+ "2",
88
+ "1 2 200 -56",
89
+ "4660 4660 -2 -2",
90
+ "4294967295 -1",
91
+ "305419896 305419896",
92
+ "0,1,2 97,98,99",
93
+ "aGVsbG8= 656c []",
94
+ ]);
95
+ });
96
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
97
+ //# sourceMappingURL=runtime-coverage-buffer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-buffer.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-buffer.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,0BAA0B,EAC1B,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,cAAc;YACd,QAAQ;YACR,OAAO;YACP,OAAO;YACP,OAAO;YACP,iBAAiB;YACjB,iBAAiB;YACjB,KAAK;YACL,SAAS;YACT,QAAQ;YACR,MAAM;YACN,QAAQ;YACR,SAAS;YACT,gBAAgB;YAChB,cAAc;YACd,iBAAiB;YACjB,QAAQ;YACR,gBAAgB;YAChB,sBAAsB;YACtB,oBAAoB;YACpB,uBAAuB;YACvB,KAAK;YACL,YAAY;YACZ,SAAS;YACT,gBAAgB;YAChB,eAAe;YACf,SAAS;YACT,GAAG;YACH,aAAa;YACb,iBAAiB;YACjB,eAAe;YACf,qBAAqB;YACrB,gBAAgB;YAChB,kBAAkB;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for the global objects, console helpers and BigInt.
3
+ */
4
+ export {};
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Runtime-coverage tests for the global objects, console helpers and BigInt.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: globals", (h) => {
8
+ it("covers Object, Map, Set and JSON globals", () => {
9
+ const source = `
10
+ console.log(Object.keys({a:1,b:2}).join(","), Object.values({a:1,b:2}).join(","), Object.entries({a:1,b:2}).map(e => e[0]+e[1]).join(","));
11
+ console.log(Object.getOwnPropertyNames([1,2]).join(","), Object.getOwnPropertyNames("ab").join(","));
12
+ console.log(Object.assign({a:1}, {b:2}, {a:3}).a, Object.assign({}, {b:2}).b);
13
+ const fz = Object.freeze({x:1});
14
+ console.log(Object.isFrozen(fz), Object.isFrozen({}));
15
+ console.log(Object.hasOwn({x:1},"x"), Object.hasOwn({x:1},"y"));
16
+ console.log(Object.is(NaN, NaN), Object.is(0, -0), Object.is(1,1), Object.is({},{}));
17
+ const proto = { greet() { return "hi"; } };
18
+ const child = Object.create(proto);
19
+ console.log(child.greet(), Object.getPrototypeOf(child) === proto);
20
+ const grouped = Object.groupBy([1,2,3,4], (n: number) => n % 2 === 0 ? "even" : "odd");
21
+ console.log(grouped.odd.join(","), grouped.even.join(","));
22
+ console.log(Object.fromEntries([["a",1],["b",2]]).a);
23
+ console.log(JSON.stringify({a:1,b:[2,3],c:"x"}), JSON.parse('{"a":1,"b":[2,3]}').b[1]);
24
+ const m = new Map<string, number>(); m.set("a",1); m.set("b",2); console.log(m.get("a"), m.size, m.has("b"), m.delete("a"), m.size);
25
+ const s = new Set<number>(); s.add(1); s.add(2); s.add(1); console.log(s.size, s.has(2), s.delete(1), s.size);
26
+ console.log([...m.keys()].join(","), [...s.values()].join(","));
27
+ `;
28
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
29
+ expect(stdout.split("\n")).toEqual([
30
+ "a,b 1,2 a1,b2",
31
+ "0,1,length 0,1,length",
32
+ "3 2",
33
+ "true false",
34
+ "true false",
35
+ "true false true false",
36
+ "hi true",
37
+ "1,3 2,4",
38
+ "1",
39
+ '{"a":1,"b":[2,3],"c":"x"} 3',
40
+ "1 2 true true 1",
41
+ "2 true true 1",
42
+ "b 2",
43
+ ]);
44
+ });
45
+ it("uses the console surface, inspect and base64 helpers", () => {
46
+ const source = `
47
+ console.count("x");
48
+ console.count("x");
49
+ console.countReset("x");
50
+ console.count("x");
51
+ console.group("g");
52
+ console.groupEnd();
53
+ console.assert(true, "no");
54
+ console.assert(false, "assert-msg");
55
+ console.dir({ a: 1 });
56
+ console.time("t");
57
+ console.timeLog("t");
58
+ console.timeEnd("t");
59
+ console.table([{ a: 1 }, { a: 2 }]);
60
+ console.warn("warn");
61
+ console.error("err");
62
+ console.info("info");
63
+ console.log(btoa("hello"), atob("aGVsbG8="));
64
+ const cyc: any = { a: 1 };
65
+ cyc.self = cyc;
66
+ console.log(cyc);
67
+ console.log({ b: 2, a: 1 });
68
+ console.log([1, "two", true, null, undefined, 3n]);
69
+ console.log(import.meta.url.length > 0, typeof import.meta.dirname, typeof import.meta.filename);
70
+ `;
71
+ const stdout = h
72
+ .runProgram(source, { extensions: true, timeout: TIMEOUT })
73
+ .split("\n")
74
+ .map((line) => (/^t: .*ms$/.test(line) ? "t: <time>" : line))
75
+ .join("\n");
76
+ expect(stdout.split("\n")).toEqual([
77
+ "x: 1",
78
+ "x: 2",
79
+ "x: 1",
80
+ "g",
81
+ "{ a: 1 }",
82
+ "t: <time>",
83
+ "t: <time>",
84
+ "[ { a: 1 }, { a: 2 } ]",
85
+ "info",
86
+ "aGVsbG8= hello",
87
+ "{ a: 1, self: [Circular *1] }",
88
+ "{ b: 2, a: 1 }",
89
+ "[ 1, 'two', true, null, undefined, 3n ]",
90
+ "true string string",
91
+ ]);
92
+ });
93
+ it("computes with BigInt", () => {
94
+ const source = `
95
+ console.log(BigInt("123"), BigInt(456), BigInt(true), BigInt(false), BigInt(10n));
96
+ console.log(10n + 20n, 10n - 3n, 2n * 3n, 10n / 3n, 10n % 3n, 2n ** 10n);
97
+ console.log(-5n, +5n, 5n < 10n, 5n == 5, 5n === 5);
98
+ console.log(255n & 15n, 255n | 15n, 255n ^ 15n, ~0n, 1n << 4n, 256n >> 4n);
99
+ console.log(10n > 5n, 10n >= 10n, 10n < 11n, 10n <= 9n, 5n != 6n, 5n !== 6);
100
+ console.log((123456789012345678901234567890n).toString());
101
+ console.log(Number(10n), +10n, (10n).toString(16), (255n).toString(2), (10n).toString(36));
102
+ try { BigInt(3.5); console.log("no"); } catch (e: any) { console.log("range threw"); }
103
+ try { BigInt({} as any); console.log("no"); } catch (e: any) { console.log("type threw"); }
104
+ console.log(5n ** 0n, 0n ** 5n, 2n ** 64n);
105
+ console.log((0n).toString(16), (-255n).toString(16));
106
+ console.log(BigInt(-12), (-12n).toString(), (-10n) / 3n, (-10n) % 3n);
107
+ console.log(100000000000000000000n + 1n, 99999999999999999999n * 3n);
108
+ console.log(18446744073709551616n > 18446744073709551615n, 18446744073709551615n < 18446744073709551616n, 18446744073709551616n === 18446744073709551616n);
109
+ console.log(1n << 100n, 1n << 200n, 2n ** 100n, 2n ** 200n);
110
+ console.log(-1n & 255n, -1n | 0n, -5n ^ 3n, ~255n, -256n >> 4n, -1n >> 100n);
111
+ console.log(BigInt("0xff"), BigInt("0b101"), BigInt("0o17"), BigInt(" 42 "));
112
+ try { BigInt("abc"); console.log("no"); } catch (e: any) { console.log("syntax threw"); }
113
+ console.log(BigInt("-0"), BigInt("+5"), (255n).toString(8), (255n).toString(16));
114
+ console.log(0n == 0, 0n === 0, 1n < 1, 1n > 0.5);
115
+ console.log((2n ** 64n) / 3n, (2n ** 64n) % 7n);
116
+ console.log((-(2n ** 64n)) / 3n, (-(2n ** 64n)) % 7n);
117
+ console.log((10n).valueOf(), (10n) + "");
118
+ console.log(9007199254740993n, BigInt(9007199254740993));
119
+ `;
120
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
121
+ expect(stdout.split("\n")).toEqual([
122
+ "123n 456n 1n 0n 10n",
123
+ "30n 7n 6n 3n 1n 1024n",
124
+ "-5n 5n true true false",
125
+ "15n 255n 240n -1n 16n 16n",
126
+ "true true true false true true",
127
+ "123456789012345678901234567890",
128
+ "10 10n a 11111111 a",
129
+ "range threw",
130
+ "type threw",
131
+ "1n 0n 18446744073709551616n",
132
+ "0 -ff",
133
+ "-12n -12 -3n -1n",
134
+ "100000000000000000001n 299999999999999999997n",
135
+ "true true true",
136
+ "1267650600228229401496703205376n 1606938044258990275541962092341162602522202993782792835301376n 1267650600228229401496703205376n 1606938044258990275541962092341162602522202993782792835301376n",
137
+ "255n -1n -8n -256n -16n -1n",
138
+ "255n 5n 15n 42n",
139
+ "syntax threw",
140
+ "0n 5n 377 ff",
141
+ "true false false true",
142
+ "6148914691236517205n 2n",
143
+ "-6148914691236517205n -2n",
144
+ "10n 10",
145
+ "9007199254740993n 9007199254740992n",
146
+ ]);
147
+ });
148
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
149
+ //# sourceMappingURL=runtime-coverage-globals.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-globals.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-globals.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,2BAA2B,EAC3B,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;OAkBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,eAAe;YACf,uBAAuB;YACvB,KAAK;YACL,YAAY;YACZ,YAAY;YACZ,uBAAuB;YACvB,SAAS;YACT,SAAS;YACT,GAAG;YACH,6BAA6B;YAC7B,iBAAiB;YACjB,eAAe;YACf,KAAK;SACN,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;OAwBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC;aACb,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;aAC1D,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aAC5D,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,MAAM;YACN,MAAM;YACN,MAAM;YACN,GAAG;YACH,UAAU;YACV,WAAW;YACX,WAAW;YACX,wBAAwB;YACxB,MAAM;YACN,gBAAgB;YAChB,+BAA+B;YAC/B,gBAAgB;YAChB,yCAAyC;YACzC,oBAAoB;SACrB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;OAyBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,qBAAqB;YACrB,uBAAuB;YACvB,wBAAwB;YACxB,2BAA2B;YAC3B,gCAAgC;YAChC,gCAAgC;YAChC,qBAAqB;YACrB,aAAa;YACb,YAAY;YACZ,6BAA6B;YAC7B,OAAO;YACP,kBAAkB;YAClB,+CAA+C;YAC/C,gBAAgB;YAChB,iMAAiM;YACjM,6BAA6B;YAC7B,iBAAiB;YACjB,cAAc;YACd,cAAc;YACd,uBAAuB;YACvB,yBAAyB;YACzB,2BAA2B;YAC3B,QAAQ;YACR,qCAAqC;SACtC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for `util` and `assert`.
3
+ */
4
+ export {};
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Runtime-coverage tests for `util` and `assert`.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: node-modules", (h) => {
8
+ it("exercises util helpers and predicates", () => {
9
+ const source = `
10
+ import util, {
11
+ format, formatWithOptions, inspect, isDeepStrictEqual, inherits, deprecate, promisify,
12
+ isString, isNumber, isBoolean, isUndefined, isNull, isFunction, isArray, isObject,
13
+ isBuffer, isDate, isRegExp, isPromise, isError,
14
+ } from "util";
15
+
16
+ console.log(format("%s %d %i %f %j %o %O %% %c", "s", 3.9, 4.2, 1.5, { a: 1 }, { b: 2 }, [1, 2], "css"));
17
+ console.log(format("%s", { a: 1 }), "|", format("%d", "5"), "|", format("%f", "2.5"));
18
+ console.log(format(1, "two", { three: 3 }));
19
+ console.log(format("only %s"), "|", format("%s and %d", "a"));
20
+ console.log(formatWithOptions({ colors: true }, "%s=%d", "x", 2));
21
+ console.log(inspect(undefined), inspect(null), inspect(true), inspect(1), inspect(10n), inspect("str"));
22
+ console.log(inspect([1, [2, [3, [4]]]]));
23
+ console.log(inspect({ a: 1, nested: { b: [1, 2] } }));
24
+ function f(): void {}
25
+ console.log(inspect(f));
26
+ console.log(inspect(new Date(0)));
27
+ console.log(inspect(/ab+c/gi));
28
+ console.log(isDeepStrictEqual({ a: [1, { b: 2 }] }, { a: [1, { b: 2 }] }), isDeepStrictEqual({ a: 1 }, { a: 2 }));
29
+ console.log(isDeepStrictEqual([1, 2], [1, 2, 3]), isDeepStrictEqual(NaN, NaN));
30
+ class Base {}
31
+ class Derived extends Base {}
32
+ const d = new Derived();
33
+ console.log(d instanceof Base);
34
+ const dep = deprecate(f, "old");
35
+ console.log(dep === f);
36
+ function addAsync(a: number, b: number, cb: (e: unknown, v: number) => void): void { cb(null, a + b); }
37
+ function failAsync(cb: (e: unknown, v: unknown) => void): void { cb(new Error("boom"), null); }
38
+ const add = promisify(addAsync);
39
+ add(2, 3).then((v: number) => { console.log("add", v); });
40
+ const failing = promisify(failAsync);
41
+ failing().then(() => { console.log("no"); }, (e: any) => { console.log("err", e.message); });
42
+ console.log(
43
+ isString("x"), isNumber(1), isBoolean(true), isUndefined(undefined), isNull(null),
44
+ isFunction(f), isArray([]), isObject({}), isBuffer(Buffer.from("x")), isDate(new Date()),
45
+ isRegExp(/x/), isPromise(Promise.resolve(1)), isError(new Error("e")),
46
+ );
47
+ console.log(util.format("%s!", "ns"), util.isNumber(3));
48
+ `;
49
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
50
+ expect(stdout.split("\n")).toEqual([
51
+ "s 3 4 1.500000 {\"a\":1} { b: 2 } [ 1, 2 ] % 'css'",
52
+ "{ a: 1 } | 5 | 2.500000",
53
+ "1 'two' { three: 3 }",
54
+ "only %s | a and %d",
55
+ "x=2",
56
+ "undefined null true 1 10n 'str'",
57
+ "[ 1, [ 2, [Array] ] ]",
58
+ "{ a: 1, nested: { b: [Array] } }",
59
+ "[Function]",
60
+ "[object Object]",
61
+ "[object Object]",
62
+ "true false",
63
+ "false true",
64
+ "true",
65
+ "false",
66
+ "true true true true true true true true true true true true true",
67
+ "ns! true",
68
+ "add 5",
69
+ "err boom",
70
+ ]);
71
+ });
72
+ it("exercises the assert module", () => {
73
+ const source = `
74
+ import assert, { strictEqual, deepStrictEqual, throws, doesNotThrow, ifError, match, doesNotMatch, notStrictEqual, ok, equal, notEqual, deepEqual, notDeepEqual, rejects, doesNotReject } from "node:assert";
75
+
76
+ function check(label: string, fn: () => void): void {
77
+ try {
78
+ fn();
79
+ console.log(label, "ok");
80
+ } catch (e: any) {
81
+ console.log(label, "threw", e.name);
82
+ }
83
+ }
84
+
85
+ check("ok-pass", () => assert.ok(1));
86
+ check("ok-fail", () => assert.ok(0));
87
+ check("equal-pass", () => assert.equal(1, "1"));
88
+ check("equal-fail", () => assert.equal(1, 2, "custom equal"));
89
+ check("notEqual-pass", () => assert.notEqual(1, 2));
90
+ check("notEqual-fail", () => assert.notEqual(1, "1"));
91
+ check("strictEqual-pass", () => assert.strictEqual(1, 1));
92
+ check("strictEqual-fail", () => assert.strictEqual(1, "1"));
93
+ check("notStrictEqual-pass", () => assert.notStrictEqual(1, "1"));
94
+ check("notStrictEqual-fail", () => assert.notStrictEqual(1, 1));
95
+ check("deepEqual-pass", () => assert.deepEqual({ a: [1, 2] }, { a: [1, 2] }));
96
+ check("deepEqual-fail", () => assert.deepEqual({ a: 1 }, { a: 2 }));
97
+ check("notDeepEqual-pass", () => assert.notDeepEqual({ a: 1 }, { a: 2 }));
98
+ check("notDeepEqual-fail", () => assert.notDeepEqual({ a: 1 }, { a: 1 }));
99
+ check("deepStrictEqual-pass", () => assert.deepStrictEqual([1, { b: 2 }], [1, { b: 2 }]));
100
+ check("deepStrictEqual-fail", () => assert.deepStrictEqual([1], [2]));
101
+ check("notDeepStrictEqual-pass", () => assert.notDeepStrictEqual([1], [2]));
102
+ check("throws-pass", () => assert.throws(() => { throw new Error("x"); }));
103
+ check("throws-fail", () => assert.throws(() => {}));
104
+ check("throws-nonfn", () => assert.throws(1 as any));
105
+ check("throws-message", () => assert.throws(() => { throw new Error("x"); }, "boom"));
106
+ check("doesNotThrow-pass", () => assert.doesNotThrow(() => {}));
107
+ check("doesNotThrow-fail", () => assert.doesNotThrow(() => { throw new Error("y"); }));
108
+ check("ifError-null", () => assert.ifError(null));
109
+ check("ifError-undefined", () => assert.ifError(undefined));
110
+ check("ifError-obj", () => assert.ifError(new Error("z")));
111
+ check("ifError-value", () => assert.ifError("bad"));
112
+ check("match-regexp", () => assert.match("hello", /ell/));
113
+ check("match-string", () => assert.match("hello", "ell"));
114
+ check("match-fail", () => assert.match("hello", /xyz/, "no match"));
115
+ check("doesNotMatch-pass", () => assert.doesNotMatch("hello", /xyz/));
116
+ check("doesNotMatch-fail", () => assert.doesNotMatch("hello", /ell/));
117
+ check("fail-default", () => assert.fail());
118
+ check("fail-custom", () => assert.fail("custom failure"));
119
+
120
+ strictEqual(1, 1);
121
+ deepStrictEqual({ x: 1 }, { x: 1 });
122
+ throws(() => { throw new Error("n"); });
123
+ doesNotThrow(() => {});
124
+ ifError(null);
125
+ match("abc", /b/);
126
+ doesNotMatch("abc", /z/);
127
+ notStrictEqual(1, 2);
128
+ ok(true);
129
+ equal(1, "1");
130
+ notEqual(1, 2);
131
+ deepEqual([1], [1]);
132
+ notDeepEqual([1], [2]);
133
+ rejects();
134
+ doesNotReject();
135
+ console.log("named-imports ok");
136
+ `;
137
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
138
+ expect(stdout.split("\n")).toEqual([
139
+ "ok-pass ok",
140
+ "ok-fail threw AssertionError",
141
+ "equal-pass ok",
142
+ "equal-fail threw AssertionError",
143
+ "notEqual-pass ok",
144
+ "notEqual-fail threw AssertionError",
145
+ "strictEqual-pass ok",
146
+ "strictEqual-fail threw AssertionError",
147
+ "notStrictEqual-pass ok",
148
+ "notStrictEqual-fail threw AssertionError",
149
+ "deepEqual-pass ok",
150
+ "deepEqual-fail threw AssertionError",
151
+ "notDeepEqual-pass ok",
152
+ "notDeepEqual-fail threw AssertionError",
153
+ "deepStrictEqual-pass ok",
154
+ "deepStrictEqual-fail threw AssertionError",
155
+ "notDeepStrictEqual-pass ok",
156
+ "throws-pass ok",
157
+ "throws-fail threw AssertionError",
158
+ "throws-nonfn threw AssertionError",
159
+ "throws-message ok",
160
+ "doesNotThrow-pass ok",
161
+ "doesNotThrow-fail threw AssertionError",
162
+ "ifError-null ok",
163
+ "ifError-undefined ok",
164
+ "ifError-obj threw Error",
165
+ "ifError-value threw AssertionError",
166
+ "match-regexp ok",
167
+ "match-string ok",
168
+ "match-fail threw AssertionError",
169
+ "doesNotMatch-pass ok",
170
+ "doesNotMatch-fail threw AssertionError",
171
+ "fail-default threw AssertionError",
172
+ "fail-custom threw AssertionError",
173
+ "named-imports ok",
174
+ ]);
175
+ });
176
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
177
+ //# sourceMappingURL=runtime-coverage-node-modules.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-node-modules.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-node-modules.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,gCAAgC,EAChC,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,qDAAqD;YACrD,yBAAyB;YACzB,sBAAsB;YACtB,oBAAoB;YACpB,KAAK;YACL,iCAAiC;YACjC,uBAAuB;YACvB,kCAAkC;YAClC,YAAY;YACZ,iBAAiB;YACjB,iBAAiB;YACjB,YAAY;YACZ,YAAY;YACZ,MAAM;YACN,OAAO;YACP,kEAAkE;YAClE,UAAU;YACV,OAAO;YACP,UAAU;SACX,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+Dd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,YAAY;YACZ,8BAA8B;YAC9B,eAAe;YACf,iCAAiC;YACjC,kBAAkB;YAClB,oCAAoC;YACpC,qBAAqB;YACrB,uCAAuC;YACvC,wBAAwB;YACxB,0CAA0C;YAC1C,mBAAmB;YACnB,qCAAqC;YACrC,sBAAsB;YACtB,wCAAwC;YACxC,yBAAyB;YACzB,2CAA2C;YAC3C,4BAA4B;YAC5B,gBAAgB;YAChB,kCAAkC;YAClC,mCAAmC;YACnC,mBAAmB;YACnB,sBAAsB;YACtB,wCAAwC;YACxC,iBAAiB;YACjB,sBAAsB;YACtB,yBAAyB;YACzB,oCAAoC;YACpC,iBAAiB;YACjB,iBAAiB;YACjB,iCAAiC;YACjC,sBAAsB;YACtB,wCAAwC;YACxC,mCAAmC;YACnC,kCAAkC;YAClC,kBAAkB;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for `crypto`, streams and `events`.
3
+ */
4
+ export {};
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Runtime-coverage tests for `crypto`, streams and `events`.
3
+ */
4
+ import { expect, it } from "vitest";
5
+ import { describeE2E } from "./harness.js";
6
+ const TIMEOUT = 120000;
7
+ describeE2E("runtime coverage: streams", (h) => {
8
+ it("hashes data with crypto", () => {
9
+ const source = `
10
+ import { createHash } from "crypto";
11
+ import crypto from "node:crypto";
12
+
13
+ console.log(createHash("sha256").update("abc").digest("hex"));
14
+ console.log(createHash("sha-256").update("abc").digest("hex"));
15
+ console.log(createHash("sha1").update("abc").digest("hex"));
16
+ console.log(createHash("sha-1").update("abc").digest("hex"));
17
+ console.log(createHash("sha256").update("x".repeat(100)).digest("base64"));
18
+ const h = createHash("sha256");
19
+ h.update("ab");
20
+ h.update("c");
21
+ console.log(h.digest("hex"));
22
+ const s = createHash("sha256");
23
+ s.setEncoding("base64");
24
+ s.write("ab");
25
+ s.write("c");
26
+ s.end("d");
27
+ console.log(s.read());
28
+ const u = createHash("md5");
29
+ console.log(u.update("abc").digest("hex").length);
30
+ console.log(crypto.createHash("sha256").update("abc").digest("latin1").length);
31
+ `;
32
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
33
+ expect(stdout.split("\n")).toEqual([
34
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
35
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
36
+ "a9993e364706816aba3e25717850c26c9cd0d89d",
37
+ "a9993e364706816aba3e25717850c26c9cd0d89d",
38
+ "Cey268i878cz9vLsRPeRq+7WqZ7fDMMVGWN4mK69Utg=",
39
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
40
+ "iNQmb9TmM40TuEX88olXnSCciXgjuSF9o+Fhk28DFYk=",
41
+ "0",
42
+ "32",
43
+ ]);
44
+ });
45
+ it("drives the stream surface", () => {
46
+ const source = `
47
+ import { Readable, Writable, Duplex, Transform, PassThrough } from "stream";
48
+
49
+ const r = new Readable({});
50
+ r.push("a");
51
+ r.push("b");
52
+ console.log("read1", r.read());
53
+ r.unshift("z");
54
+ console.log("read2", r.read());
55
+ r.setEncoding("utf8");
56
+ console.log("paused", r.isPaused());
57
+ r.pause();
58
+ console.log("paused2", r.isPaused());
59
+ r.resume();
60
+ console.log("paused3", r.isPaused());
61
+ r.push(null);
62
+ console.log("read3", r.read());
63
+
64
+ const w = new Writable({ write(chunk: string, enc: string, cb: () => void) { console.log("write-fn", chunk); cb(); } });
65
+ w.write("hello");
66
+ w.cork();
67
+ w.uncork();
68
+ w.end("bye", () => { console.log("end-cb"); });
69
+
70
+ const t = new Transform((chunk: string, enc: string, cb: (e: unknown, v: string) => void) => { cb(null, chunk.toUpperCase()); });
71
+ t.on("data", (d: string) => { console.log("transform-data", d); });
72
+ t.write("abc");
73
+
74
+ const pt = new PassThrough();
75
+ pt.on("data", (d: string) => { console.log("pt-data", d); });
76
+ pt.write("pass");
77
+ pt.end();
78
+
79
+ const d = new Duplex({ write(chunk: string, enc: string, cb: () => void) { cb(); } });
80
+ d.on("data", (v: string) => { console.log("duplex-data", v); });
81
+ d.write("duplex");
82
+
83
+ const r2 = Readable.from(["x", "y"]);
84
+ r2.on("data", (v: string) => { console.log("from-data", v); });
85
+
86
+ const src = new Readable({});
87
+ src.push("p1");
88
+ src.push("p2");
89
+ const dest = new Writable({ write(c: string, e: string, cb: () => void) { console.log("pipe-dest", c); cb(); } });
90
+ dest.on("finish", () => { console.log("dest-finish"); });
91
+ src.pipe(dest);
92
+ src.push(null);
93
+
94
+ const d2 = new Readable({});
95
+ d2.on("error", (e: any) => { console.log("stream-err", e.message); });
96
+ d2.on("close", () => { console.log("stream-close"); });
97
+ d2.destroy(new Error("boom"));
98
+ `;
99
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
100
+ expect(stdout.split("\n")).toEqual([
101
+ "read1 a",
102
+ "read2 z",
103
+ "paused false",
104
+ "paused2 true",
105
+ "paused3 false",
106
+ "read3 b",
107
+ "write-fn hello",
108
+ "write-fn bye",
109
+ "end-cb",
110
+ "transform-data ABC",
111
+ "pt-data pass",
112
+ "duplex-data duplex",
113
+ "from-data x",
114
+ "from-data y",
115
+ "pipe-dest p1",
116
+ "pipe-dest p2",
117
+ "dest-finish",
118
+ "stream-err boom",
119
+ "stream-close",
120
+ ]);
121
+ });
122
+ it("drives EventEmitter listeners and events.once", () => {
123
+ const source = `
124
+ import { EventEmitter } from "events";
125
+ import events from "node:events";
126
+ const e = new EventEmitter();
127
+ e.on("a", (x: number) => { console.log("a1", x); });
128
+ e.prependListener("a", (x: number) => { console.log("a0", x); });
129
+ e.once("b", (x: number) => { console.log("b once", x); });
130
+ e.on("b", (x: number) => { console.log("b always", x); });
131
+ e.emit("a", 1);
132
+ e.emit("b", 2);
133
+ e.emit("b", 3);
134
+ console.log(e.listenerCount("b"), e.eventNames().join(","), e.listeners("b").length);
135
+ e.removeAllListeners("a");
136
+ console.log(e.listenerCount("a"));
137
+ e.setMaxListeners(20);
138
+ console.log(e.getMaxListeners());
139
+ e.on("c", () => { console.log("c"); });
140
+ e.removeAllListeners();
141
+ console.log(e.eventNames().length);
142
+ const e2 = new EventEmitter();
143
+ events.once(e2, "done").then((v: any) => { console.log("once", v[0]); });
144
+ e2.emit("done", 42);
145
+ `;
146
+ const stdout = h.runProgram(source, { extensions: true, timeout: TIMEOUT });
147
+ expect(stdout.split("\n")).toEqual([
148
+ "a0 1",
149
+ "a1 1",
150
+ "b once 2",
151
+ "b always 2",
152
+ "b always 3",
153
+ "1 a,b 1",
154
+ "0",
155
+ "20",
156
+ "0",
157
+ "once undefined",
158
+ ]);
159
+ });
160
+ }, { tmpPrefix: "xbintsc-runtime-coverage-" });
161
+ //# sourceMappingURL=runtime-coverage-streams.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-coverage-streams.test.js","sourceRoot":"","sources":["../../../tests/e2e/runtime-coverage-streams.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,GAAG,MAAM,CAAC;AAEvB,WAAW,CACT,2BAA2B,EAC3B,CAAC,CAAC,EAAE,EAAE;IACJ,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;OAsBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,kEAAkE;YAClE,kEAAkE;YAClE,0CAA0C;YAC1C,0CAA0C;YAC1C,8CAA8C;YAC9C,kEAAkE;YAClE,8CAA8C;YAC9C,GAAG;YACH,IAAI;SACL,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoDd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,SAAS;YACT,SAAS;YACT,cAAc;YACd,cAAc;YACd,eAAe;YACf,SAAS;YACT,gBAAgB;YAChB,cAAc;YACd,QAAQ;YACR,oBAAoB;YACpB,cAAc;YACd,oBAAoB;YACpB,aAAa;YACb,aAAa;YACb,cAAc;YACd,cAAc;YACd,aAAa;YACb,iBAAiB;YACjB,cAAc;SACf,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;OAsBd,CAAC;QACF,MAAM,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;YACjC,MAAM;YACN,MAAM;YACN,UAAU;YACV,YAAY;YACZ,YAAY;YACZ,SAAS;YACT,GAAG;YACH,IAAI;YACJ,GAAG;YACH,gBAAgB;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,EACD,EAAE,SAAS,EAAE,2BAA2B,EAAE,CAC3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Runtime-coverage tests for `url`, `os`, `process` and `child_process`.
3
+ */
4
+ export {};