From 06279731196adf43c37a99b9342f96158a316af8 Mon Sep 17 00:00:00 2001 From: otoyo Date: Sat, 20 Nov 2021 10:32:07 +0900 Subject: [PATCH] Add specs for Ruby literal key regexp --- spec/scanners/ruby_key_literals_spec.rb | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/scanners/ruby_key_literals_spec.rb b/spec/scanners/ruby_key_literals_spec.rb index a7342fdf..a6b43b4b 100644 --- a/spec/scanners/ruby_key_literals_spec.rb +++ b/spec/scanners/ruby_key_literals_spec.rb @@ -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')