Sha256: 23a0d4a9b9de03f8b7b9b5e22da7c605cafdfba968ace98cdf3f3e26fa9d3d54

Contents?: true

Size: 921 Bytes

Versions: 8

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 offence for character literals' do
    inspect_source(cop, ['x = ?x'])
    expect(cop.offences.size).to eq(1)
  end

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

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

  it 'accepts ? in a %w literal' do
    inspect_source(cop, ['%w{? A}'])
    expect(cop.offences).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

8 entries across 8 versions & 2 rubygems

Version Path
ridecharge-rubocop-0.0.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.18.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.18.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.17.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.16.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.15.0 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.14.1 spec/rubocop/cop/style/character_literal_spec.rb
rubocop-0.14.0 spec/rubocop/cop/style/character_literal_spec.rb