Skip to content

Commit 1bb05a9

Browse files
committed
Add test for postfix if/unless/while/until
The postfix form for if/unless/while/until is detected in IRB Ruby parser with special token types of Tk{IF,UNLESS,WHILE,UNTIL}_MOD, but the detection is a new feature in parser.y after parsed with EXPR_LABEL bit, it's introduced after the birth of IRB. So this is an important test to replace Ruby parser of IRB with Ripper.
1 parent 27a9c41 commit 1bb05a9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/test_rdoc_parser_ruby.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,30 @@ def blah
19911991
assert_equal 'Foo#blah', methods.first.full_name
19921992
end
19931993

1994+
def test_parse_statements_postfix_if_unless
1995+
util_parser <<-CODE
1996+
class C
1997+
def foo
1998+
1 if nil
1999+
end
2000+
2001+
def bar
2002+
2 unless nil
2003+
end
2004+
end
2005+
CODE
2006+
2007+
@parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil
2008+
2009+
c = @top_level.classes.first
2010+
assert_equal 'C', c.full_name, 'class C'
2011+
2012+
methods = c.method_list
2013+
assert_equal 2, methods.length
2014+
assert_equal 'C#foo', methods[0].full_name
2015+
assert_equal 'C#bar', methods[1].full_name
2016+
end
2017+
19942018
def test_parse_statements_class_nested
19952019
comment = RDoc::Comment.new "##\n# my method\n", @top_level
19962020

0 commit comments

Comments
 (0)