[ruby/yarp] Fixes so `bundle exec rake` can run on JRuby and TruffleRuby

https://github.com/ruby/yarp/commit/e6cea4fa08
This commit is contained in:
Benoit Daloze 2023-08-12 19:21:35 +02:00 коммит произвёл Takashi Kokubun
Родитель 958ac8d586
Коммит 3536cad902
5 изменённых файлов: 17 добавлений и 12 удалений

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

@ -47,9 +47,9 @@ module YARP
Ripper::PARSER_EVENT_TABLE.each do |event, arity| Ripper::PARSER_EVENT_TABLE.each do |event, arity|
case event case event
when /_new\z/ 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/ when /_add\z/
alias :"on_#{event}" :_dispatch_event_push alias_method :"on_#{event}", :_dispatch_event_push
end end
end end
end end
@ -168,7 +168,7 @@ module YARP
def _dispatch7(_, _, _, _, _, _, _); end def _dispatch7(_, _, _, _, _, _, _); end
(Ripper::SCANNER_EVENT_TABLE.merge(Ripper::PARSER_EVENT_TABLE)).each do |event, arity| (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 end
end end

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

@ -52,7 +52,7 @@ class CommentsTest < Test::Unit::TestCase
def assert_comment(source, type, location) def assert_comment(source, type, location)
result = YARP.parse(source) result = YARP.parse(source)
assert result.errors.empty?, result.errors.map(&:message).join("\n") 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.start_offset, location.begin
assert_equal result.comments.first.location.end_offset, location.end assert_equal result.comments.first.location.end_offset, location.end
end end

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

@ -1097,10 +1097,11 @@ class ErrorsTest < Test::Unit::TestCase
private private
def assert_errors(expected, source, errors) 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.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_nodes(expected, node, compare_location: false)
assert_equal(errors, result.errors.map { |e| [e.message, e.location.start_offset..e.location.end_offset] }) 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 end
def expression(source) def expression(source)
YARP.parse(source) => YARP::ParseResult[value: YARP::ProgramNode[statements: YARP::StatementsNode[body: [*, node]]]] YARP.parse(source).value.statements.body.last
node
end end
end end

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

@ -753,9 +753,11 @@ module YARP
private private
def assert_location(kind, source, expected = 0...source.length) 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? node = yield node if block_given?
assert_kind_of kind, node assert_kind_of kind, node

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

@ -23,7 +23,8 @@ class ParseTest < Test::Unit::TestCase
end end
def test_empty_string 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 end
known_failures = %w[ 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 # Finally, assert that we can lex the source and get the same tokens as
# Ripper. # Ripper.
YARP.lex_compat(source) => { errors: [], value: tokens } lex_result = YARP.lex_compat(source)
assert_equal [], lex_result.errors
tokens = lex_result.value
begin begin
YARP.lex_ripper(source).zip(tokens).each do |(ripper, yarp)| YARP.lex_ripper(source).zip(tokens).each do |(ripper, yarp)|