Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Add specs for Ruby literal key regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
otoyo committed Nov 20, 2021
1 parent 11c8825 commit 0627973
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/scanners/ruby_key_literals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@
Object.new.extend I18n::Tasks::Scanners::RubyKeyLiterals
end

describe '#literal_re' do
subject do
/(#{scanner.literal_re})/x =~ key
Regexp.last_match(1)
end

context 'string' do
context 'single quoted' do
let(:key) { %('some_key') }
it { is_expected.to eq(key) }
end

context 'double quoted' do
let(:key) { %q("#{some_key}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
end
end

context 'symbol' do
context 'regular literal' do
let(:key) { %(:some_key) }
it { is_expected.to eq(key) }
end

context 'single quoted' do
let(:key) { %(:'some_key') }
it { is_expected.to eq(key) }
end

context 'double quoted' do
let(:key) { %q(:"#{some_key}") } # rubocop:disable Lint/InterpolationCheck
it { is_expected.to eq(key) }
end
end
end

describe '#valid_key?' do
it 'allows forward slash in key' do
expect(scanner).to be_valid_key('category/product')
Expand Down

0 comments on commit 0627973

Please sign in to comment.