Sha256: a95bb37595103cdfe890970d4f99a4bf96f9b62aa3684b0e9e0c71a8619b4768

Contents?: true

Size: 921 Bytes

Versions: 6

Compression:

Stored size: 921 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Rubocop::Cop::Style::CharacterLiteral do
  subject(:cop) { described_class.new }

  it 'registers an offense for character literals' do
    inspect_source(cop, ['x = ?x'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'registers an offense for literals like \n' do
    inspect_source(cop, ['x = ?\n'])
    expect(cop.offenses.size).to eq(1)
  end

  it 'accepts literals like ?\C-\M-d' do
    inspect_source(cop, ['x = ?\C-\M-d'])
    expect(cop.offenses).to be_empty
  end

  it 'accepts ? in a %w literal' do
    inspect_source(cop, ['%w{? A}'])
    expect(cop.offenses).to be_empty
  end

  it "auto-corrects ?x to 'x'" do
    new_source = autocorrect_source(cop, 'x = ?x')
    expect(new_source).to eq("x = 'x'")
  end

  it 'auto-corrects ?\n to "\\n"' do
    new_source = autocorrect_source(cop, 'x = ?\n')
    expect(new_source).to eq('x = "\\n"')
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-0.22.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.21.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.20.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.20.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.19.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.19.0 spec/rubocop/cop/style/character_literal_spec.rb