Skip to content

Instantly share code, notes, and snippets.

@r7kamura
Last active November 9, 2018 10:50
Show Gist options
  • Save r7kamura/db1907f80a0b8f475af25ce9b63a6115 to your computer and use it in GitHub Desktop.
Save r7kamura/db1907f80a0b8f475af25ce9b63a6115 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Style::RegexpLiteral, :config do
subject(:cop) { described_class.new(config) }
let(:config) do
supported_styles = {
'SupportedStyles' => %w[slashes percent_r mixed]
}
RuboCop::Config.new('Style/PercentLiteralDelimiters' =>
percent_literal_delimiters_config,
'Style/RegexpLiteral' =>
cop_config.merge(supported_styles))
end
let(:percent_literal_delimiters_config) do
{ 'PreferredDelimiters' => { '%r' => '{}' } }
end
let(:cop_config) do
{}
end
shared_context 'when AllowInnerSlashes is false' do
let(:cop_config) do
super().merge('AllowInnerSlashes' => false)
end
end
shared_context 'when AllowInnerSlashes is true' do
let(:cop_config) do
super().merge('AllowInnerSlashes' => true)
end
end
shared_context 'when EnforcedStyle is mixed' do
let(:cop_config) do
super().merge('EnforcedStyle' => 'mixed')
end
end
shared_context 'when EnforcedStyle is percent_r' do
let(:cop_config) do
super().merge('EnforcedStyle' => 'percent_r')
end
end
shared_context 'when EnforcedStyle is slashes' do
let(:cop_config) do
super().merge('EnforcedStyle' => 'slashes')
end
end
shared_context 'when PreferredDelimiters is //' do
let(:percent_literal_delimiters_config) do
super().merge('PreferredDelimiters' => { '%r' => '//' })
end
end
shared_context 'when PreferredDelimiters is {}' do
let(:percent_literal_delimiters_config) do
super().merge('PreferredDelimiters' => { '%r' => '{}' })
end
end
shared_context 'when source is a single-line `/a\//`' do
let(:source) do
'x = /a\//'
end
end
shared_context 'when source is a single-line `/a/`' do
let(:source) do
'x = /a/'
end
end
shared_context 'when source is a single-line `%r/a\//`' do
let(:source) do
'x = %r/a\//'
end
end
shared_context 'when source is a single-line `%r/a/`' do
let(:source) do
'x = %r/a/'
end
end
shared_context 'when source is a multi-line `/a\//x`' do
let(:source) do
<<-'RUBY'.strip_indent
x = /
a\/
/x
RUBY
end
end
shared_context 'when source is a multi-line `/a/x`' do
let(:source) do
<<-'RUBY'.strip_indent
x = /
a
/x
RUBY
end
end
shared_context 'when source is a multi-line `%r/a\//x`' do
let(:source) do
<<-'RUBY'.strip_indent
x = %r/
a\/
/x
RUBY
end
end
shared_context 'when source is a multi-line `%r/a/x`' do
let(:source) do
<<-'RUBY'.strip_indent
x = %r/
a
/x
RUBY
end
end
shared_examples 'registers no offense' do
it 'registers no offense' do
expect_no_offenses(source)
end
end
shared_examples 'auto-corrects' do
it 'auto-corrects' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a single-line `/a\//`' do
let(:source_corrected) do
'x = /a\//'
end
it 'auto-corrects to a single-line `/a\//`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a single-line `/a/`' do
let(:source_corrected) do
'x = /a/'
end
it 'auto-corrects to a single-line `/a/`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a single-line `%r/a\//`' do
let(:source_corrected) do
'x = %r/a\//'
end
it 'auto-corrects to a single-line `%r/a\//`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a single-line `%r/a/`' do
let(:source_corrected) do
'x = %r/a/'
end
it 'auto-corrects to a single-line `%r/a/`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a single-line `%r{a/}`' do
let(:source_corrected) do
'x = %r{a/}'
end
it 'auto-corrects to a single-line `%r{a/}`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a single-line `%r{a}`' do
let(:source_corrected) do
'x = %r{a}'
end
it 'auto-corrects to a single-line `%r{a}`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a multi-line `/a\//x`' do
let(:source_corrected) do
<<-'RUBY'.strip_indent
x = /
a\/
/x
RUBY
end
it 'auto-corrects to a multi-line `/a\//x`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a multi-line `/a/x`' do
let(:source_corrected) do
<<-'RUBY'.strip_indent
x = /
a
/x
RUBY
end
it 'auto-corrects to a multi-line `/a/x`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a multi-line `%r/a\//x`' do
let(:source_corrected) do
<<-'RUBY'.strip_indent
x = %r/
a\/
/x
RUBY
end
it 'auto-corrects to a multi-line `%r/a\//x`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a multi-line `%r/a/x`' do
let(:source_corrected) do
<<-'RUBY'.strip_indent
x = %r/
a
/x
RUBY
end
it 'auto-corrects to a multi-line `%r/a/x`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a multi-line `%r{a/}x`' do
let(:source_corrected) do
<<-'RUBY'.strip_indent
x = %r{
a/
}x
RUBY
end
it 'auto-corrects to a multi-line `%r{a/}x`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
shared_examples 'auto-corrects to a multi-line `%r{a}x`' do
let(:source_corrected) do
<<-'RUBY'.strip_indent
x = %r{
a
}x
RUBY
end
it 'auto-corrects to a multi-line `%r{a}x`' do
expect(autocorrect_source(source)).to eq(source_corrected)
end
end
context 'when EnforcedStyle is mixed' do
include_context 'when EnforcedStyle is mixed'
context 'when PreferredDelimiters is {}' do
include_context 'when PreferredDelimiters is {}'
context 'when AllowInnerSlashes is false' do
include_context 'when AllowInnerSlashes is false'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
context 'when source is a multi-line `%r/a\//x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a/x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
end
context 'when AllowInnerSlashes is true' do
include_context 'when AllowInnerSlashes is true'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `/a\//`'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
context 'when source is a multi-line `%r/a\//x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a/x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
end
end
context 'when PreferredDelimiters is //' do
include_context 'when PreferredDelimiters is //'
context 'when AllowInnerSlashes is false' do
include_context 'when AllowInnerSlashes is false'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r/a\//`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r/a\//x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r/a/x`'
end
context 'when source is a multi-line `%r/a\//x`' do
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'registers no offense'
end
end
context 'when AllowInnerSlashes is true' do
include_context 'when AllowInnerSlashes is true'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `/a\//`'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r/a\//x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r/a/x`'
end
context 'when source is a multi-line `%r/a\//x`' do
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'registers no offense'
end
end
end
end
context 'when EnforcedStyle is percent_r' do
include_context 'when EnforcedStyle is percent_r'
context 'when PreferredDelimiters is {}' do
include_context 'when PreferredDelimiters is {}'
context 'when AllowInnerSlashes is false' do
include_context 'when AllowInnerSlashes is false'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'auto-corrects to a single-line `%r{a}`'
end
context 'when source is a single-line `%r/a\//`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `%r/a/`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `%r{a}`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
context 'when source is a multi-line `%r/a\//x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a/x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
end
context 'when AllowInnerSlashes is true' do
include_context 'when AllowInnerSlashes is true'
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'auto-corrects to a single-line `%r{a}`'
end
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `%r/a/`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `%r{a}`'
end
context 'when source is a single-line `%r/a\//`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a\//x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a/x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `%r{a}x`'
end
end
end
context 'when PreferredDelimiters is //' do
include_context 'when PreferredDelimiters is //'
context 'when AllowInnerSlashes is false' do
include_context 'when AllowInnerSlashes is false'
context 'when source is a single-line `/a\//` with slashes' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r/a\//`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'auto-corrects to a single-line `%r/a/`'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r/a\//x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r/a/x`'
end
context 'when source is a multi-line `%r/a\//x`' do
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'registers no offense'
end
end
context 'when AllowInnerSlashes is true' do
include_context 'when AllowInnerSlashes is true'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r/a\//`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'auto-corrects to a single-line `%r/a/`'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r/a\//x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `%r/a/x`'
end
context 'when source is a multi-line `%r/a\//x`' do
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'registers no offense'
end
end
end
end
context 'when EnforcedStyle is slashes' do
include_context 'when EnforcedStyle is slashes'
context 'when PreferredDelimiters is {}' do
include_context 'when PreferredDelimiters is {}'
context 'when AllowInnerSlashes is false' do
include_context 'when AllowInnerSlashes is false'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `%r{a/}`'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `/a/x`'
end
context 'when source is a multi-line `%r/a\//x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `/a/x`'
end
end
context 'when AllowInnerSlashes is true' do
include_context 'when AllowInnerSlashes is true'
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `/a\//`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'auto-corrects to a multi-line `/a/x`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a\//x`' do
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `/a\//x`'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `/a/x`'
end
end
end
context 'when PreferredDelimiters is //' do
include_context 'when PreferredDelimiters is //'
context 'when AllowInnerSlashes is false' do
include_context 'when AllowInnerSlashes is false'
context 'when source is a single-line `/a\//` with slashes' do
include_context 'when source is a single-line `/a\//`'
include_examples 'auto-corrects to a single-line `%r/a\//`'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'auto-corrects to a multi-line `%r/a\//x`'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a\//x`' do
before do
pending 'Replacement from %r to other %r is not supported'
end
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `%r{a/}x`'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `/a/x`'
end
end
context 'when AllowInnerSlashes is true' do
include_context 'when AllowInnerSlashes is true'
context 'when source is a single-line `/a\//`' do
include_context 'when source is a single-line `/a\//`'
include_examples 'registers no offense'
end
context 'when source is a single-line `/a/`' do
include_context 'when source is a single-line `/a/`'
include_examples 'registers no offense'
end
context 'when source is a single-line `%r/a\//`' do
include_context 'when source is a single-line `%r/a\//`'
include_examples 'auto-corrects to a single-line `/a\//`'
end
context 'when source is a single-line `%r/a/`' do
include_context 'when source is a single-line `%r/a/`'
include_examples 'auto-corrects to a single-line `/a/`'
end
context 'when source is a multi-line `/a\//x`' do
include_context 'when source is a multi-line `/a\//x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `/a/x`' do
include_context 'when source is a multi-line `/a/x`'
include_examples 'registers no offense'
end
context 'when source is a multi-line `%r/a\//x`' do
include_context 'when source is a multi-line `%r/a\//x`'
include_examples 'auto-corrects to a multi-line `/a\//x`'
end
context 'when source is a multi-line `%r/a/x`' do
include_context 'when source is a multi-line `%r/a/x`'
include_examples 'auto-corrects to a multi-line `/a/x`'
end
end
end
end
describe 'when regex contains slashes in interpolation' do
let(:cop_config) { { 'EnforcedStyle' => 'slashes' } }
it 'ignores the slashes that do not belong // regex' do
expect_no_offenses('x =~ /\s{#{x[/\s+/].length}}/')
end
end
describe '%r regex with other delimiters than curly braces' do
let(:cop_config) { { 'EnforcedStyle' => 'slashes' } }
it 'registers an offense' do
expect_offense(<<-RUBY.strip_indent)
%r_ls_
^^^^^^ Use `//` around regular expression.
RUBY
end
end
end
@r7kamura
Copy link
Author

r7kamura commented Nov 9, 2018

RuboCop::Cop::Style::RegexpLiteral
  when EnforcedStyle is mixed
    when PreferredDelimiters is {}
      when AllowInnerSlashes is false
        when source is a single-line `/a\//`
          auto-corrects to a single-line `%r{a/}`
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `%r{a/}` (PENDING: Replacement from %r to other %r is not supported)
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r{a/}x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r{a}x`
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `%r{a/}x` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `%r{a}x` (PENDING: Replacement from %r to other %r is not supported)
      when AllowInnerSlashes is true
        when source is a single-line `/a\//`
          registers no offense
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `/a\//`
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r{a/}x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r{a}x`
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `%r{a/}x` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `%r{a}x` (PENDING: Replacement from %r to other %r is not supported)
    when PreferredDelimiters is //
      when AllowInnerSlashes is false
        when source is a single-line `/a\//`
          auto-corrects to a single-line `%r/a\//`
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          registers no offense
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r/a\//x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r/a/x`
        when source is a multi-line `%r/a\//x`
          registers no offense
        when source is a multi-line `%r/a/x`
          registers no offense
      when AllowInnerSlashes is true
        when source is a single-line `/a\//`
          registers no offense
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `/a\//`
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r/a\//x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r/a/x`
        when source is a multi-line `%r/a\//x`
          registers no offense
        when source is a multi-line `%r/a/x`
          registers no offense
  when EnforcedStyle is percent_r
    when PreferredDelimiters is {}
      when AllowInnerSlashes is false
        when source is a single-line `/a\//`
          auto-corrects to a single-line `%r{a/}`
        when source is a single-line `/a/`
          auto-corrects to a single-line `%r{a}`
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `%r{a/}` (PENDING: Replacement from %r to other %r is not supported)
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `%r{a}` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r{a/}x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r{a}x`
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `%r{a/}x` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `%r{a}x` (PENDING: Replacement from %r to other %r is not supported)
      when AllowInnerSlashes is true
        when source is a single-line `/a/`
          auto-corrects to a single-line `%r{a}`
        when source is a single-line `/a\//`
          auto-corrects to a single-line `%r{a/}`
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `%r{a}` (PENDING: Replacement from %r to other %r is not supported)
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `%r{a/}` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r{a}x`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r{a/}x`
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `%r{a/}x` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `%r{a}x` (PENDING: Replacement from %r to other %r is not supported)
    when PreferredDelimiters is //
      when AllowInnerSlashes is false
        when source is a single-line `/a\//` with slashes
          auto-corrects to a single-line `%r/a\//`
        when source is a single-line `/a/`
          auto-corrects to a single-line `%r/a/`
        when source is a single-line `%r/a\//`
          registers no offense
        when source is a single-line `%r/a/`
          registers no offense
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r/a\//x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r/a/x`
        when source is a multi-line `%r/a\//x`
          registers no offense
        when source is a multi-line `%r/a/x`
          registers no offense
      when AllowInnerSlashes is true
        when source is a single-line `/a\//`
          auto-corrects to a single-line `%r/a\//`
        when source is a single-line `/a/`
          auto-corrects to a single-line `%r/a/`
        when source is a single-line `%r/a\//`
          registers no offense
        when source is a single-line `%r/a/`
          registers no offense
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r/a\//x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `%r/a/x`
        when source is a multi-line `%r/a\//x`
          registers no offense
        when source is a multi-line `%r/a/x`
          registers no offense
  when EnforcedStyle is slashes
    when PreferredDelimiters is {}
      when AllowInnerSlashes is false
        when source is a single-line `/a\//`
          auto-corrects to a single-line `%r{a/}`
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `%r{a/}` (PENDING: Replacement from %r to other %r is not supported)
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r{a/}x`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `/a/x`
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `%r{a/}x` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `/a/x`
      when AllowInnerSlashes is true
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `/a\//`
          registers no offense
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `/a\//`
        when source is a multi-line `/a/x`
          auto-corrects to a multi-line `/a/x`
        when source is a multi-line `/a\//x`
          registers no offense
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `/a\//x`
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `/a/x`
    when PreferredDelimiters is //
      when AllowInnerSlashes is false
        when source is a single-line `/a\//` with slashes
          auto-corrects to a single-line `%r/a\//`
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          registers no offense
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          auto-corrects to a multi-line `%r/a\//x`
        when source is a multi-line `/a/x`
          registers no offense
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `%r{a/}x` (PENDING: Replacement from %r to other %r is not supported)
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `/a/x`
      when AllowInnerSlashes is true
        when source is a single-line `/a\//`
          registers no offense
        when source is a single-line `/a/`
          registers no offense
        when source is a single-line `%r/a\//`
          auto-corrects to a single-line `/a\//`
        when source is a single-line `%r/a/`
          auto-corrects to a single-line `/a/`
        when source is a multi-line `/a\//x`
          registers no offense
        when source is a multi-line `/a/x`
          registers no offense
        when source is a multi-line `%r/a\//x`
          auto-corrects to a multi-line `/a\//x`
        when source is a multi-line `%r/a/x`
          auto-corrects to a multi-line `/a/x`
  when regex contains slashes in interpolation
    ignores the slashes that do not belong // regex
  %r regex with other delimiters than curly braces
    registers an offense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment