44
55module SyntaxTree
66 class FormattingTest < Minitest ::Test
7- delimiter = /%(?: # (.+?))?\n /
7+ FIXTURES_3_0_0 = %w[
8+ command_def_endless
9+ def_endless
10+ fndptn
11+ rassign
12+ rassign_rocket
13+ ]
14+
15+ FIXTURES_3_1_0 = %w[
16+ pinned_begin
17+ var_field_rassign
18+ ]
819
9- Dir [ File . join ( __dir__ , "fixtures" , "*.rb" ) ] . each do |filepath |
10- basename = File . basename ( filepath , ".rb" )
11- sources = File . readlines ( filepath ) . slice_before ( delimiter )
20+ fixtures = Dir [ File . join ( __dir__ , "fixtures" , "*.rb" ) ] . map { |filepath | File . basename ( filepath , ".rb" ) }
21+ fixtures -= FIXTURES_3_1_0 if Gem ::Version . new ( RUBY_VERSION ) < Gem ::Version . new ( "3.1.0" )
22+ fixtures -= FIXTURES_3_0_0 if Gem ::Version . new ( RUBY_VERSION ) < Gem ::Version . new ( "3.0.0" )
23+
24+ delimiter = /%(?: # (.+?))?\n /
25+ fixtures . each do |fixture |
26+ filepath = File . join ( __dir__ , "fixtures" , "#{ fixture } .rb" )
1227
13- sources . each_with_index do |source , index |
28+ File . readlines ( filepath ) . slice_before ( delimiter ) . each_with_index do |source , index |
1429 comment = source . shift . match ( delimiter ) [ 1 ]
1530 original , expected = source . join . split ( "-\n " )
1631
@@ -22,7 +37,7 @@ class FormattingTest < Minitest::Test
2237 next if Gem ::Version . new ( RUBY_VERSION ) < version
2338 end
2439
25- define_method ( :"test_formatting_#{ basename } _#{ index } " ) do
40+ define_method ( :"test_formatting_#{ fixture } _#{ index } " ) do
2641 assert_equal ( expected || original , SyntaxTree . format ( original ) )
2742 end
2843 end
0 commit comments