[ruby/rdoc] fix: fix NoMethodError when token_stream is nil

The change in #1055 might be a breaking change.
So, just simply wrap `token_stream` with `Array`

https://github.com/ruby/rdoc/commit/d8c19d7fa1

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
This commit is contained in:
toshimaru 2023-11-20 08:47:52 +09:00 committed by git
parent 09ce41a01e
commit cda431f538
2 changed files with 9 additions and 2 deletions

View File

@ -105,14 +105,14 @@ module RDoc::TokenStream
# Current token stream
def token_stream
@token_stream || []
@token_stream
end
##
# Returns a string representation of the token stream
def tokens_to_s
token_stream.compact.map { |token| token[:text] }.join ''
Array(token_stream).compact.map { |token| token[:text] }.join ''
end
end

View File

@ -39,6 +39,13 @@ class TestRDocTokenStream < RDoc::TestCase
assert_equal '', RDoc::TokenStream.to_html([])
end
def test_token_stream
foo = Class.new do
include RDoc::TokenStream
end.new
assert_equal nil, foo.token_stream
end
def test_tokens_to_s
foo = Class.new do
include RDoc::TokenStream