Refactor Library And Start Runtime

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-01-20 07:10:58 -05:00
parent 45a8baa323
commit 4bec71dcf4
11 changed files with 472 additions and 65 deletions
+55
View File
@@ -0,0 +1,55 @@
import Testing
import TreeSitter
import SwiftTreeSitter
import TreeSitterP4
import Foundation
import P4
@testable import Parser
@Test func test_simple_parser() async throws {
let simple_parser_declaration = """
parser simple() {
state start {
transition drop;
}
}
"""
let program = try #require(Parser.Program(simple_parser_declaration))
#expect(program.parsers.count == 1)
#expect(program.parsers[0].states.count == 1)
#expect(program.parsers[0].states[0].state_name == "start")
#expect(program.parsers[0].states[0].statements.count == 0)
}
@Test func test_simple_parser_syntax_error() async throws {
let simple_parser_declaration = """
parser simple() {
state
transition drop;
}
}
"""
#expect(Parser.Program(simple_parser_declaration) == nil)
}
@Test func test_simple_parser_with_statement() async throws {
let simple_parser_declaration = """
parser simple() {
state start {
true;
transition drop;
}
}
"""
let program = try #require(Parser.Program(simple_parser_declaration))
#expect(program.parsers.count == 1)
#expect(program.parsers[0].states.count == 1)
#expect(program.parsers[0].states[0].state_name == "start")
#expect(program.parsers[0].states[0].statements.count == 1)
}