diff --git a/lib/yarp/ripper_compat.rb b/lib/yarp/ripper_compat.rb index f29f7a1bf1..c76f3fd07a 100644 --- a/lib/yarp/ripper_compat.rb +++ b/lib/yarp/ripper_compat.rb @@ -47,9 +47,9 @@ module YARP Ripper::PARSER_EVENT_TABLE.each do |event, arity| case event when /_new\z/ - alias :"on_#{event}" :_dispatch_event_new if arity == 0 + alias_method :"on_#{event}", :_dispatch_event_new if arity == 0 when /_add\z/ - alias :"on_#{event}" :_dispatch_event_push + alias_method :"on_#{event}", :_dispatch_event_push end end end @@ -168,7 +168,7 @@ module YARP def _dispatch7(_, _, _, _, _, _, _); end (Ripper::SCANNER_EVENT_TABLE.merge(Ripper::PARSER_EVENT_TABLE)).each do |event, arity| - alias :"on_#{event}" :"_dispatch#{arity}" + alias_method :"on_#{event}", :"_dispatch#{arity}" end end end diff --git a/test/yarp/comments_test.rb b/test/yarp/comments_test.rb index e22dffd46d..5c49f7b86e 100644 --- a/test/yarp/comments_test.rb +++ b/test/yarp/comments_test.rb @@ -52,7 +52,7 @@ class CommentsTest < Test::Unit::TestCase def assert_comment(source, type, location) result = YARP.parse(source) assert result.errors.empty?, result.errors.map(&:message).join("\n") - result => YARP::ParseResult[comments: [YARP::Comment[type: type]]] + assert_equal result.comments.first.type, type assert_equal result.comments.first.location.start_offset, location.begin assert_equal result.comments.first.location.end_offset, location.end end diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index 0777efe47a..e89ade0ba5 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -1097,10 +1097,11 @@ class ErrorsTest < Test::Unit::TestCase private def assert_errors(expected, source, errors) - assert_nil Ripper.sexp_raw(source) + # Ripper behaves differently on JRuby/TruffleRuby, so only check this on CRuby + assert_nil Ripper.sexp_raw(source) if RUBY_ENGINE == "ruby" result = YARP.parse(source) - result => YARP::ParseResult[value: YARP::ProgramNode[statements: YARP::StatementsNode[body: [*, node]]]] + node = result.value.statements.body.last assert_equal_nodes(expected, node, compare_location: false) assert_equal(errors, result.errors.map { |e| [e.message, e.location.start_offset..e.location.end_offset] }) @@ -1113,7 +1114,6 @@ class ErrorsTest < Test::Unit::TestCase end def expression(source) - YARP.parse(source) => YARP::ParseResult[value: YARP::ProgramNode[statements: YARP::StatementsNode[body: [*, node]]]] - node + YARP.parse(source).value.statements.body.last end end diff --git a/test/yarp/location_test.rb b/test/yarp/location_test.rb index 2f551949e5..2aaaa7aa76 100644 --- a/test/yarp/location_test.rb +++ b/test/yarp/location_test.rb @@ -753,9 +753,11 @@ module YARP private def assert_location(kind, source, expected = 0...source.length) - YARP.parse(source) => ParseResult[comments: [], errors: [], value: node] + result = YARP.parse(source) + assert_equal [], result.comments + assert_equal [], result.errors - node => ProgramNode[statements: [*, node]] + node = result.value.statements.body.last node = yield node if block_given? assert_kind_of kind, node diff --git a/test/yarp/parse_test.rb b/test/yarp/parse_test.rb index 91752cd483..43a1deb8fb 100644 --- a/test/yarp/parse_test.rb +++ b/test/yarp/parse_test.rb @@ -23,7 +23,8 @@ class ParseTest < Test::Unit::TestCase end def test_empty_string - YARP.parse("") => YARP::ParseResult[value: YARP::ProgramNode[statements: YARP::StatementsNode[body: []]]] + result = YARP.parse("") + assert_equal [], result.value.statements.body end known_failures = %w[ @@ -107,7 +108,9 @@ class ParseTest < Test::Unit::TestCase # Finally, assert that we can lex the source and get the same tokens as # Ripper. - YARP.lex_compat(source) => { errors: [], value: tokens } + lex_result = YARP.lex_compat(source) + assert_equal [], lex_result.errors + tokens = lex_result.value begin YARP.lex_ripper(source).zip(tokens).each do |(ripper, yarp)|