From f2d18484417fdc6e9ae4970fed7eda0de1027e91 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 1 Jul 2017 02:01:05 +0000 Subject: parse.y: f_margs parser events * parse.y (f_margs): implemented parser events for massign formal arguments. [ruby-core:81848] [Bug #13701] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ripper/test_parser_events.rb | 78 +++++++++++++++++++++++++++++++++++++++ test/ripper/test_sexp.rb | 15 ++++++++ 2 files changed, 93 insertions(+) (limited to 'test/ripper') diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index c2d6a255be..c9189ee7a8 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -896,6 +896,84 @@ class TestRipper::ParserEvents < Test::Unit::TestCase assert_equal [nil, nil, nil, nil, nil, "x", nil], arg end + def test_params_mlhs + thru_mlhs = false + tree = parse("proc {|(a, b)|}", :on_mlhs_paren) {thru_mlhs = true} + assert_equal true, thru_mlhs + assert_include(tree, "[mlhs([a,b])]") + end + + def test_params_mlhs_add + thru_mlhs_add = false + tree = parse("proc {|(a, b)|}", :on_mlhs_add) {thru_mlhs_add = true} + assert_equal true, thru_mlhs_add + assert_include(tree, "[mlhs([a,b])]") + end + + def test_params_mlhs_add_star + thru_mlhs_add_star = false + tree = parse("proc {|(a, *b)|}", :on_mlhs_add_star) {thru_mlhs_add_star = true} + assert_equal true, thru_mlhs_add_star + assert_include(tree, "[mlhs([a,*b])]") + thru_mlhs_add_star = false + tree = parse("proc {|(a, *b, c)|}", :on_mlhs_add_star) {thru_mlhs_add_star = true} + assert_equal true, thru_mlhs_add_star + assert_include(tree, "[mlhs([a,*b,c])]") + thru_mlhs_add_star = false + tree = parse("proc {|(a, *, c)|}", :on_mlhs_add_star) {thru_mlhs_add_star = true} + assert_equal true, thru_mlhs_add_star + assert_include(tree, "[mlhs([a,*,c])]") + thru_mlhs_add_star = false + tree = parse("proc {|(*b, c)|}", :on_mlhs_add_star) {thru_mlhs_add_star = true} + assert_equal true, thru_mlhs_add_star + assert_include(tree, "[mlhs([*b,c])]") + thru_mlhs_add_star = false + tree = parse("proc {|(*b)|}", :on_mlhs_add_star) {thru_mlhs_add_star = true} + assert_equal true, thru_mlhs_add_star + assert_include(tree, "[mlhs([*b])]") + end + + def test_params_mlhs_add_post + thru_mlhs_add_post = false + tree = parse("proc {|(a, *b)|}", :on_mlhs_add_post) {thru_mlhs_add_post = true} + assert_equal false, thru_mlhs_add_post + assert_include(tree, "mlhs([a,*b])") + thru_mlhs_add_post = false + tree = parse("proc {|(a, *b, c)|}", :on_mlhs_add_post) {thru_mlhs_add_post = true} + assert_equal true, thru_mlhs_add_post + assert_include(tree, "mlhs([a,*b,c])") + thru_mlhs_add_post = false + tree = parse("proc {|(a, *, c)|}", :on_mlhs_add_post) {thru_mlhs_add_post = true} + assert_equal true, thru_mlhs_add_post + assert_include(tree, "mlhs([a,*,c])") + thru_mlhs_add_post = false + tree = parse("proc {|(*b, c)|}", :on_mlhs_add_post) {thru_mlhs_add_post = true} + assert_equal true, thru_mlhs_add_post + assert_include(tree, "mlhs([*b,c])") + thru_mlhs_add_post = false + tree = parse("proc {|(*, c)|}", :on_mlhs_add_post) {thru_mlhs_add_post = true} + assert_equal true, thru_mlhs_add_post + assert_include(tree, "mlhs([*,c])") + end + + def test_params_mlhs_new + thru_mlhs_new = false + tree = parse("proc {|(a, b)|}", :on_mlhs_new) {thru_mlhs_new = true} + assert_equal true, thru_mlhs_new + assert_include(tree, "[mlhs([a,b])]") + end + + def test_params_mlhs_paren + thru_mlhs_paren = 0 + tree = parse("proc {|(a, b)|}", :on_mlhs_paren) {thru_mlhs_paren += 1} + assert_equal 1, thru_mlhs_paren + assert_include(tree, "[mlhs([a,b])]") + thru_mlhs_paren = 0 + tree = parse("proc {|((a, b))|}", :on_mlhs_paren) {thru_mlhs_paren += 1} + assert_equal 2, thru_mlhs_paren + assert_include(tree, "[mlhs([a,b])]") + end + def test_paren thru_paren = false parse('()', :on_paren) {thru_paren = true} diff --git a/test/ripper/test_sexp.rb b/test/ripper/test_sexp.rb index 26d19b13a6..d3afbb2399 100644 --- a/test/ripper/test_sexp.rb +++ b/test/ripper/test_sexp.rb @@ -60,6 +60,21 @@ eot assert_equal clear_pos(sexp1), clear_pos(sexp2) end + def test_params_mlhs + sexp = Ripper.sexp("proc {|(w, *x, y), z|}") + _, ((mlhs, w, (rest, x), y), z) = search_sexp(:params, sexp) + assert_equal(:mlhs, mlhs) + assert_equal(:@ident, w[0]) + assert_equal("w", w[1]) + assert_equal(:rest_param, rest) + assert_equal(:@ident, x[0]) + assert_equal("x", x[1]) + assert_equal(:@ident, y[0]) + assert_equal("y", y[1]) + assert_equal(:@ident, z[0]) + assert_equal("z", z[1]) + end + def search_sexp(sym, sexp) return sexp if !sexp or sexp[0] == sym sexp.find do |e| -- cgit v1.2.3