Sha256: 5bee22a88325bec0640f423e3828825adf6d378de7cc188b72fade58a26abff2
Contents?: true
Size: 1.93 KB
Versions: 3
Compression:
Stored size: 1.93 KB
Contents
# encoding: utf-8 require 'spec_helper' module Rubocop module Cop module Style describe StringLiterals do let(:sl) { StringLiterals.new } it 'registers offence for double quotes when single quotes suffice' do inspect_source(sl, ['s = "abc"', 'x = "a\\\\b"', 'y ="\\\\b"', 'z = "a\\\\"']) expect(sl.offences.size).to eq(4) end it 'accepts double quotes when they are needed' do src = ['a = "\n"', 'b = "#{encode_severity}:' + '#{sprintf("%3d", line_number)}: #{m}"', 'c = "\'"', 'd = "#@test"', 'e = "#$test"', 'f = "\e"', 'g = "#@@test"'] inspect_source(sl, src) expect(sl.offences).to be_empty end it 'accepts double quotes at the start of regexp literals' do inspect_source(sl, ['s = /"((?:[^\\"]|\\.)*)"/']) expect(sl.offences).to be_empty end it 'accepts double quotes with some other special symbols' do # "Substitutions in double-quoted strings" # http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html src = ['g = "\xf9"', 'copyright = "\u00A9"'] inspect_source(sl, src) expect(sl.offences).to be_empty end it 'can handle double quotes within embedded expression' do src = ['"#{"A"}"'] inspect_source(sl, src) expect(sl.offences).to be_empty end it 'can handle a built-in constant parsed as string' do # Parser will produce str nodes for constants such as __FILE__. src = ['if __FILE__ == $PROGRAM_NAME', 'end'] inspect_source(sl, src) expect(sl.offences).to be_empty end end end end end
Version data entries
3 entries across 3 versions & 2 rubygems