зеркало из https://github.com/github/ruby.git
[ruby/prism] Make equality operators non-associative
Fix https://github.com/ruby/prism/pull/2073 https://github.com/ruby/prism/commit/0f747d9240
This commit is contained in:
Родитель
8e1c148fd9
Коммит
3658798dbb
|
@ -10287,12 +10287,12 @@ pm_binding_powers_t pm_binding_powers[PM_TOKEN_MAXIMUM] = {
|
|||
[PM_TOKEN_AMPERSAND_AMPERSAND] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_LOGICAL_AND),
|
||||
|
||||
// != !~ == === =~ <=>
|
||||
[PM_TOKEN_BANG_EQUAL] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_BANG_TILDE] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_EQUAL_EQUAL] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_EQUAL_EQUAL_EQUAL] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_EQUAL_TILDE] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_LESS_EQUAL_GREATER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_BANG_EQUAL] = NON_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_BANG_TILDE] = NON_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_EQUAL_EQUAL] = NON_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_EQUAL_EQUAL_EQUAL] = NON_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_EQUAL_TILDE] = NON_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
[PM_TOKEN_LESS_EQUAL_GREATER] = NON_ASSOCIATIVE(PM_BINDING_POWER_EQUALITY),
|
||||
|
||||
// > >= < <=
|
||||
[PM_TOKEN_GREATER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_COMPARISON),
|
||||
|
|
|
@ -2004,6 +2004,33 @@ module Prism
|
|||
]
|
||||
end
|
||||
|
||||
def test_non_assoc_equality
|
||||
source = <<~RUBY
|
||||
1 == 2 == 3
|
||||
1 != 2 != 3
|
||||
1 === 2 === 3
|
||||
1 =~ 2 =~ 3
|
||||
1 !~ 2 !~ 3
|
||||
1 <=> 2 <=> 3
|
||||
RUBY
|
||||
message1 = 'expected a newline or semicolon after the statement'
|
||||
message2 = 'cannot parse the expression'
|
||||
assert_errors expression(source), source, [
|
||||
[message1, 6..6],
|
||||
[message2, 6..6],
|
||||
[message1, 18..18],
|
||||
[message2, 18..18],
|
||||
[message1, 31..31],
|
||||
[message2, 31..31],
|
||||
[message1, 44..44],
|
||||
[message2, 44..44],
|
||||
[message1, 56..56],
|
||||
[message2, 56..56],
|
||||
[message1, 69..69],
|
||||
[message2, 69..69],
|
||||
]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
||||
|
|
Загрузка…
Ссылка в новой задаче