Skip to content

Commit c744e47

Browse files
committed
Move total line count validation to Validator
1 parent 46842a1 commit c744e47

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

lib/spoom/sorbet/translate/validator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def validate(original, rewritten)
4646
end
4747
end
4848

49+
if original.lines.count != rewritten.lines.count
50+
on_wrong_line << { landmark_id: "EOF", expected: [original.lines.count], actual: [rewritten.lines.count] }
51+
end
52+
4953
ValidationResult.new(
5054
missing_from_rewritten_output: missing,
5155
excess_in_rewritten_output: excess,

test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,6 @@ def assert_rewrites_rbs(
12141214
raise ArgumentError, "Invalid symbol for expected_line_matched_format: #{expected_line_matched_format}"
12151215
end
12161216

1217-
assert_equal(source_with_rbs.lines.count, expected_line_matched_format.lines.count, <<~MSG)
1218-
Precondition: the expected rewritten code should have the same line count as the RBS-containing input.
1219-
This is a mistake in the test case, not the rewriter.
1220-
MSG
1221-
12221217
unless (validation_result = Validator.validate(source_with_rbs, expected_line_matched_format)).valid?
12231218
flunk(<<~MSG)
12241219
The rewritten code does not match the expected line-matched format.

test/spoom/sorbet/translate/validator_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def m; end
5454
{ landmark_id: "module M", expected: [2], actual: [3] },
5555
{ landmark_id: "def m", expected: [3], actual: [4] },
5656
{ landmark_id: "__LINE__", expected: [4], actual: [5] },
57+
{ landmark_id: "EOF", expected: [4], actual: [5] },
5758
],
5859
)
5960
end
@@ -75,6 +76,7 @@ def m; end
7576
{ landmark_id: "def m", line: 3 },
7677
{ landmark_id: "__LINE__", line: 4 },
7778
],
79+
on_wrong_line: [{ landmark_id: "EOF", expected: [4], actual: [1] }],
7880
)
7981
end
8082

@@ -95,6 +97,7 @@ def new_method; end
9597
{ landmark_id: "def new_method", line: 3 },
9698
{ landmark_id: "__LINE__", line: 4 },
9799
],
100+
on_wrong_line: [{ landmark_id: "EOF", expected: [1], actual: [4] }],
98101
)
99102
end
100103

0 commit comments

Comments
 (0)