### ### ################################################################## ### ### Parser routine tests. One test for each grammar rule. ### ### ################################################################## ### class ParserTest < Test::Unit::TestCase def check s check_ast(s){|inp| C::Parser.new.parse(inp)} end def test_comments check <a; x++; x--; (int){1}; (int){1,}; } ---- TranslationUnit entities: - FunctionDef type: Function type: Void name: "f" def: Block stmts: - ExpressionStatement expr: Variable name: "x" - ExpressionStatement expr: Index expr: Variable name: "x" index: IntLiteral val: 1 - ExpressionStatement expr: Call expr: Variable name: "x" args: - IntLiteral val: 1 - ExpressionStatement expr: Call expr: Variable name: "x" - ExpressionStatement expr: Dot expr: Variable name: "x" member: Member name: "a" - ExpressionStatement expr: Arrow expr: Variable name: "x" member: Member name: "a" - ExpressionStatement expr: PostInc expr: Variable name: "x" - ExpressionStatement expr: PostDec expr: Variable name: "x" - ExpressionStatement expr: CompoundLiteral type: Int member_inits: - MemberInit init: IntLiteral val: 1 - ExpressionStatement expr: CompoundLiteral type: Int member_inits: - MemberInit init: IntLiteral val: 1 EOS end def test_argument_expression_list check <> x; } ---- TranslationUnit entities: - FunctionDef type: Function type: Void name: "f" def: Block stmts: - ExpressionStatement expr: Variable name: "x" - ExpressionStatement expr: ShiftLeft expr1: Variable name: "x" expr2: Variable name: "x" - ExpressionStatement expr: ShiftRight expr1: Variable name: "x" expr2: Variable name: "x" EOS end def test_relational_expression check < x; x <= x; x >= x; } ---- TranslationUnit entities: - FunctionDef type: Function type: Void name: "f" def: Block stmts: - ExpressionStatement expr: Variable name: "x" - ExpressionStatement expr: Less expr1: Variable name: "x" expr2: Variable name: "x" - ExpressionStatement expr: More expr1: Variable name: "x" expr2: Variable name: "x" - ExpressionStatement expr: LessOrEqual expr1: Variable name: "x" expr2: Variable name: "x" - ExpressionStatement expr: MoreOrEqual expr1: Variable name: "x" expr2: Variable name: "x" EOS end def test_equality_expression check <>= x; x &= x; x ^= x; x |= x; } ---- TranslationUnit entities: - FunctionDef type: Function type: Void name: "f" def: Block stmts: - ExpressionStatement expr: Assign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: MultiplyAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: DivideAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: ModAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: AddAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: SubtractAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: ShiftLeftAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: ShiftRightAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: BitAndAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: BitXorAssign lval: Variable name: "x" rval: Variable name: "x" - ExpressionStatement expr: BitOrAssign lval: Variable name: "x" rval: Variable name: "x" EOS end def test_expression check <