mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
test(python): reuse the marshal small tuple fixture (#16975)
This commit is contained in:
1 parent
bff6da7449
commit
cf1d2c0f93
3 files changed
+8
-13
No files matched your search
@@ -53,7 +53,7 @@ const marshalShortAscii = (value: string, interned = false): Buffer =>
|
||||
u8(Buffer.byteLength(value, "utf8")),
|
||||
Buffer.from(value, "utf8"),
|
||||
);
|
||||
const marshalSmallTuple = (items: Buffer[]): Buffer =>
|
||||
export const marshalSmallTuple = (items: readonly Buffer[]): Buffer =>
|
||||
concat(u8(0x29), u8(items.length), ...items);
|
||||
|
||||
export type FixtureCodeFields = {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "../domain/python/pythonPyc.js";
|
||||
import {
|
||||
marshalCode,
|
||||
marshalSmallTuple as tuple,
|
||||
pythonPycFixture,
|
||||
pythonPycHeader,
|
||||
pythonPycWithCode,
|
||||
@@ -1264,15 +1265,13 @@ it("accepts code objects as set members and dictionary keys", () => {
|
||||
it("rejects code keys and members whose consts are unhashable", () => {
|
||||
const list = Buffer.concat([Buffer.from([0x5b]), u32(0)]);
|
||||
const int = Buffer.concat([Buffer.from([0x69]), i32(1)]);
|
||||
const tuple = (...items: Buffer[]): Buffer =>
|
||||
Buffer.concat([Buffer.from([0x29, items.length]), ...items]);
|
||||
const code = (...consts: Buffer[]): Buffer =>
|
||||
marshalCode("py311", { name: "u", qualname: "u", consts });
|
||||
const setOf = (kind: number, member: Buffer): Buffer =>
|
||||
Buffer.concat([Buffer.from([kind]), u32(1), member]);
|
||||
const dictKey = (key: Buffer): Buffer =>
|
||||
Buffer.concat([Buffer.from([0x7b]), key, int, Buffer.from([0x30])]);
|
||||
for (const key of [code(list), code(tuple(int, list)), code(code(list))]) {
|
||||
for (const key of [code(list), code(tuple([int, list])), code(code(list))]) {
|
||||
expect(() => parse(withConsts([setOf(0x3c, key)]))).toThrow(
|
||||
ParseFailureError,
|
||||
);
|
||||
@@ -1287,7 +1286,7 @@ it("rejects code keys and members whose consts are unhashable", () => {
|
||||
name: "u",
|
||||
qualname: "u",
|
||||
flagged: true,
|
||||
constsObject: tuple(marshalRef(0)),
|
||||
constsObject: tuple([marshalRef(0)]),
|
||||
}),
|
||||
]);
|
||||
expect(() => parse(withConsts([cyclic, setOf(0x3c, marshalRef(1))]))).toThrow(
|
||||
@@ -1301,7 +1300,7 @@ it("rejects code keys and members whose consts are unhashable", () => {
|
||||
marshalCode("py311", {
|
||||
name: "u",
|
||||
qualname: "u",
|
||||
constsObject: tuple(marshalRef(0)),
|
||||
constsObject: tuple([marshalRef(0)]),
|
||||
}),
|
||||
marshalCode("py311", {
|
||||
name: "u",
|
||||
@@ -1321,13 +1320,13 @@ it("rejects code keys and members whose consts are unhashable", () => {
|
||||
),
|
||||
).toThrow(ParseFailureError);
|
||||
|
||||
const unhashed = parse(withConsts([tuple(code(list))]));
|
||||
const unhashed = parse(withConsts([tuple([code(list)])]));
|
||||
expect(unhashed.coverage.status).toBe("complete");
|
||||
expect(unhashed.code_objects[1]?.consts[0]).toEqual({
|
||||
kind: "list",
|
||||
length: 0,
|
||||
});
|
||||
const hashable = parse(withConsts([setOf(0x3c, code(tuple(int)))]));
|
||||
const hashable = parse(withConsts([setOf(0x3c, code(tuple([int])))]));
|
||||
expect(root(hashable).consts[0]).toEqual({ kind: "set", length: 1 });
|
||||
expect(hashable.coverage.status).toBe("complete");
|
||||
});
|
||||
@@ -1473,8 +1472,6 @@ it("keeps one descendant list when many wrappers share a container", () => {
|
||||
it("keeps code objects whose consts differ only by tuple shape", () => {
|
||||
const int = (value: number): Buffer =>
|
||||
Buffer.concat([Buffer.from([0x69]), i32(value)]);
|
||||
const tuple = (items: Buffer[]): Buffer =>
|
||||
Buffer.concat([Buffer.from([0x29, items.length]), ...items]);
|
||||
const code = (consts: Buffer): Buffer =>
|
||||
marshalCode("py311", {
|
||||
name: "f",
|
||||
|
||||
Reference in new issue
Block a user