From ac7f5566c0f7ea5f549eb4f40bb49fbebf9e2fd8 Mon Sep 17 00:00:00 2001 From: Taichi Ishitani Date: Wed, 15 Jan 2025 23:24:17 +0900 Subject: [PATCH] restricted name pattern (refs: rggen/rggen#233) --- lib/rggen/core/utility/regexp_patterns.rb | 2 +- spec/rggen/core/utility/regexp_patterns_spec.rb | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/rggen/core/utility/regexp_patterns.rb b/lib/rggen/core/utility/regexp_patterns.rb index b955154..ee999a0 100644 --- a/lib/rggen/core/utility/regexp_patterns.rb +++ b/lib/rggen/core/utility/regexp_patterns.rb @@ -12,7 +12,7 @@ def included(klass) private - VARIABLE_NAME_PATTERN = /[a-z_]\w*/i + VARIABLE_NAME_PATTERN = /[a-z]\w+/i def variable_name VARIABLE_NAME_PATTERN diff --git a/spec/rggen/core/utility/regexp_patterns_spec.rb b/spec/rggen/core/utility/regexp_patterns_spec.rb index ee677a6..96edcc2 100644 --- a/spec/rggen/core/utility/regexp_patterns_spec.rb +++ b/spec/rggen/core/utility/regexp_patterns_spec.rb @@ -15,21 +15,20 @@ def regexp_pattern(type) describe '#variable_name' do it '識別子名にマッチするす' do [ - /_/i, - /_+/i, - /[a-z]/i, - /[a-z]+/i, - /_\d/i, - /_\d+/i, + /[a-z]{2,}/i, /[a-z]\d/i, /[a-z]\d+/i, - /[_a-z]\w+/i + /[a-z]\w+/i ].each do |pattern| string = random_string(pattern) expect(string).to match(regexp_pattern(:variable_name)) end [ + /_/, + /_+/, + /_\w+/, + /[a-z]/i, /\d/i, /\d+/i, /\d_/i,