Skip to content

Commit

Permalink
[ruby/prism] Simplify locals test now that all fixtures are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Apr 8, 2024
1 parent 478b4ef commit b09604e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 51 deletions.
4 changes: 2 additions & 2 deletions test/prism/fixtures/if.txt
Expand Up @@ -30,10 +30,10 @@ if type in 1
elsif type in B
end

if 1
if f1
lambda do |_|
end
elsif 2
elsif f2
lambda do |_|
end
else
Expand Down
46 changes: 3 additions & 43 deletions test/prism/locals_test.rb
Expand Up @@ -17,51 +17,11 @@

module Prism
class LocalsTest < TestCase
invalid = []
todos = []

# Invalid break
invalid << "break.txt"
invalid << "if.txt"
invalid << "rescue.txt"
invalid << "seattlerb/block_break.txt"
invalid << "unless.txt"
invalid << "whitequark/break.txt"
invalid << "whitequark/break_block.txt"

# Invalid next
invalid << "next.txt"
invalid << "seattlerb/block_next.txt"
invalid << "unparser/corpus/literal/control.txt"
invalid << "whitequark/next.txt"
invalid << "whitequark/next_block.txt"

# Invalid redo
invalid << "keywords.txt"
invalid << "whitequark/redo.txt"

# Invalid retry
invalid << "whitequark/retry.txt"

# Invalid yield
invalid << "seattlerb/dasgn_icky2.txt"
invalid << "seattlerb/yield_arg.txt"
invalid << "seattlerb/yield_call_assocs.txt"
invalid << "seattlerb/yield_empty_parens.txt"
invalid << "unparser/corpus/literal/yield.txt"
invalid << "whitequark/args_assocs.txt"
invalid << "whitequark/args_assocs_legacy.txt"
invalid << "whitequark/yield.txt"
invalid << "yield.txt"

# Dead code eliminated
invalid << "whitequark/ruby_bug_10653.txt"

base = File.join(__dir__, "fixtures")
skips = invalid | todos

Dir["**/*.txt", base: base].each do |relative|
next if skips.include?(relative)
# Skip this fixture because it has a different number of locals because
# CRuby is eliminating dead code.
next if relative == "whitequark/ruby_bug_10653.txt"

filepath = File.join(base, relative)
define_method("test_#{relative}") { assert_locals(filepath) }
Expand Down
26 changes: 20 additions & 6 deletions test/prism/snapshots/if.txt
Expand Up @@ -391,9 +391,16 @@
└── @ IfNode (location: (33,0)-(42,3))
├── if_keyword_loc: (33,0)-(33,2) = "if"
├── predicate:
│ @ IntegerNode (location: (33,3)-(33,4))
│ ├── flags: decimal
│ └── value: 1
│ @ CallNode (location: (33,3)-(33,5))
│ ├── flags: variable_call, ignore_visibility
│ ├── receiver: ∅
│ ├── call_operator_loc: ∅
│ ├── name: :f1
│ ├── message_loc: (33,3)-(33,5) = "f1"
│ ├── opening_loc: ∅
│ ├── arguments: ∅
│ ├── closing_loc: ∅
│ └── block: ∅
├── then_keyword_loc: ∅
├── statements:
│ @ StatementsNode (location: (34,2)-(35,5))
Expand Down Expand Up @@ -434,9 +441,16 @@
│ @ IfNode (location: (36,0)-(42,3))
│ ├── if_keyword_loc: (36,0)-(36,5) = "elsif"
│ ├── predicate:
│ │ @ IntegerNode (location: (36,6)-(36,7))
│ │ ├── flags: decimal
│ │ └── value: 2
│ │ @ CallNode (location: (36,6)-(36,8))
│ │ ├── flags: variable_call, ignore_visibility
│ │ ├── receiver: ∅
│ │ ├── call_operator_loc: ∅
│ │ ├── name: :f2
│ │ ├── message_loc: (36,6)-(36,8) = "f2"
│ │ ├── opening_loc: ∅
│ │ ├── arguments: ∅
│ │ ├── closing_loc: ∅
│ │ └── block: ∅
│ ├── then_keyword_loc: ∅
│ ├── statements:
│ │ @ StatementsNode (location: (37,2)-(38,5))
Expand Down

0 comments on commit b09604e

Please sign in to comment.