Skip to content

Commit df5c587

Browse files
committed
Move total line count validation to Validator
1 parent 850bd8f commit df5c587

3 files changed

Lines changed: 8 additions & 6 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: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,11 +1185,6 @@ def assert_rewrites_rbs(
11851185
raise ArgumentError, "Invalid symbol for expected_line_matched_format: #{expected_line_matched_format}"
11861186
end
11871187

1188-
assert_equal(source_with_rbs.lines.count, expected_line_matched_format.lines.count, <<~MSG)
1189-
Precondition: the expected rewritten code should have the same line count as the RBS-containing input.
1190-
This is a mistake in the test case, not the rewriter.
1191-
MSG
1192-
11931188
unless (validation_result = Validator.validate(source_with_rbs, expected_line_matched_format)).valid?
11941189
flunk(<<~MSG)
11951190
The rewritten code does not match the expected line-matched format.
@@ -1211,7 +1206,7 @@ def assert_rewrites_rbs(
12111206
overloads_strategy:,
12121207
)
12131208

1214-
# assert_equal(expected_line_matched_format, rewritten_output)
1209+
assert_equal(expected_line_matched_format, rewritten_output)
12151210
end
12161211
end
12171212
end

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)