Skip to content

Commit

Permalink
Introduce TestHelper#parse_rbi
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Aug 6, 2024
1 parent c8dc0c1 commit 6df3fee
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 157 deletions.
14 changes: 8 additions & 6 deletions test/rbi/formatter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

module RBI
class FormatterTest < Minitest::Test
include TestHelper

def test_format_add_sig_templates
rbi = <<~RBI
module Foo
Expand All @@ -13,7 +15,7 @@ def foo(a, b); end
RBI

file = File.new
file.root = Parser.parse_string(rbi)
file.root = parse_rbi(rbi)

out = Formatter.new(add_sig_templates: false).print_file(file)
assert_equal(rbi, out)
Expand All @@ -38,7 +40,7 @@ def bar(a, b); end
RBI

file = File.new
file.root = Parser.parse_string(rbi)
file.root = parse_rbi(rbi)

out = Formatter.new(group_nodes: false).print_file(file)
assert_equal(rbi, out)
Expand All @@ -63,7 +65,7 @@ def foo(a, b); end
RBI

file = File.new
file.root = Parser.parse_string(rbi)
file.root = parse_rbi(rbi)

out = Formatter.new(max_line_length: nil).print_file(file)
assert_equal(rbi, out)
Expand All @@ -90,7 +92,7 @@ def self.foo; end
RBI

file = File.new
file.root = Parser.parse_string(rbi)
file.root = parse_rbi(rbi)

out = Formatter.new(nest_singleton_methods: false).print_file(file)
assert_equal(rbi, out)
Expand All @@ -113,7 +115,7 @@ module Foo
RBI

file = File.new
file.root = Parser.parse_string(rbi)
file.root = parse_rbi(rbi)

out = Formatter.new(nest_non_public_methods: false).print_file(file)
assert_equal(rbi, out)
Expand All @@ -137,7 +139,7 @@ def bar(a, b); end
RBI

file = File.new
file.root = Parser.parse_string(rbi)
file.root = parse_rbi(rbi)

out = Formatter.new(sort_nodes: false).print_file(file)
assert_equal(rbi, out)
Expand Down
11 changes: 6 additions & 5 deletions test/rbi/index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

module RBI
class IndexTest < Minitest::Test
include TestHelper
extend T::Sig

def test_index_empty_trees
Expand All @@ -14,7 +15,7 @@ def test_index_empty_trees
end

def test_index_scopes_and_consts
rbi = Parser.parse_string(<<~RBI)
rbi = parse_rbi(<<~RBI)
class A
module B
module ::C; end
Expand All @@ -38,7 +39,7 @@ class << self; end
end

def test_index_properties
rbi = Parser.parse_string(<<~RBI)
rbi = parse_rbi(<<~RBI)
class A
attr_reader :a, :b
attr_writer :a, :b
Expand Down Expand Up @@ -70,7 +71,7 @@ def foo(a); end
end

def test_index_sorbet_constructs
rbi = Parser.parse_string(<<~RBI)
rbi = parse_rbi(<<~RBI)
class A < T::Struct
const :a, Integer
prop :b, String
Expand Down Expand Up @@ -105,15 +106,15 @@ class B < T::Enum
end

def test_index_multiple_trees
tree1 = Parser.parse_string(<<~RBI)
tree1 = parse_rbi(<<~RBI)
class A
module B
module ::C; end
end
end
RBI

tree2 = Parser.parse_string(<<~RBI)
tree2 = parse_rbi(<<~RBI)
class A
module B
module ::C; end
Expand Down
Loading

0 comments on commit 6df3fee

Please sign in to comment.