Make Formatter Happy
Continuous Integration / Library Tests (push) Successful in 4m8s
Continuous Integration / Grammar Tests (push) Successful in 36s
Continuous Integration / Library Format Tests (push) Failing after 1m12s

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-22 00:27:17 -04:00
parent 382f3de00a
commit a1908cc077
+74 -1
View File
@@ -380,5 +380,78 @@ import TreeSitterP4
// And that the proper action was invoked.
let result_arg = try #UseOkResult(updated_execution.scopes.lookup(identifier: Identifier(name: "result_arg")))
#expect(result_arg.eq(P4Value(P4IntValue(withValue: 7))))
}
@Test func test_control_key_from_struct() async throws {
let simple_parser_declaration = """
control simple(inout int result, bool x, int f) {
action a() {
result = 5;
}
action b() {
result = 7;
}
table t {
key = {
x: exact;
f: exact;
}
actions = {
a;
b;
}
}
apply {
}
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.InstancesWithTypes() { (tipe: P4QualifiedType) -> Bool in
switch tipe.baseType() {
case let c as Control: c.name == "simple"
default: false
}
}
var control = ((controls[0].baseType() as P4Type) as! Control)
// Add entries to the table.
control = control.updateTable(
addEntry: (
P4Value(P4BooleanValue(withValue: true)),
TypedIdentifier(name: "a", withType: P4QualifiedType(Action()))
)
).updateTable(
addEntry: (
P4Value(P4IntValue(withValue: 5)),
TypedIdentifier(name: "b", withType: P4QualifiedType(Action()))
))
// Set a variable in the global scope for the inout first parameter.
var global_values = VarValueScopes().enter()
global_values = global_values.declare(
identifier: Identifier(name: "result_arg"),
withValue: P4Value(
P4IntValue(withValue: 0),
P4QualifiedType(P4Int())))
let runtime = try #UseOkResult(
P4Runtime.Runtime<P4TableHitMissValue, Control>.create(control: control, withGlobalValues: global_values))
let (hit_miss, updated_execution) = try #UseOkResult(runtime.run(
withArguments: ArgumentList([
Argument(TypedIdentifier(name: "result_arg", withType: P4QualifiedType(P4Int())), atIndex: 0),
Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 1),
Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 2),
])))
// We expect there to be a hit.
#expect(hit_miss == P4TableHitMissValue.Hit)
// And that the proper action was invoked.
let result_arg = try #UseOkResult(updated_execution.scopes.lookup(identifier: Identifier(name: "result_arg")))
#expect(result_arg.eq(P4Value(P4IntValue(withValue: 7))))
}