Skip to content

Commit b0f88c1

Browse files
committed
Tighten RBS test suite: consolidate redundant variants, strengthen weak assertions
Six edits driven by a focused review of the PR's 44 added tests: * Drop test_method_without_type_signature — pure default-state check that was redundant with every other parser test using a sig-less sibling. * Drop test_merge_rbs_signatures_unmatched_key — exercised built-in Hash semantics rather than store behavior. * Replace six per-type-form tests (union/optional/tuple/intersection/proc/ block) with one data-driven test that iterates the same six shapes. Same coverage, ~50 fewer lines. * Strengthen test_signature_to_html_multiline — previously asserted only that a newline appeared somewhere; now asserts ordered structure of each rendered line. * Strengthen test_type_signature_invalid_still_stored_and_warns — asserts the parser emits the documented "invalid RBS type signature" warning in addition to keeping the malformed sig. * Re-target test_merge_rbs_signatures_clears_signatures_removed_in_subsequent_merge (formerly _replaces_previous_rbs_signature) to verify that a key REMOVED in a later merge clears the signature — the actual property clear_rbs_signatures was added for. Net: 44 PR-added tests -> 37, same or stronger coverage.
1 parent 91b8bfa commit b0f88c1

3 files changed

Lines changed: 48 additions & 89 deletions

File tree

test/rdoc/parser/ruby_test.rb

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,20 +2696,6 @@ def convert(value); end
26962696
assert_equal 'Convert a value', convert.comment.text.strip
26972697
end
26982698

2699-
def test_method_without_type_signature
2700-
util_parser <<~RUBY
2701-
class Foo
2702-
# A plain method
2703-
def plain; end
2704-
end
2705-
RUBY
2706-
2707-
klass = @store.find_class_named 'Foo'
2708-
plain = klass.method_list.first
2709-
assert_nil plain.type_signature_lines
2710-
assert_equal 'A plain method', plain.comment.text.strip
2711-
end
2712-
27132699
def test_method_type_signature_with_blank_line_separation
27142700
util_parser <<~RUBY
27152701
class Foo
@@ -2726,18 +2712,24 @@ def bar(x); end
27262712
assert_equal "Documentation here", bar.comment.text
27272713
end
27282714

2729-
def test_type_signature_invalid_still_stored
2730-
util_parser <<~RUBY
2731-
class Foo
2732-
#: (String ->
2733-
def bar(x); end
2734-
end
2735-
RUBY
2715+
def test_type_signature_invalid_still_stored_and_warns
2716+
@options.verbosity = 2
2717+
_out, err = capture_output do
2718+
util_parser <<~RUBY
2719+
class Foo
2720+
#: (String ->
2721+
def bar(x); end
2722+
end
2723+
RUBY
2724+
end
27362725

27372726
klass = @store.find_class_named 'Foo'
27382727
bar = klass.method_list.first
2739-
# Invalid sigs are still stored (don't block display)
2728+
# Invalid sigs are still stored so the doc author can see what they typed.
27402729
assert_equal ['(String ->'], bar.type_signature_lines
2730+
# ...but a warning must be emitted so it doesn't slip through silently.
2731+
# The format includes the file and line so authors can find the typo.
2732+
assert_match %r{:\d+: invalid RBS type signature: "\(String ->"}, err
27412733
end
27422734

27432735
def util_parser(content)

test/rdoc/rbs_helper_test.rb

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -97,56 +97,34 @@ def test_signature_to_html_multiline
9797
lookup = { 'String' => 'String.html', 'Integer' => 'Integer.html' }
9898
result = RDoc::RbsHelper.signature_to_html(["(String) -> Integer", "(Integer) -> String"], lookup: lookup, from_path: 'Test.html')
9999

100-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
101-
assert_includes result, '<a href="Integer.html" class="rbs-type">Integer</a>'
102-
assert_includes result, "\n"
103-
end
104-
105-
def test_signature_to_html_union_type
106-
lookup = { 'String' => 'String.html', 'Integer' => 'Integer.html' }
107-
result = RDoc::RbsHelper.signature_to_html(["(String | Integer) -> void"], lookup: lookup, from_path: 'Test.html')
108-
109-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
110-
assert_includes result, '<a href="Integer.html" class="rbs-type">Integer</a>'
111-
end
112-
113-
def test_signature_to_html_optional_type
114-
lookup = { 'String' => 'String.html' }
115-
result = RDoc::RbsHelper.signature_to_html(["String?"], lookup: lookup, from_path: 'Test.html')
116-
117-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
118-
end
119-
120-
def test_signature_to_html_tuple_type
121-
lookup = { 'String' => 'String.html', 'Integer' => 'Integer.html' }
122-
result = RDoc::RbsHelper.signature_to_html(["[String, Integer]"], lookup: lookup, from_path: 'Test.html')
123-
124-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
125-
assert_includes result, '<a href="Integer.html" class="rbs-type">Integer</a>'
126-
end
127-
128-
def test_signature_to_html_intersection_type
129-
lookup = { 'String' => 'String.html', 'Comparable' => 'Comparable.html' }
130-
result = RDoc::RbsHelper.signature_to_html(["(String & Comparable) -> void"], lookup: lookup, from_path: 'Test.html')
131-
132-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
133-
assert_includes result, '<a href="Comparable.html" class="rbs-type">Comparable</a>'
134-
end
135-
136-
def test_signature_to_html_proc_type
137-
lookup = { 'String' => 'String.html', 'Integer' => 'Integer.html' }
138-
result = RDoc::RbsHelper.signature_to_html(["^(String) -> Integer"], lookup: lookup, from_path: 'Test.html')
139-
140-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
141-
assert_includes result, '<a href="Integer.html" class="rbs-type">Integer</a>'
142-
end
143-
144-
def test_signature_to_html_links_block_return_type
145-
lookup = { 'String' => 'String.html', 'Integer' => 'Integer.html' }
146-
result = RDoc::RbsHelper.signature_to_html(["() { (String) -> Integer } -> void"], lookup: lookup, from_path: 'Test.html')
147-
148-
assert_includes result, '<a href="String.html" class="rbs-type">String</a>'
149-
assert_includes result, '<a href="Integer.html" class="rbs-type">Integer</a>'
100+
first, second = result.split("\n", 2)
101+
assert_match %r{<a href="String\.html"[^>]*>String</a>.*&rarr;.*<a href="Integer\.html"[^>]*>Integer</a>}, first
102+
assert_match %r{<a href="Integer\.html"[^>]*>Integer</a>.*&rarr;.*<a href="String\.html"[^>]*>String</a>}, second
103+
end
104+
105+
def test_signature_to_html_links_types_inside_compound_forms
106+
lookup = {
107+
'String' => 'String.html',
108+
'Integer' => 'Integer.html',
109+
'Comparable' => 'Comparable.html',
110+
}
111+
112+
cases = [
113+
['union', "(String | Integer) -> void", %w[String Integer]],
114+
['optional', "String?", %w[String]],
115+
['tuple', "[String, Integer]", %w[String Integer]],
116+
['intersection', "(String & Comparable) -> void", %w[String Comparable]],
117+
['proc', "^(String) -> Integer", %w[String Integer]],
118+
['block', "() { (String) -> Integer } -> void", %w[String Integer]],
119+
]
120+
121+
cases.each do |form, sig, expected_types|
122+
result = RDoc::RbsHelper.signature_to_html([sig], lookup: lookup, from_path: 'Test.html')
123+
expected_types.each do |type|
124+
assert_includes result, %(<a href="#{lookup[type]}" class="rbs-type">#{type}</a>),
125+
"#{form} signature #{sig.inspect} did not link #{type}"
126+
end
127+
end
150128
end
151129

152130
def test_signature_to_html_unparseable_signature

test/rdoc/rdoc_store_test.rb

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,16 +1326,16 @@ def test_merge_rbs_signatures_constructor
13261326
assert_equal ['(String name) -> void'], ctor.type_signature_lines
13271327
end
13281328

1329-
def test_merge_rbs_signatures_replaces_previous_rbs_signature
1329+
def test_merge_rbs_signatures_clears_signatures_removed_in_subsequent_merge
13301330
@s.merge_rbs_signatures(
13311331
'Object#method' => ['() -> String']
13321332
)
1333+
assert_equal ['() -> String'], @meth.type_signature_lines
13331334

1334-
@s.merge_rbs_signatures(
1335-
'Object#method' => ['() -> Integer']
1336-
)
1337-
1338-
assert_equal ['() -> Integer'], @meth.type_signature_lines
1335+
# Subsequent merge no longer mentions the key — the signature must be
1336+
# cleared rather than left stale, so live-reload reflects deletions.
1337+
@s.merge_rbs_signatures({})
1338+
assert_nil @meth.type_signature_lines
13391339
end
13401340

13411341
def test_merge_rbs_signatures_propagates_to_method_alias
@@ -1447,15 +1447,4 @@ def test_merge_rbs_signatures_does_not_overwrite_inline_annotations
14471447
assert_equal ['(String) -> void'], m.type_signature_lines
14481448
end
14491449

1450-
def test_merge_rbs_signatures_unmatched_key
1451-
@s.merge_rbs_signatures(
1452-
'Object#nonexistent' => ['(String) -> void']
1453-
)
1454-
1455-
# No method matches — nothing should blow up, no sigs assigned
1456-
@klass.method_list.each do |m|
1457-
assert_nil m.type_signature_lines
1458-
end
1459-
end
1460-
14611450
end

0 commit comments

Comments
 (0)