diff --git a/lib/bitclust/entry.rb b/lib/bitclust/entry.rb index edc0375..07230ac 100644 --- a/lib/bitclust/entry.rb +++ b/lib/bitclust/entry.rb @@ -175,11 +175,17 @@ def display_text(text) def description_text(text) text = display_text(text) return text unless text + # module function の ".#" は表示専用なので、DB バージョンが 4.0 以降なら + # "?." で表示する(RDCompiler#display_spec と同じ #250/#282 の規則。 + # ここは可視ページを通さない meta description 用の経路なので、bracket_link + # と同じ変換を独立に適用する必要がある。spec・URL・アンカーキーは不変) + version = @db&.propget('version') text = text.split("\n").map(&:strip).join("\n") .gsub(/(\P{ascii})\n(?=\P{ascii})/) { $1 || raise } .tr("\n", ' ') text.gsub(BracketLink) {|link| - ((link[2..-3] || raise).split(':', 2).last || raise).rstrip + label = ((link[2..-3] || raise).split(':', 2).last || raise).rstrip + label.include?('.#') ? label.sub('.#', NameUtils.display_typemark('.#', version)) : label } end private :description_text diff --git a/test/test_methodentry.rb b/test/test_methodentry.rb index 2072d7a..6742226 100644 --- a/test/test_methodentry.rb +++ b/test/test_methodentry.rb @@ -148,6 +148,39 @@ def test_instance_method_and_special_variable_display_are_unaffected_by_version end end +# meta description(コンパイラを通さない表示テキスト)内の module function +# 参照 [[m:Kernel.#mf2]] のラベルも、可視ページの bracket_link と同様に +# DB バージョン 4.0 以降では "?." で表示する(bitclust#282/#283 の続き。 +# 従来この経路だけ ".#" のまま残っていた) +class TestMethodEntryDescriptionQdot < Test::Unit::TestCase + SRC = < version}) + db.get_method(BitClust::MethodSpec.parse('Kernel.#mf')).description + end + + def test_meta_description_keeps_dot_hash_before_4_0 + assert_equal('Kernel.#mf2 を参照してください。', description('3.4')) + end + + def test_meta_description_uses_question_dot_at_4_0 + assert_equal('Kernel?.mf2 を参照してください。', description('4.0')) + end +end + # メソッド名別の since/until (bitclust#132 P1)。 # # テストリスト: