summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoshimaru <[email protected]>2023-11-20 08:47:52 +0900
committergit <[email protected]>2023-12-05 06:21:51 +0000
commitcda431f5388e8359532998c7fbf5fa615ce6d45e (patch)
treef4069ddfd530954e572b0ab3634f3838240af3f5
parent09ce41a01eeb12d0887e7edb9b499e81fe4da99f (diff)
[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 <[email protected]>
-rw-r--r--lib/rdoc/token_stream.rb4
-rw-r--r--test/rdoc/test_rdoc_token_stream.rb7
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/rdoc/token_stream.rb b/lib/rdoc/token_stream.rb
index 1ff4b0d09e..ea8d9417cc 100644
--- a/lib/rdoc/token_stream.rb
+++ b/lib/rdoc/token_stream.rb
@@ -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
diff --git a/test/rdoc/test_rdoc_token_stream.rb b/test/rdoc/test_rdoc_token_stream.rb
index dafbe22323..4a0ddb9fec 100644
--- a/test/rdoc/test_rdoc_token_stream.rb
+++ b/test/rdoc/test_rdoc_token_stream.rb
@@ -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