###################################################################### # # Parser routine tests. One test for each grammar rule. # ###################################################################### require 'test_helper' class ParserTest < Test::Unit::TestCase def check(s) check_ast(s){|inp| @parser.parse(inp)} end def setup @parser = C::Parser.new end def test_features assert !@parser.block_expressions_enabled? @parser.enable_block_expressions assert @parser.block_expressions_enabled? @parser.block_expressions_enabled = false assert !@parser.block_expressions_enabled? 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 <