ya-struct 0.0.10 → 0.0.12
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/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +3 -1
- package/dist/lib/layout.js +44 -44
- package/dist/lib/parser.d.ts +7 -1
- package/dist/lib/parser.js +6 -0
- package/dist/lib/tests/compile-and-compare.vibe.d.ts +30 -0
- package/dist/lib/tests/compile-and-compare.vibe.js +221 -0
- package/dist/lib/types/array.js +1 -0
- package/dist/lib/types/string.js +1 -0
- package/dist/lib/types/struct.js +1 -0
- package/package.json +12 -7
- package/.editorconfig +0 -8
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/npm-publish.yml +0 -28
- package/eslint.config.js +0 -127
- package/lib/bit-buffer.ts +0 -70
- package/lib/common.ts +0 -30
- package/lib/index.ts +0 -21
- package/lib/layout.ts +0 -286
- package/lib/parser.ts +0 -88
- package/lib/types/array.ts +0 -90
- package/lib/types/c-types.ts +0 -222
- package/lib/types/index.ts +0 -122
- package/lib/types/integer.ts +0 -160
- package/lib/types/pointer.ts +0 -27
- package/lib/types/string.ts +0 -56
- package/lib/types/struct.ts +0 -146
- package/lib/types/value.ts +0 -8
- package/package.npm.json +0 -25
- package/samples/basic.ts +0 -40
- package/test/c-structs.ts +0 -399
- package/test/compile-util.ts +0 -92
- package/test/nested-structs.ts +0 -78
- package/tsconfig.json +0 -11
package/test/nested-structs.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import nodeAssert from "node:assert";
|
|
2
|
-
import { define } from "../lib/parser.ts";
|
|
3
|
-
import { types } from "../lib/types/index.ts";
|
|
4
|
-
|
|
5
|
-
const abi = {
|
|
6
|
-
compiler: "gcc",
|
|
7
|
-
dataModel: "LP64",
|
|
8
|
-
endianness: "little",
|
|
9
|
-
} as const;
|
|
10
|
-
|
|
11
|
-
const innerStructDefinition = {
|
|
12
|
-
type: "struct",
|
|
13
|
-
packed: false,
|
|
14
|
-
fixedAbi: {},
|
|
15
|
-
fields: [
|
|
16
|
-
{ name: "a", definition: types.UInt64 },
|
|
17
|
-
{ name: "b", definition: types.UInt32 },
|
|
18
|
-
{ name: "c", definition: types.UInt32 },
|
|
19
|
-
],
|
|
20
|
-
} as const;
|
|
21
|
-
|
|
22
|
-
const outerStructDefinition = {
|
|
23
|
-
type: "struct",
|
|
24
|
-
packed: false,
|
|
25
|
-
fixedAbi: {},
|
|
26
|
-
fields: [
|
|
27
|
-
{ name: "x", definition: types.UInt64 },
|
|
28
|
-
{ name: "inner", definition: innerStructDefinition },
|
|
29
|
-
],
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
const expectedEncoded = () => {
|
|
33
|
-
const data = new Uint8Array(24);
|
|
34
|
-
const view = new DataView(data.buffer);
|
|
35
|
-
|
|
36
|
-
view.setBigUint64(0, 1n, true);
|
|
37
|
-
view.setBigUint64(8, 2n, true);
|
|
38
|
-
view.setUint32(16, 3, true);
|
|
39
|
-
view.setUint32(20, 4, true);
|
|
40
|
-
|
|
41
|
-
return data;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
describe("nested-structs", () => {
|
|
45
|
-
it("should format nested structs", () => {
|
|
46
|
-
const parser = define({ definition: outerStructDefinition }).parser({ abi });
|
|
47
|
-
|
|
48
|
-
const encoded = parser.format({
|
|
49
|
-
value: {
|
|
50
|
-
x: 1n,
|
|
51
|
-
inner: {
|
|
52
|
-
a: 2n,
|
|
53
|
-
b: 3n,
|
|
54
|
-
c: 4n,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
nodeAssert.deepStrictEqual(encoded, expectedEncoded());
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should parse nested structs", () => {
|
|
63
|
-
const parser = define({ definition: outerStructDefinition }).parser({ abi });
|
|
64
|
-
|
|
65
|
-
const parsed = parser.parse({
|
|
66
|
-
data: expectedEncoded(),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
nodeAssert.deepStrictEqual(parsed, {
|
|
70
|
-
x: 1n,
|
|
71
|
-
inner: {
|
|
72
|
-
a: 2n,
|
|
73
|
-
b: 3n,
|
|
74
|
-
c: 4n,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|