[ruby/prism] Duplicated when clauses

865b0d5fbe
This commit is contained in:
Kevin Newton 2024-02-23 11:05:32 -05:00
parent d1ce989829
commit a38cc177d2
10 changed files with 58 additions and 13 deletions

View file

@ -20,7 +20,7 @@
│ ├── keyword_loc: (1,10)-(1,14) = "when"
│ ├── conditions: (length: 1)
│ │ └── @ StringNode (location: (1,15)-(1,20))
│ │ ├── flags:
│ │ ├── flags: frozen
│ │ ├── opening_loc: (1,15)-(1,16) = "'"
│ │ ├── content_loc: (1,16)-(1,19) = "bar"
│ │ ├── closing_loc: (1,19)-(1,20) = "'"

View file

@ -20,7 +20,7 @@
│ ├── keyword_loc: (1,10)-(1,14) = "when"
│ ├── conditions: (length: 1)
│ │ └── @ StringNode (location: (1,15)-(1,20))
│ │ ├── flags:
│ │ ├── flags: frozen
│ │ ├── opening_loc: (1,15)-(1,16) = "'"
│ │ ├── content_loc: (1,16)-(1,19) = "bar"
│ │ ├── closing_loc: (1,19)-(1,20) = "'"

View file

@ -20,13 +20,13 @@
│ ├── keyword_loc: (1,10)-(1,14) = "when"
│ ├── conditions: (length: 2)
│ │ ├── @ StringNode (location: (1,15)-(1,20))
│ │ │ ├── flags:
│ │ │ ├── flags: frozen
│ │ │ ├── opening_loc: (1,15)-(1,16) = "'"
│ │ │ ├── content_loc: (1,16)-(1,19) = "bar"
│ │ │ ├── closing_loc: (1,19)-(1,20) = "'"
│ │ │ └── unescaped: "bar"
│ │ └── @ StringNode (location: (1,22)-(1,27))
│ │ ├── flags:
│ │ ├── flags: frozen
│ │ ├── opening_loc: (1,22)-(1,23) = "'"
│ │ ├── content_loc: (1,23)-(1,26) = "baz"
│ │ ├── closing_loc: (1,26)-(1,27) = "'"

View file

@ -20,7 +20,7 @@
│ ├── keyword_loc: (1,10)-(1,14) = "when"
│ ├── conditions: (length: 1)
│ │ └── @ StringNode (location: (1,15)-(1,20))
│ │ ├── flags:
│ │ ├── flags: frozen
│ │ ├── opening_loc: (1,15)-(1,16) = "'"
│ │ ├── content_loc: (1,16)-(1,19) = "bar"
│ │ ├── closing_loc: (1,19)-(1,20) = "'"

View file

@ -46,23 +46,36 @@ module Prism
private
def parse_warning(left, right)
source = <<~RUBY
def parse_warnings(left, right)
warnings = []
warnings << Prism.parse(<<~RUBY, filepath: __FILE__).warnings.first
{
#{left} => 1,
#{right} => 2
}
RUBY
Prism.parse(source, filepath: __FILE__).warnings.first
warnings << Prism.parse(<<~RUBY, filepath: __FILE__).warnings.first
case foo
when #{left}
when #{right}
end
RUBY
warnings
end
def assert_warning(left, right = left)
assert_match %r{key #{Regexp.escape(left)} .+ line 3}, parse_warning(left, right)&.message
hash_keys, when_clauses = parse_warnings(left, right)
assert_include hash_keys.message, left
assert_include hash_keys.message, "line 3"
assert_include when_clauses.message, "line 3"
end
def refute_warning(left, right)
assert_nil parse_warning(left, right)
assert_empty parse_warnings(left, right).compact
end
end
end