From 1bb05a91d534f0ec3d6f4ff362f0788abe003768 Mon Sep 17 00:00:00 2001 From: Code Ass Date: Mon, 10 Jul 2017 00:45:34 +0900 Subject: [PATCH] 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. --- test/test_rdoc_parser_ruby.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index 7415f20dee..c799916fa2 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -1991,6 +1991,30 @@ def blah assert_equal 'Foo#blah', methods.first.full_name end + def test_parse_statements_postfix_if_unless + util_parser <<-CODE +class C + def foo + 1 if nil + end + + def bar + 2 unless nil + end +end + CODE + + @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil + + c = @top_level.classes.first + assert_equal 'C', c.full_name, 'class C' + + methods = c.method_list + assert_equal 2, methods.length + assert_equal 'C#foo', methods[0].full_name + assert_equal 'C#bar', methods[1].full_name + end + def test_parse_statements_class_nested comment = RDoc::Comment.new "##\n# my method\n", @top_level