Test grammar#
Test grammar describes test declarations, fixtures, setup blocks, assertions, and expected error paths.
Source#
| Property | Value |
|---|---|
| Grammar file | packages/business/language/grammar/test.g4 |
| Grammar name | test |
| Grammar kind | parser |
| Imports | common, type, expression |
| Imported by | BusinessLanguage, module |
| Direct rule or token count | 8 |
How to use this page#
Read the examples first when authoring Business Language. Use the rule inventory when checking exact grammar coverage or when updating parser, lowering, editor, or documentation behavior.
Entry rules and syntax families#
Start with these rules when reading this grammar: testDeclaration.
- Declarations:
testDeclaration
Key grammar excerpts#
testDeclaration#
testDeclaration: TEST identifier OPEN_BRACE testMemberList? CLOSE_BRACE;Complete rule and token inventory#
testAssertion, testContext, testDeclaration, testExpectation, testMatcher, testMember, testMemberList, testSetupExamples#
Success assertion#
test vendor_lookup_returns_vendor {
context vendor_id: VendorId = "V-100";
setup {
seed_vendor(vendor_id);
}
assert find_vendor(vendor_id) != null;
teardown {
clear_vendor(vendor_id);
}
}Failure expectation#
test missing_approval_policy_fails_closed {
context invoice_id: InvoiceId = "INV-100";
expect post_invoice(invoice_id) to throw MissingApprovalPolicy;
}Comparison matchers#
test matcher_examples {
context invoice: Invoice = sample_invoice;
expect calculate_total(invoice) to equal invoice.amount;
expect invoice.tags to contain expected_tag;
expect invoice.status to be expected_status;
}Common authoring mistakes#
- Do not copy examples without checking the rule inventory for the exact grammar boundary.
- Do not add behavior that depends on missing configuration or undeclared user-facing errors.
Related guides#
- /language/testing/
- /language/rules-tests-errors/
Authoring notes#
- Keep examples aligned with the grammar source, not with inferred syntax from another language.
- Use declared messages for user-facing failures, and fail closed when required configuration is absent.