Merge pull request #855 from ThrowTheSwitch/fix/module-naming-conventions

Match generate_module naming conventions to their help text
This commit is contained in:
Mark VanderVoord
2026-10-17 11:44:16 -04:00
committed by GitHub
2 changed files with 42 additions and 4 deletions
+4 -4
View File
@@ -182,9 +182,9 @@ class UnityModuleGenerator
############################
def create_filename(part1, part2 = '')
name = part2.empty? ? part1 : "#{part1}_#{part2}"
case @options[:naming]
when 'bumpy' then neutralize_filename(name, start_cap: false).delete('_')
when 'camel' then neutralize_filename(name).delete('_')
case @options[:naming]&.to_s
when 'bumpy' then neutralize_filename(name).delete('_')
when 'camel' then neutralize_filename(name, start_cap: false).delete('_')
when 'snake' then neutralize_filename(name).downcase
when 'caps' then neutralize_filename(name).upcase
else name
@@ -221,7 +221,7 @@ class UnityModuleGenerator
end
if @options[:update_svn]
`svn add \"#{file[:path]}\"`
if $!.exitstatus.zero?
if $?.exitstatus.zero?
puts "File #{file[:path]} created and added to source control"
else
puts "File #{file[:path]} created but FAILED adding to source control!"
+38
View File
@@ -0,0 +1,38 @@
# =========================================================================
# Unity - A Test Framework for C
# ThrowTheSwitch.org
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================
require '../auto/generate_module.rb'
# Each naming convention produces the case its help text names, whether the
# convention arrives as a string or, from YAML, as a symbol
describe 'UnityModuleGenerator naming' do
def filename(naming, name = 'mad_science')
UnityModuleGenerator.new(naming: naming).create_filename(name)
end
it 'makes bumpy names start with a capital' do
expect(filename('bumpy')).to eq('MadScience')
end
it 'makes camel names start with a lowercase letter' do
expect(filename('camel')).to eq('madScience')
end
it 'makes snake and caps names' do
expect(filename('snake', 'MadScience')).to eq('mad_science')
expect(filename('caps', 'MadScience')).to eq('MAD_SCIENCE')
end
it 'accepts a convention given as a symbol' do
expect(filename(:bumpy)).to eq('MadScience')
expect(filename(:snake, 'MadScience')).to eq('mad_science')
end
it 'keeps a name as given without a convention' do
expect(filename(nil, 'MadScience')).to eq('MadScience')
end
end