[ruby/yarp] Revisit lex.rake, make lex:rubygems more useable

https://github.com/ruby/yarp/commit/4c76f4a0c0
This commit is contained in:
Kevin Newton 2023-08-30 10:40:29 -04:00 коммит произвёл git
Родитель c46858fd6a
Коммит cc71e2344b
3 изменённых файлов: 4 добавлений и 21 удалений

Просмотреть файл

@ -13,7 +13,7 @@ module YARP
assert_desugars("(AndNode (LocalVariableReadNode) (LocalVariableWriteNode (CallNode)))", "foo &&= bar")
assert_desugars("(AndNode (LocalVariableReadNode) (LocalVariableWriteNode (CallNode)))", "foo = 1; foo &&= bar")
end
def test_or_write
assert_desugars("(IfNode (DefinedNode (ClassVariableReadNode)) (StatementsNode (ClassVariableReadNode)) (ElseNode (StatementsNode (ClassVariableWriteNode (CallNode)))))", "@@foo ||= bar")
assert_desugars("(IfNode (DefinedNode (ConstantPathNode (ConstantReadNode) (ConstantReadNode))) (StatementsNode (ConstantPathNode (ConstantReadNode) (ConstantReadNode))) (ElseNode (StatementsNode (ConstantPathWriteNode (ConstantPathNode (ConstantReadNode) (ConstantReadNode)) (CallNode)))))", "Foo::Bar ||= baz")
@ -23,7 +23,7 @@ module YARP
assert_desugars("(OrNode (LocalVariableReadNode) (LocalVariableWriteNode (CallNode)))", "foo ||= bar")
assert_desugars("(OrNode (LocalVariableReadNode) (LocalVariableWriteNode (CallNode)))", "foo = 1; foo ||= bar")
end
def test_operator_write
assert_desugars("(ClassVariableWriteNode (CallNode (ClassVariableReadNode) (ArgumentsNode (CallNode))))", "@@foo += bar")
assert_desugars("(ConstantPathWriteNode (ConstantPathNode (ConstantReadNode) (ConstantReadNode)) (CallNode (ConstantPathNode (ConstantReadNode) (ConstantReadNode)) (ArgumentsNode (CallNode))))", "Foo::Bar += baz")
@ -33,7 +33,7 @@ module YARP
assert_desugars("(LocalVariableWriteNode (CallNode (LocalVariableReadNode) (ArgumentsNode (CallNode))))", "foo += bar")
assert_desugars("(LocalVariableWriteNode (CallNode (LocalVariableReadNode) (ArgumentsNode (CallNode))))", "foo = 1; foo += bar")
end
private
def ast_inspect(node)

Просмотреть файл

@ -4,7 +4,7 @@ require_relative "test_helper"
module YARP
# These tests are simply to exercise snippets found by the fuzzer that caused invalid memory access.
class FuzzerTest < Test::Unit::TestCase
class FuzzerTest < TestCase
def self.snippet(name, source)
define_method(:"test_fuzzer_#{name}") { YARP.dump(source) }
end

Просмотреть файл

@ -83,22 +83,5 @@ module YARP
assert_equal expected, actual
end
end
def assert_valid_locations(value, parent: nil)
case value
when Array
value.each do |element|
assert_valid_locations(element, parent: value)
end
when Node
value.deconstruct_keys(nil).each_value do |field|
assert_valid_locations(field, parent: value)
end
when Location
assert_operator value.start_offset, :<=, value.end_offset, -> {
"start_offset > end_offset for #{value.inspect}, parent is #{parent.pretty_inspect}"
}
end
end
end
end