Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/code_object/top_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize(absolute_name, relative_name = absolute_name)

def parser=(val)
@parser = val
@store.update_parser_of_file(absolute_name, val) if @store
@store.update_parser_of_file(relative_name, val) if @store
@parser
end

Expand Down
8 changes: 4 additions & 4 deletions lib/rdoc/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ def resolve_c_superclasses
end

##
# Sets the parser of +absolute_name+, unless it from a source code file.
# Sets the parser of +relative_name+, unless it from a source code file.

def update_parser_of_file(absolute_name, parser)
if top_level = @files_hash[absolute_name] then
@text_files_hash[absolute_name] = top_level if top_level.text?
def update_parser_of_file(relative_name, parser)
if top_level = @files_hash[relative_name] then
@text_files_hash[relative_name] = top_level if top_level.text?
Comment on lines +324 to +328
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method comment is inaccurate/grammatically incorrect: update_parser_of_file does not “set the parser”, it only updates @text_files_hash based on top_level.text? (and the sentence is missing “is”: “unless it is from ...”). Also, the parser parameter is unused; consider removing it or renaming to _parser to make the intent clear.

Copilot uses AI. Check for mistakes.
end
end

Expand Down
74 changes: 74 additions & 0 deletions test/rdoc/rdoc_server_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frozen_string_literal: true
require_relative 'support/test_case'

class RDocServerTest < RDoc::TestCase

def setup
super

@dir = Dir.mktmpdir("test_rdoc_server_")

File.write File.join(@dir, "PAGE.md"), "# A Page\n\nSome content.\n"
File.write File.join(@dir, "NOTES.rdoc"), "= Notes\n\nSome notes.\n"
File.write File.join(@dir, "example.rb"), "# A class\nclass Example; end\n"

@options.files = [@dir]
@options.op_dir = File.join(@dir, "_site")
@options.root = Pathname(@dir)
@options.verbosity = 0
@options.finish

@rdoc.options = @options
@rdoc.store = RDoc::Store.new(@options)

capture_output do
@rdoc.parse_files @options.files
end
@rdoc.store.complete @options.visibility

@server = RDoc::Server.new(@rdoc, 0)
end

def teardown
FileUtils.rm_rf @dir
super
end

def test_route_serves_text_page
status, content_type, body = @server.send(:route, '/PAGE_md.html')

assert_equal 200, status
assert_equal 'text/html', content_type
assert_include body, 'A Page'
end

def test_route_serves_rdoc_text_page
status, content_type, body = @server.send(:route, '/NOTES_rdoc.html')

assert_equal 200, status
assert_equal 'text/html', content_type
assert_include body, 'Notes'
end

def test_route_serves_class_page
status, content_type, body = @server.send(:route, '/Example.html')

assert_equal 200, status
assert_equal 'text/html', content_type
assert_include body, 'Example'
end

def test_route_serves_index
status, content_type, _body = @server.send(:route, '/')

assert_equal 200, status
assert_equal 'text/html', content_type
end

def test_route_returns_404_for_missing_page
status, content_type, _body = @server.send(:route, '/nonexistent.html')

assert_equal 404, status
assert_equal 'text/html', content_type
end
end
7 changes: 7 additions & 0 deletions test/rdoc/rdoc_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ def test_find_text_page
assert_equal page, @store.find_text_page('PAGE.txt')
end

def test_find_text_page_when_parser_set_after_add_file
page = @store.add_file '/absolute/path/to/PAGE.md', relative_name: 'PAGE.md'
page.parser = RDoc::Parser::Simple

assert_equal page, @store.find_text_page('PAGE.md')
end

def test_friendly_path
@orig_xdg_data_home = ENV.delete('XDG_DATA_HOME')

Expand Down
Loading