Skip to content

Commit

Permalink
[ruby/rdoc] fix: fix NoMethodError when token_stream is nil
Browse files Browse the repository at this point in the history
The change in #1055 might be a breaking change.
So, just simply wrap `token_stream` with `Array`

ruby/rdoc@d8c19d7fa1

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
  • Loading branch information
2 people authored and matzbot committed Dec 5, 2023
1 parent 09ce41a commit cda431f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rdoc/token_stream.rb
Expand Up @@ -105,14 +105,14 @@ def pop_token
# 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
7 changes: 7 additions & 0 deletions test/rdoc/test_rdoc_token_stream.rb
Expand Up @@ -39,6 +39,13 @@ def test_class_to_html_empty
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
Expand Down

0 comments on commit cda431f

Please sign in to comment.