test/test_parser.rb in cast-0.0.1 vs test/test_parser.rb in cast-0.1.0
- old
+ new
@@ -4,14 +4,11 @@
### Parser routine tests. One test for each grammar rule.
###
### ##################################################################
###
-require 'common.rb'
-
class ParserTest < Test::Unit::TestCase
- include CheckAst
def check s
check_ast(s){|inp| C::Parser.new.parse(inp)}
end
def test_comments
@@ -84,12 +81,12 @@
type: Int
declarators:
- Declarator
name: "i"
EOS
- assert_raise(ParseError){C::Parser.new.parse("")}
- assert_raise(ParseError){C::Parser.new.parse(";")}
+ assert_raise(C::ParseError){C::Parser.new.parse("")}
+ assert_raise(C::ParseError){C::Parser.new.parse(";")}
end
def test_external_declaration
check <<EOS
int i;
@@ -140,32 +137,32 @@
type: Char
name: "argv"
name: "main"
EOS
## non-function type
- assert_raise(ParseError){C::Parser.new.parse("int f {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("int f {}")}
## both prototype and declist
- assert_raise(ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
- assert_raise(ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(int argc, int argv) int argc, argv; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(int argc, argv) int argv; {}")}
## bad param name
- assert_raise(ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
- assert_raise(ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argx, argc, argv; {}")}
## type missing
- assert_raise(ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("void f(argc, argv) int argc; {}")}
## bad storage
- assert_raise(ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
- assert_raise(ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
- assert_raise(ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("typedef void f(argc, argv) int argc; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("auto void f(argc, argv) int argc; {}")}
+ assert_raise(C::ParseError){C::Parser.new.parse("register void f(argc, argv) int argc; {}")}
## duplicate storages
- assert_raise(ParseError){C::Parser.new.parse("static auto int i;")}
- assert_raise(ParseError){C::Parser.new.parse("static extern int i;")}
- assert_raise(ParseError){C::Parser.new.parse("typedef register int i;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("static auto int i;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("static extern int i;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("typedef register int i;")}
## `inline' can be repeated
assert_nothing_raised{C::Parser.new.parse("inline inline int i() {}")}
end
@@ -835,13 +832,13 @@
name: "i"
- Declarator
name: "j"
EOS
## duplicate storages
- assert_raise(ParseError){C::Parser.new.parse("static auto int ;")}
- assert_raise(ParseError){C::Parser.new.parse("static extern int i ;")}
- assert_raise(ParseError){C::Parser.new.parse("typedef register int i, j;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("static auto int ;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("static extern int i ;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("typedef register int i, j;")}
## `inline' can be repeated
assert_nothing_raised{C::Parser.new.parse("inline inline int f();")}
end
@@ -1152,19 +1149,19 @@
- Declaration
type: CustomType
name: "I"
EOS
## some illegal combos
- assert_raise(ParseError){C::Parser.new.parse("int float;")}
- assert_raise(ParseError){C::Parser.new.parse("struct s {} int;")}
- assert_raise(ParseError){C::Parser.new.parse("_Complex;")}
- assert_raise(ParseError){C::Parser.new.parse("_Complex _Imaginary float;")}
- assert_raise(ParseError){C::Parser.new.parse("short long;")}
- assert_raise(ParseError){C::Parser.new.parse("signed unsigned char;")}
- assert_raise(ParseError){C::Parser.new.parse("int int;")}
- assert_raise(ParseError){C::Parser.new.parse("long char;")}
- assert_raise(ParseError){C::Parser.new.parse("long long long;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("int float;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("struct s {} int;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("_Complex;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("_Complex _Imaginary float;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("short long;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("signed unsigned char;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("int int;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("long char;")}
+ assert_raise(C::ParseError){C::Parser.new.parse("long long long;")}
end
def test_struct_or_union_specifier
check <<EOS
struct s { int i; } ;
@@ -2150,15 +2147,16 @@
init: IntLiteral
val: 1
EOS
end
- def test_argument_comma
+ def test_argument_expression_list
check <<EOS
void f() {
x(1);
- x(1, 2);
+ x(int);
+ x(1, int);
}
----
TranslationUnit
entities:
- FunctionDef
@@ -2177,13 +2175,62 @@
- ExpressionStatement
expr: Call
expr: Variable
name: "x"
args:
+ - Int
+ - ExpressionStatement
+ expr: Call
+ expr: Variable
+ name: "x"
+ args:
- IntLiteral
val: 1
- - IntLiteral
- val: 2
+ - Int
+EOS
+ end
+
+ def test_argument_expression
+ check <<EOS
+void f() {
+ x(a = 1);
+ x(int*);
+ x(const struct s[]);
+}
+----
+TranslationUnit
+ entities:
+ - FunctionDef
+ type: Function
+ type: Void
+ name: "f"
+ def: Block
+ stmts:
+ - ExpressionStatement
+ expr: Call
+ expr: Variable
+ name: "x"
+ args:
+ - Assign
+ lval: Variable
+ name: "a"
+ rval: IntLiteral
+ val: 1
+ - ExpressionStatement
+ expr: Call
+ expr: Variable
+ name: "x"
+ args:
+ - Pointer
+ type: Int
+ - ExpressionStatement
+ expr: Call
+ expr: Variable
+ name: "x"
+ args:
+ - Array
+ type: Struct (const)
+ name: "s"
EOS
end
def test_unary_expression
check <<EOS