Skip to content

Commit

Permalink
Merge pull request #12980 from Earlopain/supported-on-prism
Browse files Browse the repository at this point in the history
Enable a bunch of tests for prism
  • Loading branch information
koic committed Jun 10, 2024
2 parents 40148ea + e04d2c2 commit 88f94c9
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 566 deletions.
180 changes: 86 additions & 94 deletions spec/rubocop/cop/layout/case_indentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,21 @@
RUBY
end

context 'Ruby <= 3.2', :ruby32, unsupported_on: :prism do
it "accepts a `when` clause that's equally indented with `case`" do
expect_no_offenses(<<~RUBY)
y = case a
when 0 then break
when 0 then return
else
z = case b
when 1 then return
when 1 then break
end
end
case c
when 2 then encoding
end
RUBY
end
it "accepts a `when` clause that's equally indented with `case`" do
expect_no_offenses(<<~RUBY)
y = case a
when 0 then break
when 0 then return
else
z = case b
when 1 then return
when 1 then break
end
end
case c
when 2 then encoding
end
RUBY
end

it "doesn't get confused by strings with `case` in them" do
Expand Down Expand Up @@ -312,23 +310,21 @@
RUBY
end

context 'Ruby <= 3.2', :ruby32, unsupported_on: :prism do
it "accepts an `in` clause that's equally indented with `case`" do
expect_no_offenses(<<~RUBY)
y = case a
in 0 then break
in 0 then return
else
z = case b
in 1 then return
in 1 then break
end
end
case c
in 2 then encoding
end
RUBY
end
it "accepts an `in` clause that's equally indented with `case`" do
expect_no_offenses(<<~RUBY)
y = case a
in 0 then break
in 0 then return
else
z = case b
in 1 then return
in 1 then break
end
end
case c
in 2 then encoding
end
RUBY
end

it "doesn't get confused by strings with `case` in them" do
Expand Down Expand Up @@ -432,41 +428,39 @@
RUBY
end

context 'Ruby <= 3.2', :ruby32, unsupported_on: :prism do
it 'registers an offense and corrects a `when` clause that is equally indented with `case`' do
expect_offense(<<~RUBY)
y = case a
it 'registers an offense and corrects a `when` clause that is equally indented with `case`' do
expect_offense(<<~RUBY)
y = case a
when 0 then break
^^^^ Indent `when` one step more than `case`.
when 0 then return
^^^^ Indent `when` one step more than `case`.
z = case b
when 1 then return
^^^^ Indent `when` one step more than `case`.
when 1 then break
^^^^ Indent `when` one step more than `case`.
end
end
case c
when 2 then encoding
^^^^ Indent `when` one step more than `case`.
end
RUBY

expect_correction(<<~RUBY)
y = case a
when 0 then break
^^^^ Indent `when` one step more than `case`.
when 0 then return
^^^^ Indent `when` one step more than `case`.
z = case b
z = case b
when 1 then return
^^^^ Indent `when` one step more than `case`.
when 1 then break
^^^^ Indent `when` one step more than `case`.
end
end
case c
end
end
case c
when 2 then encoding
^^^^ Indent `when` one step more than `case`.
end
RUBY

expect_correction(<<~RUBY)
y = case a
when 0 then break
when 0 then return
z = case b
when 1 then return
when 1 then break
end
end
case c
when 2 then encoding
end
RUBY
end
end
RUBY
end

context 'when indentation width is overridden for this cop only' do
Expand Down Expand Up @@ -544,41 +538,39 @@
RUBY
end

context 'Ruby <= 3.2', :ruby32, unsupported_on: :prism do
it 'registers an offense and corrects an `in` clause that is equally indented with `case`' do
expect_offense(<<~RUBY)
y = case a
it 'registers an offense and corrects an `in` clause that is equally indented with `case`' do
expect_offense(<<~RUBY)
y = case a
in 0 then break
^^ Indent `in` one step more than `case`.
in 0 then return
^^ Indent `in` one step more than `case`.
z = case b
in 1 then return
^^ Indent `in` one step more than `case`.
in 1 then break
^^ Indent `in` one step more than `case`.
end
end
case c
in 2 then encoding
^^ Indent `in` one step more than `case`.
end
RUBY

expect_correction(<<~RUBY)
y = case a
in 0 then break
^^ Indent `in` one step more than `case`.
in 0 then return
^^ Indent `in` one step more than `case`.
z = case b
z = case b
in 1 then return
^^ Indent `in` one step more than `case`.
in 1 then break
^^ Indent `in` one step more than `case`.
end
end
case c
end
end
case c
in 2 then encoding
^^ Indent `in` one step more than `case`.
end
RUBY

expect_correction(<<~RUBY)
y = case a
in 0 then break
in 0 then return
z = case b
in 1 then return
in 1 then break
end
end
case c
in 2 then encoding
end
RUBY
end
end
RUBY
end

context 'when indentation width is overridden for this cop only' do
Expand Down
64 changes: 31 additions & 33 deletions spec/rubocop/cop/layout/empty_line_after_guard_clause_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,44 +529,42 @@ def foo
RUBY
end

context 'Ruby <= 3.2', :ruby32, unsupported_on: :prism do
it 'registers an offense and corrects a method starting with end_' do
expect_offense(<<~RUBY)
def foo
next unless need_next?
^^^^^^^^^^^^^^^^^^^^^^ Add empty line after guard clause.
end_this!
end
RUBY
it 'registers an offense and corrects a method starting with end_' do
expect_offense(<<~RUBY)
def foo
next unless need_next?
^^^^^^^^^^^^^^^^^^^^^^ Add empty line after guard clause.
end_this!
end
RUBY

expect_correction(<<~RUBY)
def foo
next unless need_next?
expect_correction(<<~RUBY)
def foo
next unless need_next?
end_this!
end
RUBY
end
end_this!
end
RUBY
end

it 'registers an offense and corrects only the last guard clause' do
expect_offense(<<~RUBY)
def foo
next if foo?
next if bar?
^^^^^^^^^^^^ Add empty line after guard clause.
foobar
end
RUBY
it 'registers an offense and corrects only the last guard clause' do
expect_offense(<<~RUBY)
def foo
next if foo?
next if bar?
^^^^^^^^^^^^ Add empty line after guard clause.
foobar
end
RUBY

expect_correction(<<~RUBY)
def foo
next if foo?
next if bar?
expect_correction(<<~RUBY)
def foo
next if foo?
next if bar?
foobar
end
RUBY
end
foobar
end
RUBY
end

it 'registers no offenses using heredoc with `and return` before guard condition with empty line' do
Expand Down

0 comments on commit 88f94c9

Please sign in to comment.