Skip to content

Commit

Permalink
Add hash equality to Section
Browse files Browse the repository at this point in the history
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
  • Loading branch information
drbrain committed Mar 17, 2016
1 parent d6fe615 commit 1b5e454
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions History.rdoc
Expand Up @@ -2,6 +2,8 @@

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

=== 4.2.2 / 2016-02-09

Expand Down
6 changes: 6 additions & 0 deletions lib/rdoc/context/section.rb
Expand Up @@ -57,6 +57,8 @@ def == other
self.class === other and @title == other.title
end

alias eql? ==

##
# Adds +comment+ to this section

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

def hash # :nodoc:
@title.hash
end

##
# The files comments in this section come from

Expand Down
24 changes: 24 additions & 0 deletions test/test_rdoc_context_section.rb
Expand Up @@ -47,6 +47,22 @@ def test_aref
assert_equal 'one+two', @S.new(nil, 'one two', nil).aref
end

def test_eql_eh
other = @S.new @klass, 'other', comment('# comment', @top_level)

assert @s.eql? @s
assert @s.eql? @s.dup
refute @s.eql? other
end

def test_equals
other = @S.new @klass, 'other', comment('# comment', @top_level)

assert_equal @s, @s
assert_equal @s, @s.dup
refute_equal @s, other
end

def test_extract_comment
assert_equal '', @s.extract_comment(comment('')).text
assert_equal '', @s.extract_comment(comment("# :section: b\n")).text
Expand All @@ -55,6 +71,14 @@ def test_extract_comment
@s.extract_comment(comment("# a\n# :section: b\n# c")).text
end

def test_hash
other = @S.new @klass, 'other', comment('# comment', @top_level)

assert_equal @s.hash, @s.hash
assert_equal @s.hash, @s.dup.hash
refute_equal @s.hash, other.hash
end

def test_marshal_dump
loaded = Marshal.load Marshal.dump @s

Expand Down

0 comments on commit 1b5e454

Please sign in to comment.