Skip to content
Merged
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
16 changes: 14 additions & 2 deletions lib/rdoc/code_object/method_attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def <=>(other)
return unless other.respond_to?(:singleton) &&
other.respond_to?(:name)

[ @singleton ? 0 : 1, name] <=>
[other.singleton ? 0 : 1, other.name]
[@singleton ? 0 : 1, name_codepoint_range, name] <=>
[other.singleton ? 0 : 1, other.name_codepoint_range, other.name]
end

def == other # :nodoc:
Expand Down Expand Up @@ -415,4 +415,16 @@ def to_s # :nodoc:
end
end

def name_codepoint_range # :nodoc:
case name.codepoints[0]
Copy link
Member

Choose a reason for hiding this comment

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

TIL codepoints

Copy link
Member

Choose a reason for hiding this comment

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

case name.ord

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you. See #1220

when 0..64 # anything below "A"
1
when 91..96 # the symbols between "Z" and "a"
2
when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
3
else # everythig else can be sorted as normal
4
end
end
end
28 changes: 27 additions & 1 deletion test/rdoc/test_rdoc_method_attr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,36 @@ def test_search_record
assert_equal expected, @c1_m.search_record
end

def test_spaceship
def test_spaceship_returns_nil_on_inappropriate_types
assert_nil @c1_m.<=>(RDoc::CodeObject.new)
end

def test_spaceship_orders_symbols_first
# in the desired sort order
m_plus = RDoc::AnyMethod.new nil, '+'
m_eqeq = RDoc::AnyMethod.new nil, '=='
m_bracket = RDoc::AnyMethod.new nil, '[]'
m_caret = RDoc::AnyMethod.new nil, '^'
m_bar = RDoc::AnyMethod.new nil, '|'
m_tilde = RDoc::AnyMethod.new nil, '~'
m_Alpha = RDoc::AnyMethod.new nil, 'Alpha'
m_Zero = RDoc::AnyMethod.new nil, 'Zero'
m_alpha = RDoc::AnyMethod.new nil, 'alpha'
m_zero = RDoc::AnyMethod.new nil, 'zero'
m_konnichiwa = RDoc::AnyMethod.new nil, 'こんにちは'

assert_equal(-1, m_plus <=> m_eqeq)
assert_equal(-1, m_eqeq <=> m_bracket)
assert_equal(-1, m_bracket <=> m_caret)
assert_equal(-1, m_caret <=> m_bar)
assert_equal(-1, m_bar <=> m_tilde)
assert_equal(-1, m_tilde <=> m_Alpha)
assert_equal(-1, m_Alpha <=> m_Zero)
assert_equal(-1, m_Zero <=> m_alpha)
assert_equal(-1, m_alpha <=> m_zero)
assert_equal(-1, m_zero <=> m_konnichiwa)
end

def test_equals2
assert_equal @c1_m, @c1_m
refute_equal @c1_m, @parent_m
Expand Down