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
12 changes: 10 additions & 2 deletions lib/bitclust/simplesearcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ def parse_method_spec_pattern(pat)
end
return pat, nil, nil if /\A[A-Z]\w*\z/ =~ pat
return nil, '$', $1 if /\$(\S*)/ =~ pat
_m, _t, _c = pat.reverse.split(/(::|[\#,]\.|\.[\#,]|[\#\.\,])/, 2)
# bitclust#250: "?." is an alternate spelling of the module-function
# separator ".#" (Ruby >=4.0 docs display it that way since #277; see
# NameUtils.display_typemark). Accept it here regardless of which
# Ruby version the query is about -- this is query *input*, not
# display, so both notations are always accepted. "?" is added to the
# same reversed-pattern alternative that already matches "#." and ",."
# (a marker character immediately followed by ".", read in the
# reversed pattern), so "?." matches the same way "#." already does.
_m, _t, _c = pat.reverse.split(/(::|[\#,]\.|\.[\#,\?]|[\#\.\,])/, 2)
_m || raise
c = _c.reverse if _c
t = _t.tr(',', '#').sub(/\#\./, '.#') if _t
t = _t.tr(',?', '##').sub(/\#\./, '.#') if _t
m = _m.reverse
return c, t, m
end
Expand Down
28 changes: 28 additions & 0 deletions test/test_simplesearcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def setup
== Class Methods
--- bar
= reopen Kernel
== Module Functions
--- open

== Instance Methods
--- puts

== Special Variables
--- $spespe

Expand Down Expand Up @@ -45,4 +51,26 @@ def test_simple_search
assert_equal([], search_pattern(@db, " "), 'space')
assert_equal([], search_pattern(@db, ""), 'blank')
end

# bitclust#250 follow-up: the dynamic server's /search accepts free-text
# queries, and a module function may be typed in either notation --
# "Kernel.#open" (bitclust's own internal spec-string form, still what
# docs for Ruby < 4.0 display) or "Kernel?.open" (what docs for Ruby >=
# 4.0 display since #277). Both must resolve to the same method,
# regardless of which notation the *query* uses -- the query parser has
# no idea (and shouldn't need to know) which doc version the user is
# thinking of.
def test_module_function_query_notation
[['Kernel?.open', 'open'], # new (>=4.0 display) notation
['Kernel.#open', 'open'], # existing (bitclust-internal) notation: regression check
['?.open', 'open'], # bare module-function marker, no class name
['Kernel#puts', 'puts'], # instance method: unaffected by the "?." change
].each{|q, expected|
ret = search_pattern(@db, q)
assert_not_equal([], ret, q)
assert_equal(expected, ret[0].name, q)
}
# Singleton-method dot notation ('Hoge.h' => 'hoge' in test_simple_search
# above) is also unaffected; kept there rather than duplicated here.
end
end
Loading