class CMockUnityHelperParser

CMock Project - Automatic Mock Generation for C
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]

Attributes

c_types[RW]

Public Class Methods

new(config) click to toggle source
# File vendor/cmock/lib/cmock_unityhelper_parser.rb, line 10
def initialize(config)
  @config = config
  @fallback = @config.plugins.include?(:array) ? 'UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY' : 'UNITY_TEST_ASSERT_EQUAL_MEMORY'
  @c_types = map_c_types.merge(import_source)
end

Public Instance Methods

get_helper(ctype) click to toggle source
# File vendor/cmock/lib/cmock_unityhelper_parser.rb, line 16
def get_helper(ctype)
  lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/, '\1\3\5\6').strip.gsub(/\s+/, '_')
  return [@c_types[lookup], ''] if @c_types[lookup]

  if lookup =~ /\*$/
    lookup = lookup.gsub(/\*$/, '')
    return [@c_types[lookup], '*'] if @c_types[lookup]
  else
    lookup += '*'
    return [@c_types[lookup], '&'] if @c_types[lookup]
  end
  return ['UNITY_TEST_ASSERT_EQUAL_PTR', ''] if ctype =~ /cmock_\w+_ptr\d+/
  raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown

  lookup =~ /\*$/ ? [@fallback, '&'] : [@fallback, '']
end