diff options
| author | yui-knk <spiketeika@gmail.com> | 2024-07-22 16:28:00 +0900 |
|---|---|---|
| committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2024-07-23 14:35:23 +0900 |
| commit | 57b11be15ae518288b719fb36068ceb23da6e050 (patch) | |
| tree | 9a772e11ab2a75c86a3df1f83e67247751b1679e /test/ruby | |
| parent | f23485a8d693cb69fd7b84c1ab93cb4198ecfe4a (diff) | |
Implement UNLESS NODE keyword locations
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11227
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_ast.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 4c579287a9..e6edc111ef 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -1327,12 +1327,22 @@ dummy class TestLocation < Test::Unit::TestCase def test_lineno_and_column node = RubyVM::AbstractSyntaxTree.parse("1 + 2") - location = node.locations[0] + assert_locations(node.locations, [[1, 0, 1, 5]]) + end + + def test_unless_locations + node = RubyVM::AbstractSyntaxTree.parse("unless cond then 1 else 2 end") + assert_locations(node.children[-1].locations, [[1, 0, 1, 29], [1, 0, 1, 6], [1, 12, 1, 16], [1, 26, 1, 29]]) + + node = RubyVM::AbstractSyntaxTree.parse("1 unless 2") + assert_locations(node.children[-1].locations, [[1, 0, 1, 10], [1, 2, 1, 8], nil, nil]) + end + + private + def assert_locations(locations, expected) + ary = locations.map {|loc| loc && [loc.first_lineno, loc.first_column, loc.last_lineno, loc.last_column] } - assert_equal(1, location.first_lineno) - assert_equal(0, location.first_column) - assert_equal(1, location.last_lineno) - assert_equal(5, location.last_column) + assert_equal(ary, expected) end end end |
