1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test_parser_events.rb: simplify

* test/ripper/dummyparser.rb (DummyParser): simplified mlhs node
  representation.

* test/ripper/test_parser_events.rb (test_mlhs_add_star):
  simplified assertions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-07-01 01:29:22 +00:00
parent 24171da222
commit 046f8469f3
2 changed files with 38 additions and 5 deletions

View file

@ -38,6 +38,11 @@ class NodeList
self self
end end
def concat(item)
@list.concat item
self
end
def prepend(items) def prepend(items)
@list.unshift items @list.unshift items
end end
@ -209,6 +214,34 @@ class DummyParser < Ripper
words.push word words.push word
end end
def on_mlhs_new
NodeList.new
end
def on_mlhs_paren(list)
Node.new(:mlhs, list)
end
def on_mlhs_add(list, node)
list.push node
end
def on_mlhs_add_block(list, blk)
if blk
list.push('&' + blk.to_s)
else
list
end
end
def on_mlhs_add_star(list, arg)
list.push('*' + arg.to_s)
end
def on_mlhs_add_post(list, post)
list.concat(post.list)
end
def on_rescue(exc, *rest) def on_rescue(exc, *rest)
Node.new('rescue', (exc && NodeList.new(exc)), *rest) Node.new('rescue', (exc && NodeList.new(exc)), *rest)
end end

View file

@ -470,23 +470,23 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
thru_mlhs_add_star = false thru_mlhs_add_star = false
tree = parse("a, *b = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true} tree = parse("a, *b = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star assert_equal true, thru_mlhs_add_star
assert_match(/mlhs_add_star\(mlhs_add\(mlhs_new\(\),a\),b\)/, tree) assert_include(tree, "massign([a,*b]")
thru_mlhs_add_star = false thru_mlhs_add_star = false
tree = parse("a, *b, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true} tree = parse("a, *b, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star assert_equal true, thru_mlhs_add_star
assert_match(/mlhs_add\(mlhs_add_star\(mlhs_add\(mlhs_new\(\),a\),b\),mlhs_add\(mlhs_new\(\),c\)\)/, tree, bug2232) assert_include(tree, "massign([a,*b,[c]]", bug2232)
thru_mlhs_add_star = false thru_mlhs_add_star = false
tree = parse("a, *, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true} tree = parse("a, *, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star assert_equal true, thru_mlhs_add_star
assert_match(/mlhs_add\(mlhs_add_star\(mlhs_add\(mlhs_new\(\),a\)\),mlhs_add\(mlhs_new\(\),c\)\)/, tree, bug4364) assert_include(tree, "massign([a,*,[c]]", bug4364)
thru_mlhs_add_star = false thru_mlhs_add_star = false
tree = parse("*b, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true} tree = parse("*b, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star assert_equal true, thru_mlhs_add_star
assert_match(/mlhs_add\(mlhs_add_star\(mlhs_new\(\),b\),mlhs_add\(mlhs_new\(\),c\)\)/, tree, bug4364) assert_include(tree, "massign([*b,[c]]", bug4364)
thru_mlhs_add_star = false thru_mlhs_add_star = false
tree = parse("*, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true} tree = parse("*, c = 1, 2", :on_mlhs_add_star) {thru_mlhs_add_star = true}
assert_equal true, thru_mlhs_add_star assert_equal true, thru_mlhs_add_star
assert_match(/mlhs_add\(mlhs_add_star\(mlhs_new\(\)\),mlhs_add\(mlhs_new\(\),c\)\)/, tree, bug4364) assert_include(tree, "massign([*,[c]],", bug4364)
end end
def test_mlhs_new def test_mlhs_new