Skip to content

Commit

Permalink
Encode current behavior of helpers parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Aug 6, 2024
1 parent edda975 commit 37bc668
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/rbi/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,24 @@ def baz; end
assert_equal(rbi, out.string)
end

def test_parse_helpers_vs_sends
rbi = <<~RBI
abstract!
sealed!
interface!
x!
foo!
RBI

tree = parse_rbi(rbi)

# Make sure the helpers are properly parsed as `Helper` classes
assert_equal(2, tree.nodes.grep(Send).size) # `x!` and `foo!`
assert_equal(3, tree.nodes.grep(Helper).size)

assert_equal(rbi, tree.string)
end

def test_parse_sorbet_helpers
rbi = <<~RBI
class Foo
Expand All @@ -314,8 +332,16 @@ class Foo
end
RBI

out = parse_rbi(rbi)
assert_equal(rbi, out.string)
tree = parse_rbi(rbi)

# Make sure the helpers are properly parsed as `Helper` classes
cls = T.cast(tree.nodes.first, Class)
assert_equal(0, cls.nodes.grep(Send).size)
assert_equal(3, cls.nodes.grep(Helper).size)
assert_equal(1, cls.nodes.grep(MixesInClassMethods).size)
assert_equal(1, cls.nodes.grep(RequiresAncestor).size)

assert_equal(rbi, tree.string)
end

def test_parse_sorbet_type_members_and_templates
Expand Down

0 comments on commit 37bc668

Please sign in to comment.