From cc71e2344b21e6d9931e7bdd4434c08c56a8ea00 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 30 Aug 2023 10:40:29 -0400 Subject: [PATCH] [ruby/yarp] Revisit lex.rake, make lex:rubygems more useable https://github.com/ruby/yarp/commit/4c76f4a0c0 --- test/yarp/desugar_visitor_test.rb | 6 +++--- test/yarp/fuzzer_test.rb | 2 +- test/yarp/test_helper.rb | 17 ----------------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/test/yarp/desugar_visitor_test.rb b/test/yarp/desugar_visitor_test.rb index 4dee182ef1..c03b02e67a 100644 --- a/test/yarp/desugar_visitor_test.rb +++ b/test/yarp/desugar_visitor_test.rb @@ -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) diff --git a/test/yarp/fuzzer_test.rb b/test/yarp/fuzzer_test.rb index 61845b91f7..384f3ff0d2 100644 --- a/test/yarp/fuzzer_test.rb +++ b/test/yarp/fuzzer_test.rb @@ -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 diff --git a/test/yarp/test_helper.rb b/test/yarp/test_helper.rb index 49587e3b03..b79adf4b16 100644 --- a/test/yarp/test_helper.rb +++ b/test/yarp/test_helper.rb @@ -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