Parser Test Specifications
Overview
The parser transforms a token stream into a document object model. These tests validate correct construction of the abstract syntax tree and object hierarchy.
Test Cases
PARSER_001: Empty Object
Purpose: Parse minimal valid TON document
Input:
{ }
Expected Result:
- Document.RootObject exists
- RootObject.Properties is empty
- RootObject.Children is empty
- RootObject.ClassName is null/empty
PARSER_002: Object With Class
Purpose: Parse object with class annotation
Input:
{(person)}
Expected Result:
- RootObject.ClassName = "person"
- RootObject.Properties is empty
PARSER_003: Simple Properties
Purpose: Parse basic property assignments
Input:
{
name = 'John Doe',
age = 30,
active = true
}
Expected Properties:
- Property "name": Type=String, Value="John Doe"
- Property "age": Type=Integer, Value=30
- Property "active": Type=Boolean, Value=true
PARSER_004: At-Prefixed Properties
Purpose: Parse properties with @ prefix
Input:
{@name = 'John', @age = 30}
Expected Behavior:
- Properties accessible as "@name" or "name"
- Value for "@name" and "name" = "John"
- Value for "@age" and "age" = 30
PARSER_005: Quoted Property Names
Purpose: Parse properties with special characters
Input:
{
'first name' = 'John',
"last-name" = 'Doe',
'user@id' = 123
}
Expected Properties:
- Property "first name" = "John"
- Property "last-name" = "Doe"
- Property "user@id" = 123
PARSER_006: Null and Undefined
Purpose: Parse null and undefined values
Test Cases:
Input | Expected Type | IsNull | IsUndefined |
---|---|---|---|
{value = null} |
Null | true | false |
{value = undefined} |
Undefined | false | true |
PARSER_007: Number Formats
Purpose: Parse various number formats
Test Cases:
Input | Expected Decimal Value |
---|---|
{value = 0xFF} |
255 |
{value = 0x1A2B} |
6699 |
{value = 0b1010} |
10 |
{value = 0b11111111} |
255 |
PARSER_008: GUID Values
Purpose: Parse GUID values
Input:
{id = 550e8400-e29b-41d4-a716-446655440000}
Expected:
- Property "id": Type=Guid
- Value as GUID = 550e8400-e29b-41d4-a716-446655440000
PARSER_009: Enum Values
Purpose: Parse single enum values
Input:
{status = |active|}
Expected:
- Property "status": Type=Enum
- EnumValue = "active"
PARSER_010: Enum Sets
Purpose: Parse multiple enum values
Input:
{permissions = |read|write|admin|}
Expected:
- Property "permissions": Type=EnumSet
- EnumSet.Values = ["read", "write", "admin"]
- EnumSet.Count = 3
PARSER_011: Nested Objects
Purpose: Parse hierarchical object structures
Input:
{(person)
name = 'John',
{(address)
street = '123 Main St',
city = 'Springfield'
}
}
Expected Structure:
- RootObject.ClassName = "person"
- RootObject.Property["name"] = "John"
- RootObject.Children.Count = 1
- Child[0].ClassName = "address"
- Child[0].Property["street"] = "123 Main St"
- Child[0].Property["city"] = "Springfield"
PARSER_012: Arrays
Purpose: Parse array values
Input:
{
numbers = [1, 2, 3],
mixed = [1, 'hello', true, null]
}
Expected:
- Property "numbers": Type=Array, Count=3
- numbers[0] = 1, numbers[1] = 2, numbers[2] = 3
- Property "mixed": Type=Array, Count=4
- mixed[0].Type=Integer, mixed[1].Type=String, mixed[2].Type=Boolean, mixed[3].Type=Null
PARSER_013: Type Hints
Purpose: Parse values with type hints
Input:
{
name = $'John',
age = %30,
id = &550e8400-e29b-41d4-a716-446655440000
}
Expected:
- Property "name": Type=String (hint preserved)
- Property "age": Type=Integer (hint preserved)
- Property "id": Type=Guid (hint preserved)
PARSER_014: Type Annotations
Purpose: Parse properties with type annotations
Input:
{
name:string = 'John',
age:int = 30
}
Expected:
- Property "name": TypeAnnotation="string", Value="John"
- Property "age": TypeAnnotation="int", Value=30
PARSER_015: Multi-line Strings
Purpose: Parse triple-quoted multi-line strings
Input:
{
description = """
This is a
multi-line string
"""
}
Expected:
- Property "description": Type=String
- Value contains newline characters
- Leading/trailing whitespace handled per spec
PARSER_016: Header Section
Purpose: Parse document header
Input:
#@ tonVersion = '1'
#@ encoding = 'UTF-8'
{}
Expected:
- Document.Header.tonVersion = "1"
- Document.Header.encoding = "UTF-8"
- Document.RootObject exists
PARSER_017: Schema Section
Purpose: Parse inline schema definitions
Input:
{}
#! enum(status) [active, inactive]
#! {(person)
/name = string(required)
}
Expected:
- Document.Schemas.Enums contains "status" with values ["active", "inactive"]
- Document.Schemas.Classes contains "person" with property "/name"
Error Cases
The parser should produce errors for:
- Missing opening brace
- Unclosed braces
- Missing equals sign in property assignment
- Trailing commas in arrays
- Invalid property names
- Duplicate property names (last value wins or error)
Implementation Notes
- Property names are case-sensitive
- @ prefix is optional when accessing properties
- Order of properties should be preserved
- Child objects maintain parent-child relationship
- Type coercion should not occur during parsing