Skip to content

Commit

Permalink
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`

Co-authored-by: Jonathan Hefner <[email protected]>
  • Loading branch information
toshimaru and jonathanhefner committed Nov 21, 2023
1 parent 72897d3 commit 604dc16
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 604dc16

Please sign in to comment.