diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 1c9a298..5ef56f0 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -107,10 +107,12 @@ class CMockHeaderParser square_bracket_pair_regex_format = /\{[^\{\}]*\}/ # Regex to match one whole block enclosed by two square brackets # Convert user provided string patterns to regex + # Use word bounderies before and after the user regex to limit matching to actual word iso part of a word @inline_function_patterns.each do |user_format_string| user_regex = Regexp.new(user_format_string) - cleanup_spaces_after_user_regex = /\s*/ - inline_function_regex_formats << Regexp.new(user_regex.source + cleanup_spaces_after_user_regex.source) + word_boundary_before_user_regex = /\b/ + cleanup_spaces_after_user_regex = /[ ]*\b/ + inline_function_regex_formats << Regexp.new(word_boundary_before_user_regex.source + user_regex.source + cleanup_spaces_after_user_regex.source) end puts "INLINE REGEXS" diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index 9e22b84..f44fe37 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -2154,8 +2154,13 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do assert_equal(expected, @parser.transform_inline_functions(source)) end - it "Transform inline functions TODO" do + it "Transform inline functions limits deleting user macro to actual line/word" do source = + "#if defined (FORCE_INLINE)\n" + + "#define MY_LIBRARY_INLINE static __inline__ __attribute__ ((always_inline))\n" + + "#else\n" + + "#define MY_LIBRARY_INLINE\n" + + "#endif\n" + "#define INLINE static __inline__ __attribute__ ((always_inline))\n" + "#define INLINE_TWO \\\nstatic\\\ninline\n" + "INLINE uint16_t _somefunc (uint32_t a)\n" + @@ -2177,13 +2182,16 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do "#define INLINE_THREE \\\nstatic\\\ninline" expected = + "#if defined (FORCE_INLINE)\n" + + "#else\n" + + "#endif\n" + "uint16_t _somefunc (uint32_t a);\n" + "uint16_t _somefunc_0 (uint32_t a);\n" + "uint16_t _somefunc_1 (uint32_t a);\n" + "uint16_t _somefunc_2(uint32_t a);\n" @parser.treat_inlines = :include - @parser.inline_function_patterns = ['INLINE_THREE', 'INLINE_TWO', 'INLINE', 'static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__'] + @parser.inline_function_patterns = ['MY_LIBRARY_INLINE', 'INLINE_THREE', 'INLINE_TWO', 'INLINE', 'static __inline__ __attribute__ \(\(always_inline\)\)', 'static __inline__'] assert_equal(expected, @parser.transform_inline_functions(source)) end