module ZenTestMapping

def munge name

def munge name
  name = name.to_s.dup
  is_cls_method = name.sub!(/^self\./, '')
  name = @@method_map[name] if @@method_map.has_key? name
  name = name.sub(/=$/, '_equals')
  name = name.sub(/\?$/, '_eh')
  name = name.sub(/\!$/, '_bang')
  name = yield name if block_given?
  name = "class_" + name if is_cls_method
  name
end

def normal_to_test name

(used for arithmetic, etc
taking into account names composed of metacharacters
Generates a test method name from a normal method,
def normal_to_test name
  "test_#{munge name}"
end

def test_to_normal(name, klassname=nil)

#normal_to_test().
symbolic names which may have been anglicised by
corresponding normal method name, taking into account
Converts a method name beginning with test to its
def test_to_normal(name, klassname=nil)
  unmunge(name.to_s.sub(/^test_/, '')) do |n|
    if defined? @inherited_methods then
      known_methods = (@inherited_methods[klassname] || {}).keys.sort.reverse
      known_methods_re = known_methods.map {|s| Regexp.escape(s) }.join("|")
      n = n.sub(/^(#{known_methods_re})(_.*)?$/) { $1 } unless
        known_methods_re.empty?
      n
    end
  end
end

def unmunge name

def unmunge name
  name = name.to_s.dup
  is_cls_method = name.sub!(/^class_/, '')
  name = name.sub(/_equals(_.*)?$/, '=') unless name =~ /index/
  name = name.sub(/_bang(_.*)?$/, '!')
  name = name.sub(/_eh(_.*)?$/, '?')
  name = name.sub(/^(#{@@mapped_re})(_.*)?$/) {$1}
  name = yield name if block_given?
  name = @@method_map[name] if @@method_map.has_key? name
  name = 'self.' + name if is_cls_method
  name
end