Skip to content

Commit cb620ee

Browse files
authored
Merge pull request #855 from ThrowTheSwitch/fix/module-naming-conventions
Match generate_module naming conventions to their help text
2 parents 34def09 + f03f932 commit cb620ee

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

‎auto/generate_module.rb‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def neutralize_filename(name, start_cap: true)
182182
############################
183183
def create_filename(part1, part2 = '')
184184
name = part2.empty? ? part1 : "#{part1}_#{part2}"
185-
case @options[:naming]
186-
when 'bumpy' then neutralize_filename(name, start_cap: false).delete('_')
187-
when 'camel' then neutralize_filename(name).delete('_')
185+
case @options[:naming]&.to_s
186+
when 'bumpy' then neutralize_filename(name).delete('_')
187+
when 'camel' then neutralize_filename(name, start_cap: false).delete('_')
188188
when 'snake' then neutralize_filename(name).downcase
189189
when 'caps' then neutralize_filename(name).upcase
190190
else name
@@ -221,7 +221,7 @@ def generate(module_name, pattern = nil)
221221
end
222222
if @options[:update_svn]
223223
`svn add \"#{file[:path]}\"`
224-
if $!.exitstatus.zero?
224+
if $?.exitstatus.zero?
225225
puts "File #{file[:path]} created and added to source control"
226226
else
227227
puts "File #{file[:path]} created but FAILED adding to source control!"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# =========================================================================
2+
# Unity - A Test Framework for C
3+
# ThrowTheSwitch.org
4+
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
5+
# SPDX-License-Identifier: MIT
6+
# =========================================================================
7+
8+
require '../auto/generate_module.rb'
9+
10+
# Each naming convention produces the case its help text names, whether the
11+
# convention arrives as a string or, from YAML, as a symbol
12+
describe 'UnityModuleGenerator naming' do
13+
def filename(naming, name = 'mad_science')
14+
UnityModuleGenerator.new(naming: naming).create_filename(name)
15+
end
16+
17+
it 'makes bumpy names start with a capital' do
18+
expect(filename('bumpy')).to eq('MadScience')
19+
end
20+
21+
it 'makes camel names start with a lowercase letter' do
22+
expect(filename('camel')).to eq('madScience')
23+
end
24+
25+
it 'makes snake and caps names' do
26+
expect(filename('snake', 'MadScience')).to eq('mad_science')
27+
expect(filename('caps', 'MadScience')).to eq('MAD_SCIENCE')
28+
end
29+
30+
it 'accepts a convention given as a symbol' do
31+
expect(filename(:bumpy)).to eq('MadScience')
32+
expect(filename(:snake, 'MadScience')).to eq('mad_science')
33+
end
34+
35+
it 'keeps a name as given without a convention' do
36+
expect(filename(nil, 'MadScience')).to eq('MadScience')
37+
end
38+
end

0 commit comments

Comments
 (0)