From 99422cddb12ea49df1b1de9cb6428347493f53bf Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Mon, 11 Jan 2010 12:46:43 +0000 Subject: [PATCH] * added tests for single bracket arrays as pointers (need to think of desired way to handle mulitdimensional arrays) * rolled unity float support in as default. user can still overload with :treat_as git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@153 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_config.rb | 2 ++ lib/cmock_header_parser.rb | 8 +++--- .../expect_and_return_treat_as.yml | 25 +++++++++++++++++++ .../test_interactions/parsing_challenges.yml | 5 +++- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 1c68e91..471d7f1 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -94,6 +94,8 @@ class CMockConfig 'pCHAR' => 'STRING', 'cstring' => 'STRING', 'CSTRING' => 'STRING', + 'float' => 'FLOAT', + 'double' => 'FLOAT', } end end diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 48b7d34..236e959 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -126,9 +126,9 @@ class CMockHeaderParser return 'void' else c=0 - arg_list.gsub!(/(\w)\s*\[[\s\d]*\]/,'*\1') # magically turn brackets into asterisks - arg_list.gsub!(/\s+\*/,'*') # remove space to place asterisks with type (where they belong) - arg_list.gsub!(/\*(\w)/,'* \1') # pull asterisks away from arg to place asterisks with type (where they belong) + arg_list.gsub!(/(\w+)(?:\s*\[[\s\d]*\])+/,'*\1') # magically turn brackets into asterisks + arg_list.gsub!(/\s+\*/,'*') # remove space to place asterisks with type (where they belong) + arg_list.gsub!(/\*(\w)/,'* \1') # pull asterisks away from arg to place asterisks with type (where they belong) #scan argument list for function pointers and replace them with custom types arg_list.gsub!(/([\w\s]+)\(*\(\s*\*([\w\s]+)\)\s*\(([\w\s,]+)\)\)*/) do |m| @@ -160,7 +160,7 @@ class CMockHeaderParser def parse_declaration(declaration) decl = {} - + regex_match = @declaration_parse_matcher.match(declaration) raise "Failed parsing function declaration: '#{declaration}'" if regex_match.nil? diff --git a/test/system/test_interactions/expect_and_return_treat_as.yml b/test/system/test_interactions/expect_and_return_treat_as.yml index 7108b2e..e48c960 100644 --- a/test/system/test_interactions/expect_and_return_treat_as.yml +++ b/test/system/test_interactions/expect_and_return_treat_as.yml @@ -17,11 +17,13 @@ MY_INT foo(MY_HEX a); MY_INT bar(MY_HEX b); MY_STRING foo_char_strings(MY_STRING a, MY_STRING b); + float float_adder(float a, float b); :source: :header: | MY_INT function_a(MY_INT a, MY_INT b); MY_STRING function_b(MY_STRING a, MY_STRING b); + float function_c(float a, float b); :code: | MY_INT function_a(MY_INT a, MY_INT b) @@ -34,6 +36,11 @@ return foo_char_strings(a, b); } + float function_c(float a, float b) + { + return float_adder(b, a); + } + :tests: :common: | void setUp(void) {} @@ -77,4 +84,22 @@ TEST_ASSERT_EQUAL_STRING("boing!", function_b((MY_STRING)"jello", (MY_STRING)"jiggle")); } + - :pass: TRUE + :should: 'handle floating point numbers with Unity support: pass' + :code: | + test() + { + float_adder_ExpectAndReturn(1.2345, 6.7890, 8.0235); + TEST_ASSERT_EQUAL_FLOAT(8.0235, function_c(6.7890, 1.2345)); + } + + - :pass: FALSE + :should: 'handle floating point numbers with Unity support: fail' + :code: | + test() + { + float_adder_ExpectAndReturn(1.2345, 6.7892, 8.0235); + TEST_ASSERT_EQUAL_FLOAT(8.0235, function_c(6.7890, 1.2345)); + } + ... diff --git a/test/system/test_interactions/parsing_challenges.yml b/test/system/test_interactions/parsing_challenges.yml index 07b55dd..16682ee 100644 --- a/test/system/test_interactions/parsing_challenges.yml +++ b/test/system/test_interactions/parsing_challenges.yml @@ -58,6 +58,9 @@ TypeDefInt uses_typedef_like_names(TypeDefInt typedefvar); + void oh_brackets1(int fudge[5]); + void oh_brackets2(int caramel[]); + :source: :header: | U16* exercise_return_pointers(int a); @@ -66,7 +69,7 @@ char exercise_multiline_declarations(int a, unsigned int b); void exercise_double_pointers(unsigned int a); int exercise_many_descriptors(int a); - TypeDefInt exercise_typedef_like_names(TypeDefInt a); + TypeDefInt exercise_typedef_like_names(TypeDefInt a); :code: | int A, B, C;