Skip to content

Commit

Permalink
Fix wrong test for class defined inside singleton class
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Feb 1, 2025
1 parent c5d96a8 commit 25f1df9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/rdoc/test_rdoc_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def setup
@mod.record_location @top_level
end

def using_prism_ruby_parser?
RDoc::Parser::Ruby.name == 'RDoc::Parser::PrismRuby'
end

def teardown
super

Expand Down Expand Up @@ -161,13 +165,17 @@ def test_add_file_relative

def test_all_classes_and_modules
expected = %w[
C1 C10 C10::C11 C11 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C8::S1 C9 C9::A C9::B
C1 C10 C10::C11 C11 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C9 C9::A C9::B
Child
M1 M1::M2
Object
Parent
]

# C8::S1 does not exist. It should not be in the list.
# class C8; class << something; class S1; end; end; end
expected = (expected + ['C8::S1']).sort unless using_prism_ruby_parser?

assert_equal expected,
@store.all_classes_and_modules.map { |m| m.full_name }.sort
end
Expand Down Expand Up @@ -213,12 +221,16 @@ def test_class_path

def test_classes
expected = %w[
C1 C10 C10::C11 C11 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C8::S1 C9 C9::A C9::B
C1 C10 C10::C11 C11 C2 C2::C3 C2::C3::H1 C3 C3::H1 C3::H2 C4 C4::C4 C5 C5::C1 C6 C7 C8 C9 C9::A C9::B
Child
Object
Parent
]

# C8::S1 does not exist. It should not be in the list.
# class C8; class << something; class S1; end; end; end
expected = (expected + ['C8::S1']).sort unless using_prism_ruby_parser?

assert_equal expected, @store.all_classes.map { |m| m.full_name }.sort
end

Expand Down Expand Up @@ -550,6 +562,13 @@ def test_load_class
end

def test_load_single_class
if using_prism_ruby_parser?
# Class defined inside singleton class is not documentable.
# @c8_s1 should be nil because C8::S1 does not exist.
assert_nil @c8_s1
return
end

@s.save_class @c8_s1
@s.classes_hash.clear

Expand Down
1 change: 1 addition & 0 deletions test/rdoc/xref_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class C7
class C8
class << self
# This is C8.singleton_class::S1. C8::S1 does not exist.
class S1
end
end
Expand Down

0 comments on commit 25f1df9

Please # to comment.