Skip to content

Commit

Permalink
Added AST tests for endless method definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jan 1, 2021
1 parent de5f8a9 commit 1e51027
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/ruby/test_ast.rb
Expand Up @@ -255,6 +255,15 @@ def test_defn
assert_equal(:SCOPE, defn.type)
end

def test_defn_endless
node = RubyVM::AbstractSyntaxTree.parse("def a = nil")
_, _, body = *node.children
assert_equal(:DEFN, body.type)
mid, defn = body.children
assert_equal(:a, mid)
assert_equal(:SCOPE, defn.type)
end

def test_defs
node = RubyVM::AbstractSyntaxTree.parse("def a.b; end")
_, _, body = *node.children
Expand All @@ -265,6 +274,16 @@ def test_defs
assert_equal(:SCOPE, defn.type)
end

def test_defs_endless
node = RubyVM::AbstractSyntaxTree.parse("def a.b = nil")
_, _, body = *node.children
assert_equal(:DEFS, body.type)
recv, mid, defn = body.children
assert_equal(:VCALL, recv.type)
assert_equal(:b, mid)
assert_equal(:SCOPE, defn.type)
end

def test_dstr
node = parse('"foo#{1}bar"')
_, _, body = *node.children
Expand Down

0 comments on commit 1e51027

Please sign in to comment.