Skip to content

Commit 1b5e454

Browse files
committed
Add hash equality to Section
When an item is not in any section it ends up in the nil section. Unfortunately RDoc creates a separate Section object between grouping and display time which would cause items to disappear from a section at HTML generation time. Now that two Section objects with the same title map to the same Hash key the constants will not disappear. Fixes bug #399
1 parent d6fe615 commit 1b5e454

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Bug fixes
44
* Ensure badge data is included in result of JsonIndex template.
5+
* Ensure items in the nil section are displayed in HTML output. Issue #399
6+
by Daniel Svensson.
57

68
=== 4.2.2 / 2016-02-09
79

lib/rdoc/context/section.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def == other
5757
self.class === other and @title == other.title
5858
end
5959

60+
alias eql? ==
61+
6062
##
6163
# Adds +comment+ to this section
6264

@@ -127,6 +129,10 @@ def inspect # :nodoc:
127129
"#<%s:0x%x %p>" % [self.class, object_id, title]
128130
end
129131

132+
def hash # :nodoc:
133+
@title.hash
134+
end
135+
130136
##
131137
# The files comments in this section come from
132138

test/test_rdoc_context_section.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ def test_aref
4747
assert_equal 'one+two', @S.new(nil, 'one two', nil).aref
4848
end
4949

50+
def test_eql_eh
51+
other = @S.new @klass, 'other', comment('# comment', @top_level)
52+
53+
assert @s.eql? @s
54+
assert @s.eql? @s.dup
55+
refute @s.eql? other
56+
end
57+
58+
def test_equals
59+
other = @S.new @klass, 'other', comment('# comment', @top_level)
60+
61+
assert_equal @s, @s
62+
assert_equal @s, @s.dup
63+
refute_equal @s, other
64+
end
65+
5066
def test_extract_comment
5167
assert_equal '', @s.extract_comment(comment('')).text
5268
assert_equal '', @s.extract_comment(comment("# :section: b\n")).text
@@ -55,6 +71,14 @@ def test_extract_comment
5571
@s.extract_comment(comment("# a\n# :section: b\n# c")).text
5672
end
5773

74+
def test_hash
75+
other = @S.new @klass, 'other', comment('# comment', @top_level)
76+
77+
assert_equal @s.hash, @s.hash
78+
assert_equal @s.hash, @s.dup.hash
79+
refute_equal @s.hash, other.hash
80+
end
81+
5882
def test_marshal_dump
5983
loaded = Marshal.load Marshal.dump @s
6084

0 commit comments

Comments
 (0)