@@ -13,14 +13,16 @@ Feature: Parser
13
13
Examples :
14
14
| expr | tree | notes |
15
15
| "1 + 2 " | [:do ,[:+,1 ,2 ]] | The full parser wraps a [:do ] around everything |
16
- | "foo { }" | [:do ,[:call ,:foo ,[], [:lambda ]]] | Testing empty blocks |
17
- | "foo (1 ) { }" | [:do ,[:call ,:foo ,1 , [:lambda ]]] | Testing empty blocks |
18
- | "foo (1 ) { bar }" | [:do ,[:call ,:foo ,1 , [:lambda , [],[:bar ]]]] | Testing function calls inside a block |
19
- | "foo (1 ) { bar 1 }" | [:do ,[:call ,:foo ,1 , [:lambda , [],[[:call ,:bar ,1 ]]]]] | Testing function calls inside a block |
20
- | "foo { bar [0 ] }" | [:do ,[:call ,:foo ,[],[:lambda , [],[[:callm ,:bar ,:[],[0 ]]]]]] | Testing index operator inside a block |
16
+ | "foo (1 )" | [:do ,[:call ,:foo ,[1 ]]] | Simple function /method call |
17
+ | "foo (1 ,2 )" | [:do ,[:call ,:foo ,[1 ,2 ]]] | Simple function /method call |
18
+ | "foo { }" | [:do ,[:call ,:foo ,[], [:proc ]]] | Testing empty blocks |
19
+ | "foo (1 ) { }" | [:do ,[:call ,:foo ,1 , [:proc ]]] | Testing empty blocks |
20
+ | "foo (1 ) { bar }" | [:do ,[:call ,:foo ,1 , [:proc , [],[:bar ]]]] | Testing function calls inside a block |
21
+ | "foo (1 ) { bar 1 }" | [:do ,[:call ,:foo ,1 , [:proc , [],[[:call ,:bar ,[1 ]]]]]] | Testing function calls inside a block |
22
+ | "foo { bar [0 ] }" | [:do ,[:call ,:foo ,[],[:proc , [],[[:callm ,:bar ,:[],[0 ]]]]]] | Testing index operator inside a block |
21
23
| "while foo do end " | [:do , [:while , :foo , [:do ]]] | while with "do ... end " instead of just "end " |
22
24
| "Keywords =Set [1 ]"+10 .chr +"foo " | [:do ,[:assign ,:Keywords ,[:callm ,:Set ,:[],[1 ]]],:foo ] | :rp before linefeed should terminate an expression |
23
- | "expect (',') or return args " | [:do ,[:or ,[:call ,:expect ,","],[:return ,:args ]]] | Priority of "or " vs . call /return |
25
+ | "expect (',') or return args " | [:do ,[:or ,[:call ,:expect ,[ ","]] ,[:return ,:args ]]] | Priority of "or " vs . call /return |
24
26
| "require File .dirname () + '/../spec_helper '" | [:do , [:require , [:+, [:callm , :File , :dirname , nil ], "/../spec_helper "]]] | |
25
27
| "File .dirname () + '/../spec_helper '" | [:do , [:+, [:callm , :File , :dirname , nil ], "/../spec_helper "]] | |
26
28
| "dirname () + '/../spec_helper '" | [:do , [:+,[:call , :dirname ],"/../spec_helper "]] | |
@@ -58,7 +60,7 @@ Feature: Parser
58
60
| "{:a => 1 , :b => 2 }" | [:do ,[:hash ,[:pair ,:":a ",1 ],[:pair ,:":b ",2 ]]] | Literal hash with two values |
59
61
| "vtable = {}" | [:do ,[:assign ,:vtable ,[:hash ]]] | Literal hash |
60
62
| "foo = {:a => 1 ,}" | [:do ,[:assign ,:foo ,[:hash ,[:pair ,:":a ",1 ]]]] | Literal hash with trailing comma |
61
- | "{:a => foo (1 ), :b => foo (2 )}" | [:do , [:hash , [:pair , :":a ", [:call , :foo , 1 ]], [:pair , :":b ", [:call , :foo , 2 ]]]] | Hash where value is a function call |
63
+ | "{:a => foo (1 ), :b => foo (2 )}" | [:do , [:hash , [:pair , :":a ", [:call , :foo , [ 1 ]]] , [:pair , :":b ", [:call , :foo , [ 2 ] ]]]] | Hash where value is a function call |
62
64
| "{:a => 1 , }" | [:do , [:hash , [:pair ,:":a ",1 ]]] | Trailing , |
63
65
| "a = {'foo ' => :bar }" | [:do , [:assign , :a , [:hash , [:pair , "foo ", :":bar "]]]] | |
64
66
@@ -99,7 +101,7 @@ Feature: Parser
99
101
| "def foo (bar =nil ); end " | [:do , [:defm , :foo , [[:bar , :default , :nil ]], []]] | Default value for arguments |
100
102
| "def foo (bar = nil ); end " | [:do , [:defm , :foo , [[:bar , :default , :nil ]], []]] | Default value for arguments - with whitespace |
101
103
| "def foo (bar = []); end " | [:do , [:defm , :foo , [[:bar , :default , [:array ]]], []]] | Default value for arguments - with whitespace |
102
- | "def foo (&bar );end " | [:do , [:defm , :foo , [[:bar ,:block ]], []]] | Block as named argument |
104
+ | "def foo (&bar );end " | [:do , [:defm , :foo , [[:bar ,:block ]], []]] | Block as named argument |
103
105
| "def foo (a = :b , c = :d );end ; " | [:do , [:defm , :foo , [[:a ,:default , :":b "],[:c ,:default , :":d "]], []]] | Second argument following argument with initializer |
104
106
| "def foo (a = :b , &bar );end ; " | [:do , [:defm , :foo , [[:a ,:default , :":b "],[:bar ,:block ]], []]] | Second argument following argument with initializer |
105
107
| "def self .foo ;end ;" | [:do , [:defm , [:self ,:foo ], [], []]] | Class method etc . |
@@ -129,7 +131,7 @@ Feature: Parser
129
131
| "case foo ; when a ; end " | [:do , [:case , :foo , [[:when , :a , []]]]] | Basic case structure |
130
132
| "case foo ; when a ; b ;when c ; d ; end " | [:do ,[:case , :foo , [[:when ,:a ,[:b ]],[:when ,:c ,[:d ]]]]] | More complicated case |
131
133
| "case foo ; when ?a ..?z , ?A ..?Z ; end " | [:do , [:case , :foo , [[:when , [[:range , 97 , 122 ], [:range , 65 , 90 ]], []]]]] | "When " with multiple conditions |
132
- | "begin ; puts 'foo ';rescue Exception => e ; end ; " | [:do , [:block , [], [[:call , :puts , "foo "]], [:rescue , :Exception , :e , []]]] | begin /rescue |
134
+ | "begin ; puts 'foo ';rescue Exception => e ; end ; " | [:do , [:block , [], [[:call , :puts , [ "foo "] ]], [:rescue , :Exception , :e , []]]] | begin /rescue |
133
135
| "unless foo ; bar ; else ; baz ; end " | [:do , [:unless , :foo , [:do , :bar ], [:do , :baz ]]] | |
134
136
| "if foo ; bar ; elsif baz ; a ; else ; b ; end " | [:do , [:if , :foo , [:do , :bar ], [:do , [:if , :baz , [:do , :a ], [:do , :b ]]]]] | |
135
137
@@ -159,4 +161,22 @@ Feature: Parser
159
161
| "a && b " | [:do , [:and , :a , :b ]] | Simple |
160
162
161
163
162
-
164
+ @lambda
165
+ Scenario Outline : Lambda and block expressions
166
+ Given the expression <expr>
167
+ When I parse it with the full parser
168
+ Then the parse tree should become <tree>
169
+
170
+ Examples :
171
+ | expr | tree |
172
+ | "lambda do end " | [:do , [:lambda ]] |
173
+ | "lambda do puts 'test '; end " | [:do , [:lambda ,[], [[:call , :puts , ["test "]]]]] |
174
+ | "lambda do puts 'hello '; puts 'world '; end " | [:do , [:lambda ,[], [[:call , :puts , ["hello "]], [:call , :puts , ["world "]]]]] |
175
+ | "foo do puts 'hello '; puts 'world '; end " | [:do , [:call , :foo ,[], [:proc , [], [[:call , :puts , ["hello "]], [:call , :puts , ["world "]]]]]] |
176
+ | "l = lambda do puts 'test '; end " | [:do , [:assign , :l , [:lambda , [], [[:call , :puts , ["test "]]]]]] |
177
+ | "l = lambda do puts 'foo '; end ; puts 'bar '" | [:do , [:assign , :l , [:lambda , [], [[:call , :puts , ["foo "]]]]], [:call , :puts , ["bar "]]] |
178
+
179
+
180
+
181
+
182
+
0 commit comments