Thing contract, TypeScript: the Slot arm at key 13 with a ParamName codec; names test and refusals at key 14
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b101572fc3
commit
0fb25e4f39
6 changed files with 23 additions and 8 deletions
|
|
@ -40,6 +40,7 @@ const readOnlyList = <TItem>(item: Codec<TItem>): Codec<TItem[]> => {
|
|||
};
|
||||
|
||||
// source.rs
|
||||
export const paramName = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("ParamName")));
|
||||
export const textSourceParam = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("TextSourceParam")));
|
||||
export const numberSourceParam = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("NumberSourceParam")));
|
||||
export const boolSourceParam = present(codecs.slots<T.ParamName>({ 0: ["name", text] }, named("BoolSourceParam")));
|
||||
|
|
@ -461,6 +462,8 @@ export const useNode = present(codecs.slots<T.UseNode>(
|
|||
named("UseNode"),
|
||||
));
|
||||
|
||||
export const slotNode = present(codecs.slots<T.SlotNode>({ 0: ["param", paramName] }, named("SlotNode")));
|
||||
|
||||
const nodeUnion = present(
|
||||
codecs.union<T.Node>(
|
||||
"Node",
|
||||
|
|
@ -478,6 +481,7 @@ const nodeUnion = present(
|
|||
10: ["Plot", plotNode],
|
||||
11: ["Embed", embedNode],
|
||||
12: ["Use", useNode],
|
||||
13: ["Slot", slotNode],
|
||||
},
|
||||
named("Node"),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -198,7 +198,16 @@ export type Node =
|
|||
| Arm<"Overlay", OverlayNode>
|
||||
| Arm<"Plot", PlotNode>
|
||||
| Arm<"Embed", EmbedNode>
|
||||
| Arm<"Use", UseNode>;
|
||||
| Arm<"Use", UseNode>
|
||||
| Arm<"Slot", SlotNode>;
|
||||
/**
|
||||
* Where a composition body places the nodes passed for its Slot parameter `param`. Only a child list of a composition
|
||||
* body holds one, and resolve refuses it elsewhere. It carries no NodeCommon: the argument's nodes, keeping their
|
||||
* caller-scope ids, replace it.
|
||||
*/
|
||||
export interface SlotNode {
|
||||
readonly param: ParamName;
|
||||
}
|
||||
export interface BoxNode {
|
||||
readonly common: NodeCommon;
|
||||
readonly style: BoxStyle;
|
||||
|
|
|
|||
|
|
@ -450,7 +450,7 @@ export function fullComposition(): CompositionDocument {
|
|||
{ name: "act", kind: { kind: "Command" } },
|
||||
{ name: "body", kind: { kind: "Slot" } },
|
||||
],
|
||||
body: boxed("panel-root", [text("panel-title", "t"), innerUse]),
|
||||
body: boxed("panel-root", [text("panel-title", "t"), innerUse, { kind: "Slot", param: { name: "body" } }]),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ const entries = Object.entries(codecs) as [string, { typeName?: string; decode(r
|
|||
const rustName = (key: string) => key[0].toUpperCase() + key.slice(1);
|
||||
const names = new Set(nonEmptyLines(join(parityDir, "type-names.txt")));
|
||||
|
||||
test("the package exports one hundred and one codecs", () => {
|
||||
assert.equal(entries.length, 101);
|
||||
test("the package exports one hundred and three codecs", () => {
|
||||
assert.equal(entries.length, 103);
|
||||
});
|
||||
|
||||
test("every codec's type name is a type of the C# package", () => {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@ const NS = "GameCult.Thing.Contract.";
|
|||
const names = new Set(nonEmptyLines(join(parityDir, "type-names.txt")));
|
||||
const entries = Object.entries(codecs) as [string, { typeName?: string; members?: readonly { typeName: string }[] }][];
|
||||
|
||||
test("ParamName and Scalar are Rust names the C# package does not have; each arm has its own codec", () => {
|
||||
assert.equal(names.has(`${NS}ParamName`), false);
|
||||
test("Scalar is a Rust name the C# package does not have; ParamName is its type for a slot; each Param arm has its own codec", () => {
|
||||
assert.equal(names.has(`${NS}Scalar`), false);
|
||||
for (const [key, codec] of entries) assert.doesNotMatch(codec.typeName ?? "", /\.(ParamName|Scalar)$/u, key);
|
||||
for (const [key, codec] of entries) assert.doesNotMatch(codec.typeName ?? "", /.Scalar$/u, key);
|
||||
assert.ok(names.has(`${NS}ParamName`));
|
||||
assert.equal(codecs.paramName.typeName, `${NS}ParamName`);
|
||||
assert.equal(codecs.slotNode.typeName, `${NS}SlotNode`);
|
||||
const arms = {
|
||||
textSourceParam: "TextSourceParam",
|
||||
numberSourceParam: "NumberSourceParam",
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ test("a Thing 1 flat map is not a command result", () => {
|
|||
});
|
||||
|
||||
test("an unknown Node arm is refused naming the union and the key", () => {
|
||||
assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 13/);
|
||||
assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 14/);
|
||||
});
|
||||
|
||||
test("an unknown Outcome arm is refused naming the union and the key", () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue