File: inline_mapping_instead_of_zentest_mapping

package info (click to toggle)
ruby-inline 3.12.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 408 kB
  • sloc: ruby: 1,504; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,887 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Author: Gunnar Wolf <gwolf@debian.org>
Forwarded: Not-needed
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=658889
Last-Update: 2012-02-06
Applied-upstream: no
Description: Replaced ZenTestMapping usage with custom implementation
 This avoids pulling in a series of build-dependencies while allowing
 us to run the test suite

Index: ruby-inline/lib/inline.rb
===================================================================
--- ruby-inline.orig/lib/inline.rb	2014-01-15 23:29:03.227042905 +0100
+++ ruby-inline/lib/inline.rb	2014-01-15 23:29:05.000000000 +0100
@@ -52,7 +52,7 @@ require "digest/md5"
 require 'fileutils'
 #require 'rubygems'
 
-require 'zentest_mapping'
+require 'inline_method_name_mapping'
 
 $TESTING = false unless defined? $TESTING
 
@@ -165,7 +165,7 @@ module Inline
 
   class C
 
-    include ZenTestMapping
+    include MethodNameMapping
 
     MAGIC_ARITY_THRESHOLD = 15
     MAGIC_ARITY = -1
@@ -259,7 +259,7 @@ module Inline
       signature = parse_signature(src, !expand_types)
       function_name = signature['name']
       method_name = options[:method_name]
-      method_name ||= test_to_normal function_name
+      method_name ||= to_ruby function_name
       return_type = signature['return']
       arity = options[:arity] || signature['arity']
 
Index: ruby-inline/lib/inline_method_name_mapping.rb
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ruby-inline/lib/inline_method_name_mapping.rb	2014-01-15 23:30:02.314633885 +0100
@@ -0,0 +1,48 @@
+module MethodNameMapping
+  @@method_map = {
+    'bang'         => '!',
+    'percent'      => '%',
+    'and'          => '&',
+    'times'        => '*',
+    'times2'       => '**',
+    'plus'         => '+',
+    'minus'        => '-',
+    'div'          => '/',
+    'lt'           => '<',
+    'lte'          => '<=',
+    'spaceship'    => '<=>',
+    'lt2'          => '<<',
+    'equals2'      => '==',
+    'equals3'      => '===',
+    'equalstilde'  => '=~',
+    'gt'           => '>',
+    'ge'           => '>=',
+    'gt2'          => '>>',
+    'unary_plus'   => '+@',
+    'unary_minus'  => '-@',
+    'index'        => '[]',
+    'index_equals' => '[]=',
+    'carat'        => '^',
+    'or'           => '|',
+    'tilde'        => '~',
+  }
+
+  @@mapped_re = @@method_map.values.map {|s| Regexp.escape(s)}.join("|")
+
+  def to_ruby(name)
+    name = name.to_s.dup
+    is_class_method = name.sub!(/^class_/, '')
+
+    if @@method_map.has_key?(name)
+      name=@@method_map[name]
+    elsif name.sub!(/_equals(_.*)?$/, '=')
+    elsif name.sub!(/_bang(_.*)?$/, '!')
+    elsif name.sub!(/_eh(_.*)?$/, '?')
+    elsif name =~ /(.*?)_/ and @@method_map.has_key? $1
+      name = @@method_map[$1]
+    end
+    name = 'self.' + name if is_class_method
+
+    return name
+  end
+end