Extract #assert_rewrites_rbs helper#939
Conversation
a435d91 to
68dc474
Compare
| #| ?max_line_length: Integer?, | ||
| #| ?overloads_strategy: Symbol | ||
| #| ) -> String | ||
| def assert_rewrites_rbs( |
There was a problem hiding this comment.
Looks like there are 7 occurrences of tests where the from and to_pretty_format_for_humans is equivalent. Wdyt about adding a default value so that if they're equal the callsites won't have to specify the kwargs:
def assert_rewrites_rbs(
from = nil,
to: from,
max_line_length: nil,
overloads_strategy: :translate_all
)There was a problem hiding this comment.
Spoke offline. Will following up with something similar, but as a separate method like assert_rbs_rewrite_is_no_op.
That way you don't have a call with a from: but not to:
There was a problem hiding this comment.
Oh also, some things that are no-op today, might not be no-op in the new rewriter mode. I'll explain it in the PR when I open it.
| source_with_rbs = from | ||
| expected_pretty_format = to_pretty_format_for_humans | ||
|
|
||
| begin # Validate the human-readable rewrite |
There was a problem hiding this comment.
Why is this wrapped in a begin?
There was a problem hiding this comment.
Just for visual grouping
There was a problem hiding this comment.
Felt weird at first sight, but it quickly grew up on me 👍
There was a problem hiding this comment.
For context, up the stack there will be two of these, running different sets of assertions/validations against the two different outputs:
spoom/test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb
Lines 1035 to 1066 in 658304d
68dc474 to
9a3d00b
Compare
9a3d00b to
b35b615
Compare
Background
As part of #787, I'm building a more comprehensive test suite that will ensure that the RBS-to-Sorbet translator preserves line numbering.
Achieving correct line numbers while still keeping the same meaning will require the translator to produce some pretty funky code, which is great for machines, but sucks for humans. So we'll want to support both:
__LINE__, etc.This PR
Refactors our existing tests into a new
#assert_rewrites_rbshelper. Currently it just has one input and one expected output.In a future PR, I'll be adding a second expected output for each test case. WIP, but you can get an idea here: 658304d
Very easy to review if you hide whitespace changes.
Alternatives considered
Make a dedicated test class for the line-matching rewriter. That way this test class' test cases have one input and one (human-readable) expected output, and the other class' test cases have one input and one (machine-readable) expected output.
I tried that out, but it became obvious that the two suites would be hard to keep in sync, and we would surely have new additions in the future that are only tested in one mode or the other, rather than both.