nodewrap 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/COPYING +59 -0
  2. data/LEGAL +6 -0
  3. data/LGPL +515 -0
  4. data/LICENSE +6 -0
  5. data/README +31 -0
  6. data/TODO +9 -0
  7. data/example/README +5 -0
  8. data/example/simple_client.rb +12 -0
  9. data/example/simple_server.rb +11 -0
  10. data/example/triangle_client.rb +7 -0
  11. data/example/triangle_server.rb +24 -0
  12. data/ext/MANIFEST +11 -0
  13. data/ext/builtins.h +25 -0
  14. data/ext/cached/ruby-1.6.3/COPYING +340 -0
  15. data/ext/cached/ruby-1.6.3/README +3 -0
  16. data/ext/cached/ruby-1.6.3/classpath.c +3 -0
  17. data/ext/cached/ruby-1.6.3/classpath.h +8 -0
  18. data/ext/cached/ruby-1.6.3/evalinfo.h +62 -0
  19. data/ext/cached/ruby-1.6.3/global_entry.h +15 -0
  20. data/ext/cached/ruby-1.6.3/insns_info.c +40 -0
  21. data/ext/cached/ruby-1.6.3/insns_info.h +19 -0
  22. data/ext/cached/ruby-1.6.3/node_type_descrip.c +150 -0
  23. data/ext/cached/ruby-1.6.3/nodeinfo.c +3182 -0
  24. data/ext/cached/ruby-1.6.3/nodeinfo.h +66 -0
  25. data/ext/cached/ruby-1.6.4/COPYING +340 -0
  26. data/ext/cached/ruby-1.6.4/README +3 -0
  27. data/ext/cached/ruby-1.6.4/classpath.c +3 -0
  28. data/ext/cached/ruby-1.6.4/classpath.h +8 -0
  29. data/ext/cached/ruby-1.6.4/evalinfo.h +62 -0
  30. data/ext/cached/ruby-1.6.4/global_entry.h +15 -0
  31. data/ext/cached/ruby-1.6.4/insns_info.c +40 -0
  32. data/ext/cached/ruby-1.6.4/insns_info.h +19 -0
  33. data/ext/cached/ruby-1.6.4/node_type_descrip.c +150 -0
  34. data/ext/cached/ruby-1.6.4/nodeinfo.c +3182 -0
  35. data/ext/cached/ruby-1.6.4/nodeinfo.h +66 -0
  36. data/ext/cached/ruby-1.6.5/COPYING +56 -0
  37. data/ext/cached/ruby-1.6.5/GPL +340 -0
  38. data/ext/cached/ruby-1.6.5/LEGAL +325 -0
  39. data/ext/cached/ruby-1.6.5/LGPL +504 -0
  40. data/ext/cached/ruby-1.6.5/README +3 -0
  41. data/ext/cached/ruby-1.6.5/classpath.c +3 -0
  42. data/ext/cached/ruby-1.6.5/classpath.h +8 -0
  43. data/ext/cached/ruby-1.6.5/evalinfo.h +63 -0
  44. data/ext/cached/ruby-1.6.5/global_entry.h +15 -0
  45. data/ext/cached/ruby-1.6.5/insns_info.c +40 -0
  46. data/ext/cached/ruby-1.6.5/insns_info.h +19 -0
  47. data/ext/cached/ruby-1.6.5/node_type_descrip.c +150 -0
  48. data/ext/cached/ruby-1.6.5/nodeinfo.c +3182 -0
  49. data/ext/cached/ruby-1.6.5/nodeinfo.h +66 -0
  50. data/ext/cached/ruby-1.6.7/COPYING +56 -0
  51. data/ext/cached/ruby-1.6.7/GPL +340 -0
  52. data/ext/cached/ruby-1.6.7/LEGAL +308 -0
  53. data/ext/cached/ruby-1.6.7/LGPL +504 -0
  54. data/ext/cached/ruby-1.6.7/README +3 -0
  55. data/ext/cached/ruby-1.6.7/classpath.c +3 -0
  56. data/ext/cached/ruby-1.6.7/classpath.h +8 -0
  57. data/ext/cached/ruby-1.6.7/evalinfo.h +63 -0
  58. data/ext/cached/ruby-1.6.7/global_entry.h +15 -0
  59. data/ext/cached/ruby-1.6.7/insns_info.c +40 -0
  60. data/ext/cached/ruby-1.6.7/insns_info.h +19 -0
  61. data/ext/cached/ruby-1.6.7/node_type_descrip.c +150 -0
  62. data/ext/cached/ruby-1.6.7/nodeinfo.c +3182 -0
  63. data/ext/cached/ruby-1.6.7/nodeinfo.h +66 -0
  64. data/ext/cached/ruby-1.6.8/COPYING +56 -0
  65. data/ext/cached/ruby-1.6.8/GPL +340 -0
  66. data/ext/cached/ruby-1.6.8/LEGAL +308 -0
  67. data/ext/cached/ruby-1.6.8/LGPL +504 -0
  68. data/ext/cached/ruby-1.6.8/README +3 -0
  69. data/ext/cached/ruby-1.6.8/classpath.c +3 -0
  70. data/ext/cached/ruby-1.6.8/classpath.h +8 -0
  71. data/ext/cached/ruby-1.6.8/evalinfo.h +63 -0
  72. data/ext/cached/ruby-1.6.8/global_entry.h +15 -0
  73. data/ext/cached/ruby-1.6.8/insns_info.c +40 -0
  74. data/ext/cached/ruby-1.6.8/insns_info.h +19 -0
  75. data/ext/cached/ruby-1.6.8/node_type_descrip.c +150 -0
  76. data/ext/cached/ruby-1.6.8/nodeinfo.c +3182 -0
  77. data/ext/cached/ruby-1.6.8/nodeinfo.h +66 -0
  78. data/ext/cached/ruby-1.8.0/COPYING +56 -0
  79. data/ext/cached/ruby-1.8.0/GPL +340 -0
  80. data/ext/cached/ruby-1.8.0/LEGAL +371 -0
  81. data/ext/cached/ruby-1.8.0/LGPL +504 -0
  82. data/ext/cached/ruby-1.8.0/README +3 -0
  83. data/ext/cached/ruby-1.8.0/classpath.c +27 -0
  84. data/ext/cached/ruby-1.8.0/classpath.h +14 -0
  85. data/ext/cached/ruby-1.8.0/evalinfo.h +65 -0
  86. data/ext/cached/ruby-1.8.0/global_entry.h +10 -0
  87. data/ext/cached/ruby-1.8.0/insns_info.c +40 -0
  88. data/ext/cached/ruby-1.8.0/insns_info.h +19 -0
  89. data/ext/cached/ruby-1.8.0/node_type_descrip.c +150 -0
  90. data/ext/cached/ruby-1.8.0/nodeinfo.c +3199 -0
  91. data/ext/cached/ruby-1.8.0/nodeinfo.h +66 -0
  92. data/ext/cached/ruby-1.8.1/COPYING +56 -0
  93. data/ext/cached/ruby-1.8.1/GPL +340 -0
  94. data/ext/cached/ruby-1.8.1/LEGAL +371 -0
  95. data/ext/cached/ruby-1.8.1/LGPL +504 -0
  96. data/ext/cached/ruby-1.8.1/README +3 -0
  97. data/ext/cached/ruby-1.8.1/classpath.c +27 -0
  98. data/ext/cached/ruby-1.8.1/classpath.h +14 -0
  99. data/ext/cached/ruby-1.8.1/evalinfo.h +59 -0
  100. data/ext/cached/ruby-1.8.1/global_entry.h +10 -0
  101. data/ext/cached/ruby-1.8.1/insns_info.c +40 -0
  102. data/ext/cached/ruby-1.8.1/insns_info.h +19 -0
  103. data/ext/cached/ruby-1.8.1/node_type_descrip.c +150 -0
  104. data/ext/cached/ruby-1.8.1/nodeinfo.c +3199 -0
  105. data/ext/cached/ruby-1.8.1/nodeinfo.h +66 -0
  106. data/ext/cached/ruby-1.8.2/COPYING +56 -0
  107. data/ext/cached/ruby-1.8.2/GPL +340 -0
  108. data/ext/cached/ruby-1.8.2/LEGAL +371 -0
  109. data/ext/cached/ruby-1.8.2/LGPL +504 -0
  110. data/ext/cached/ruby-1.8.2/README +3 -0
  111. data/ext/cached/ruby-1.8.2/classpath.c +45 -0
  112. data/ext/cached/ruby-1.8.2/classpath.h +17 -0
  113. data/ext/cached/ruby-1.8.2/evalinfo.h +60 -0
  114. data/ext/cached/ruby-1.8.2/global_entry.h +10 -0
  115. data/ext/cached/ruby-1.8.2/insns_info.c +40 -0
  116. data/ext/cached/ruby-1.8.2/insns_info.h +19 -0
  117. data/ext/cached/ruby-1.8.2/node_type_descrip.c +150 -0
  118. data/ext/cached/ruby-1.8.2/nodeinfo.c +3199 -0
  119. data/ext/cached/ruby-1.8.2/nodeinfo.h +66 -0
  120. data/ext/cached/ruby-1.8.3/COPYING +56 -0
  121. data/ext/cached/ruby-1.8.3/GPL +340 -0
  122. data/ext/cached/ruby-1.8.3/LEGAL +370 -0
  123. data/ext/cached/ruby-1.8.3/LGPL +504 -0
  124. data/ext/cached/ruby-1.8.3/README +3 -0
  125. data/ext/cached/ruby-1.8.3/classpath.c +45 -0
  126. data/ext/cached/ruby-1.8.3/classpath.h +17 -0
  127. data/ext/cached/ruby-1.8.3/evalinfo.h +61 -0
  128. data/ext/cached/ruby-1.8.3/global_entry.h +10 -0
  129. data/ext/cached/ruby-1.8.3/insns_info.c +40 -0
  130. data/ext/cached/ruby-1.8.3/insns_info.h +19 -0
  131. data/ext/cached/ruby-1.8.3/node_type_descrip.c +150 -0
  132. data/ext/cached/ruby-1.8.3/nodeinfo.c +3199 -0
  133. data/ext/cached/ruby-1.8.3/nodeinfo.h +66 -0
  134. data/ext/cached/ruby-1.8.4/COPYING +56 -0
  135. data/ext/cached/ruby-1.8.4/GPL +340 -0
  136. data/ext/cached/ruby-1.8.4/LEGAL +370 -0
  137. data/ext/cached/ruby-1.8.4/LGPL +504 -0
  138. data/ext/cached/ruby-1.8.4/README +3 -0
  139. data/ext/cached/ruby-1.8.4/classpath.c +45 -0
  140. data/ext/cached/ruby-1.8.4/classpath.h +17 -0
  141. data/ext/cached/ruby-1.8.4/evalinfo.h +61 -0
  142. data/ext/cached/ruby-1.8.4/global_entry.h +10 -0
  143. data/ext/cached/ruby-1.8.4/insns_info.c +40 -0
  144. data/ext/cached/ruby-1.8.4/insns_info.h +19 -0
  145. data/ext/cached/ruby-1.8.4/node_type_descrip.c +150 -0
  146. data/ext/cached/ruby-1.8.4/nodeinfo.c +3199 -0
  147. data/ext/cached/ruby-1.8.4/nodeinfo.h +66 -0
  148. data/ext/cached/ruby-1.8.5/COPYING +56 -0
  149. data/ext/cached/ruby-1.8.5/GPL +340 -0
  150. data/ext/cached/ruby-1.8.5/LEGAL +370 -0
  151. data/ext/cached/ruby-1.8.5/LGPL +504 -0
  152. data/ext/cached/ruby-1.8.5/README +3 -0
  153. data/ext/cached/ruby-1.8.5/classpath.c +45 -0
  154. data/ext/cached/ruby-1.8.5/classpath.h +17 -0
  155. data/ext/cached/ruby-1.8.5/evalinfo.h +61 -0
  156. data/ext/cached/ruby-1.8.5/global_entry.h +10 -0
  157. data/ext/cached/ruby-1.8.5/insns_info.c +40 -0
  158. data/ext/cached/ruby-1.8.5/insns_info.h +19 -0
  159. data/ext/cached/ruby-1.8.5/node_type_descrip.c +150 -0
  160. data/ext/cached/ruby-1.8.5/nodeinfo.c +3187 -0
  161. data/ext/cached/ruby-1.8.5/nodeinfo.h +64 -0
  162. data/ext/cached/ruby-1.8.6/COPYING +56 -0
  163. data/ext/cached/ruby-1.8.6/GPL +340 -0
  164. data/ext/cached/ruby-1.8.6/LEGAL +370 -0
  165. data/ext/cached/ruby-1.8.6/LGPL +504 -0
  166. data/ext/cached/ruby-1.8.6/README +3 -0
  167. data/ext/cached/ruby-1.8.6/classpath.c +45 -0
  168. data/ext/cached/ruby-1.8.6/classpath.h +17 -0
  169. data/ext/cached/ruby-1.8.6/evalinfo.h +61 -0
  170. data/ext/cached/ruby-1.8.6/global_entry.h +10 -0
  171. data/ext/cached/ruby-1.8.6/insns_info.c +40 -0
  172. data/ext/cached/ruby-1.8.6/insns_info.h +19 -0
  173. data/ext/cached/ruby-1.8.6/node_type_descrip.c +150 -0
  174. data/ext/cached/ruby-1.8.6/nodeinfo.c +3187 -0
  175. data/ext/cached/ruby-1.8.6/nodeinfo.h +64 -0
  176. data/ext/classpath.c +42 -0
  177. data/ext/classpath.c.rpp +28 -0
  178. data/ext/classpath.h +17 -0
  179. data/ext/classpath.h.rpp +35 -0
  180. data/ext/evalinfo.h +21 -0
  181. data/ext/evalinfo.h.rpp +49 -0
  182. data/ext/extconf.rb +68 -0
  183. data/ext/generate.rb +201 -0
  184. data/ext/generate_cached.rb +49 -0
  185. data/ext/global_entry.h +10 -0
  186. data/ext/global_entry.h.rpp +25 -0
  187. data/ext/insns_info.c +6079 -0
  188. data/ext/insns_info.c.rpp +210 -0
  189. data/ext/insns_info.h +819 -0
  190. data/ext/insns_info.h.rpp +50 -0
  191. data/ext/node_type_descrip.c +148 -0
  192. data/ext/node_type_descrip.c.rpp +72 -0
  193. data/ext/node_type_descrip.h +17 -0
  194. data/ext/node_type_descrip.rb +169 -0
  195. data/ext/nodeinfo.c +3164 -0
  196. data/ext/nodeinfo.c.rpp +519 -0
  197. data/ext/nodeinfo.h +67 -0
  198. data/ext/nodeinfo.h.rpp +27 -0
  199. data/ext/nodewrap.c +2576 -0
  200. data/ext/nodewrap.h +20 -0
  201. data/ext/read_node_h.rb +19 -0
  202. data/ext/ruby_source_dir.rb +15 -0
  203. data/ext/ruby_version.h +12 -0
  204. data/ext/ruby_version_code.rb +16 -0
  205. data/ext/rubypp.rb +97 -0
  206. data/ext/test.rb +15 -0
  207. data/generate_rdoc.rb +33 -0
  208. data/install.rb +1022 -0
  209. data/lib/as_code.rb +347 -0
  210. data/lib/as_expression.rb +657 -0
  211. data/lib/bytedecoder.rb +848 -0
  212. data/lib/classtree.rb +54 -0
  213. data/lib/methodsig.rb +266 -0
  214. data/lib/node_to_a.rb +34 -0
  215. data/lib/nodepp.rb +71 -0
  216. data/lib/nwdebug.rb +18 -0
  217. data/lib/nwdump.rb +53 -0
  218. data/lib/nwobfusc.rb +57 -0
  219. data/lib/procsig.rb +182 -0
  220. data/lib/test.rb +8 -0
  221. data/metaconfig +10 -0
  222. data/post-config.rb +53 -0
  223. data/post-setup.rb +9 -0
  224. data/pre-config.rb +1 -0
  225. data/run_tests.rb +48 -0
  226. data/test/expression_samples.rb +158 -0
  227. data/test/node_samples.rb +122 -0
  228. data/test/test.rb +39 -0
  229. data/test/test2.rb +7 -0
  230. data/test/test3.rb +5 -0
  231. data/test/test4.rb +5 -0
  232. data/test/test_as_code.rb +249 -0
  233. data/test/test_as_expression.rb +222 -0
  234. data/test/test_methodsig.rb +189 -0
  235. data/test/test_nodewrap.rb +369 -0
  236. metadata +286 -0
@@ -0,0 +1,189 @@
1
+ require 'test/unit'
2
+ require 'test/unit/ui/console/testrunner'
3
+
4
+ dir = File.dirname(__FILE__)
5
+ $:.unshift(dir) if not $:.include?(dir)
6
+ $:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
7
+ $:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
8
+
9
+ require 'nodewrap'
10
+ require 'methodsig'
11
+
12
+ $stdout.sync = true
13
+ $stderr.sync = true
14
+
15
+ class TC_Methodsig < Test::Unit::TestCase
16
+ def no_args_no_parens
17
+ end
18
+
19
+ def test_no_args_no_parens
20
+ name = :no_args_no_parens
21
+ sig = method(name).signature
22
+ assert_equal self.class, sig.origin_class
23
+ assert_equal name.to_s, sig.name
24
+ assert_equal [], sig.arg_names
25
+ assert_equal Hash.new, sig.arg_info
26
+ assert_equal "#{self.class.name}##{name}()", sig.to_s
27
+ end
28
+
29
+ def no_args_with_parens()
30
+ end
31
+
32
+ def test_no_args_with_parens
33
+ name = :no_args_with_parens
34
+ sig = method(name).signature
35
+ assert_equal self.class, sig.origin_class
36
+ assert_equal name.to_s, sig.name
37
+ assert_equal [], sig.arg_names
38
+ assert_equal Hash.new, sig.arg_info
39
+ assert_equal "#{self.class.name}##{name}()", sig.to_s
40
+ end
41
+
42
+ def one_arg(a)
43
+ end
44
+
45
+ def test_one_arg
46
+ name = :one_arg
47
+ sig = method(name).signature
48
+ assert_equal self.class, sig.origin_class
49
+ assert_equal name.to_s, sig.name
50
+ assert_equal [:a], sig.arg_names
51
+ assert_equal Hash[:a=>"a"], sig.arg_info
52
+ assert_equal "#{self.class.name}##{name}(a)", sig.to_s
53
+ end
54
+
55
+ def two_args(a, b)
56
+ end
57
+
58
+ def test_two_args
59
+ name = :two_args
60
+ sig = method(name).signature
61
+ assert_equal self.class, sig.origin_class
62
+ assert_equal name.to_s, sig.name
63
+ assert_equal [:a, :b], sig.arg_names
64
+ assert_equal Hash[:a=>"a", :b=>"b"], sig.arg_info
65
+ assert_equal "#{self.class.name}##{name}(a, b)", sig.to_s
66
+ end
67
+
68
+ def three_args(a, b, c)
69
+ end
70
+
71
+ def test_three_args
72
+ name = :three_args
73
+ sig = method(name).signature
74
+ assert_equal self.class, sig.origin_class
75
+ assert_equal name.to_s, sig.name
76
+ assert_equal [:a, :b, :c], sig.arg_names
77
+ assert_equal Hash[:a=>"a", :b=>"b", :c=>"c"], sig.arg_info
78
+ assert_equal "#{self.class.name}##{name}(a, b, c)", sig.to_s
79
+ end
80
+
81
+ def block_arg(&b)
82
+ end
83
+
84
+ def test_block_arg
85
+ name = :block_arg
86
+ sig = method(name).signature
87
+ assert_equal self.class, sig.origin_class
88
+ assert_equal name.to_s, sig.name
89
+ assert_equal [:b], sig.arg_names
90
+ assert_equal Hash[:b=>"&b"], sig.arg_info
91
+ assert_equal "#{self.class.name}##{name}(&b)", sig.to_s
92
+ end
93
+
94
+ def rest_arg(*r)
95
+ end
96
+
97
+ def test_rest_arg
98
+ name = :rest_arg
99
+ sig = method(name).signature
100
+ assert_equal self.class, sig.origin_class
101
+ assert_equal name.to_s, sig.name
102
+ assert_equal [:r], sig.arg_names
103
+ assert_equal Hash[:r=>"*r"], sig.arg_info
104
+ assert_equal "#{self.class.name}##{name}(*r)", sig.to_s
105
+ end
106
+
107
+ def block_and_rest_arg(*r, &b)
108
+ end
109
+
110
+ def test_block_and_rest_arg
111
+ name = :block_and_rest_arg
112
+ sig = method(name).signature
113
+ assert_equal self.class, sig.origin_class
114
+ assert_equal name.to_s, sig.name
115
+ assert_equal [:r, :b], sig.arg_names
116
+ assert_equal Hash[:r=>"*r", :b=>"&b"], sig.arg_info
117
+ assert_equal "#{self.class.name}##{name}(*r, &b)", sig.to_s
118
+ end
119
+
120
+ def default_arg(a = 1)
121
+ end
122
+
123
+ def test_default_arg
124
+ name = :default_arg
125
+ sig = method(name).signature
126
+ assert_equal self.class, sig.origin_class
127
+ assert_equal name.to_s, sig.name
128
+ assert_equal [:a], sig.arg_names
129
+ assert_equal Hash[:a=>"a=1"], sig.arg_info
130
+ assert_equal "#{self.class.name}##{name}(a=1)", sig.to_s
131
+ end
132
+
133
+ def default_and_nondefault_arg(a, b = 42)
134
+ end
135
+
136
+ def test_default_and_nondefault_arg
137
+ name = :default_and_nondefault_arg
138
+ sig = method(name).signature
139
+ assert_equal self.class, sig.origin_class
140
+ assert_equal name.to_s, sig.name
141
+ assert_equal [:a, :b], sig.arg_names
142
+ assert_equal Hash[:a=>"a", :b=>"b=42"], sig.arg_info
143
+ assert_equal "#{self.class.name}##{name}(a, b=42)", sig.to_s
144
+ end
145
+
146
+ def default_and_rest(a = 42, *r)
147
+ end
148
+
149
+ def test_default_and_rest
150
+ name = :default_and_rest
151
+ sig = method(name).signature
152
+ assert_equal self.class, sig.origin_class
153
+ assert_equal name.to_s, sig.name
154
+ assert_equal [:a, :r], sig.arg_names
155
+ assert_equal Hash[:a=>"a=42", :r=>"*r"], sig.arg_info
156
+ assert_equal "#{self.class.name}##{name}(a=42, *r)", sig.to_s
157
+ end
158
+
159
+ def default_and_rest_and_block(a = 42, *r, &b)
160
+ end
161
+
162
+ def test_default_and_rest_and_block
163
+ name = :default_and_rest_and_block
164
+ sig = method(name).signature
165
+ assert_equal self.class, sig.origin_class
166
+ assert_equal name.to_s, sig.name
167
+ assert_equal [:a, :r, :b], sig.arg_names
168
+ assert_equal Hash[:a=>"a=42", :r=>"*r", :b=>"&b"], sig.arg_info
169
+ assert_equal "#{self.class.name}##{name}(a=42, *r, &b)", sig.to_s
170
+ end
171
+
172
+ def nondefault_and_default_and_rest_and_block(a, b = 42, *r, &block)
173
+ end
174
+
175
+ def test_nondefault_and_default_and_rest_and_block
176
+ name = :nondefault_and_default_and_rest_and_block
177
+ sig = method(name).signature
178
+ assert_equal self.class, sig.origin_class
179
+ assert_equal name.to_s, sig.name
180
+ assert_equal [:a, :b, :r, :block], sig.arg_names
181
+ assert_equal Hash[:a=>"a", :b=>"b=42", :r=>"*r", :block=>"&block"], sig.arg_info
182
+ assert_equal "#{self.class.name}##{name}(a, b=42, *r, &block)", sig.to_s
183
+ end
184
+ end
185
+
186
+ if __FILE__ == $0 then
187
+ exit Test::Unit::AutoRunner.run
188
+ end
189
+
@@ -0,0 +1,369 @@
1
+ require 'test/unit'
2
+ require 'test/unit/ui/console/testrunner'
3
+
4
+ dir = File.dirname(__FILE__)
5
+ $:.unshift(dir) if not $:.include?(dir)
6
+ $:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
7
+ $:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
8
+
9
+ require 'nodewrap'
10
+ require 'pp'
11
+ require 'nodepp'
12
+
13
+ require "node_samples"
14
+
15
+ $stdout.sync = true
16
+ $stderr.sync = true
17
+
18
+ # Instance methods defined in Class get returned by
19
+ # rb_class_instance_methods, though they are not in the class's method
20
+ # table. Having this here ensures that we don't accidentally try to
21
+ # dump methods that aren't in the class we are trying to dump.
22
+ class Class
23
+ def xyzzy
24
+ end
25
+ end
26
+
27
+ class TC_Nodewrap < Test::Unit::TestCase
28
+ module Foo
29
+ def foo(n=1)
30
+ # A fancy way to return 42
31
+ if false then
32
+ answer = 0
33
+ else
34
+ answer = 0
35
+ (1..42).each do |i|
36
+ answer += (i / i)
37
+ end
38
+ end
39
+ return n * answer
40
+ end
41
+ end
42
+
43
+ include Foo
44
+
45
+ Tmp_Foo = nil
46
+
47
+ # For the cvar proc test
48
+ @@a = 42
49
+
50
+ def initialize(test_method_name)
51
+ # TODO: This seems to be the only way to get tests defined with #
52
+ # define_method to run on 1.8.1 and earlier.
53
+ @method_name = test_method_name
54
+ @test_passed = true
55
+ end
56
+
57
+ def test_node_eval
58
+ node = Node.compile_string('1 + 1')
59
+ assert_equal 2, node.eval(self)
60
+ end
61
+
62
+ if not Object.const_defined?(:VM) then
63
+ define_method(:test_proc_body) do
64
+ p = proc { 1 + 1 }
65
+ assert_equal p.call, p.body.eval(self)
66
+ end
67
+ end
68
+
69
+ def test_method_node
70
+ m = method(:foo)
71
+ n = m.body
72
+ if Object.const_defined?(:VM) and
73
+ VM.const_defined?(:InstructionSequence) then
74
+ # YARV
75
+ assert_equal Node::METHOD, n.class
76
+ else
77
+ # pre-YARV
78
+ assert_equal Node::SCOPE, n.class
79
+ end
80
+ end
81
+
82
+ def test_add_method
83
+ m = method(:foo)
84
+ n = m.body
85
+ klass = Class.new
86
+ klass.instance_eval do
87
+ add_method(:foo, n, Noex::PUBLIC)
88
+ end
89
+ obj = klass.new
90
+ assert_equal 42, obj.foo
91
+ end
92
+
93
+ def test_marshal_node
94
+ m = method(:foo)
95
+ n = m.body
96
+ d = Marshal.dump(n)
97
+ n2 = Marshal.load(d)
98
+ assert_equal n.nd_file, n2.nd_file
99
+ assert_equal n.nd_type, n2.nd_type
100
+ assert_equal n.flags, n2.flags
101
+ klass = Class.new;
102
+ klass.instance_eval do
103
+ add_method(:foo, n2, Noex::PUBLIC)
104
+ end
105
+ obj = klass.new
106
+ assert_equal 42, obj.foo
107
+ end
108
+
109
+ def test_marshal_proc
110
+ p = proc { 1 + 1 }
111
+ d = Marshal.dump(p)
112
+ u = Marshal.load(d)
113
+ p2 = u.bind(binding)
114
+ assert_equal(p.call, p2.call)
115
+ end
116
+
117
+ class MarshalMethodHelper
118
+ include Foo
119
+ end
120
+
121
+ def test_marshal_method
122
+ o = MarshalMethodHelper.new
123
+ m = o.method(:foo)
124
+ d = Marshal.dump(m)
125
+ m2 = Marshal.load(d)
126
+ assert_equal m.call, m2.call
127
+ end
128
+
129
+ def test_marshal_unbound_method
130
+ o = MarshalMethodHelper.new
131
+ u = o.method(:foo).unbind
132
+ d = Marshal.dump(u)
133
+ u2 = Marshal.load(d)
134
+ m = u.bind(o)
135
+ m2 = u.bind(o)
136
+ assert_equal m.call, m2.call
137
+ end
138
+
139
+ def test_ruby_eval_tree
140
+ assert Node === $ruby_eval_tree
141
+ end
142
+
143
+ def test_ruby_eval_tree_begin
144
+ assert_equal nil, $ruby_eval_tree_begin
145
+ end
146
+
147
+ def test_proc_unbind
148
+ p = proc { 1 + 1 }
149
+ u = p.unbind
150
+ p2 = u.bind(binding)
151
+ assert_equal(p.call, p2.call)
152
+ end
153
+
154
+ class TestClassBase
155
+ # for testing super()
156
+ def foo
157
+ return 42
158
+ end
159
+ end
160
+
161
+ class TestClass < TestClassBase
162
+ include Foo
163
+ FOO = 1
164
+ @foo = 2
165
+ @@foo = 3
166
+ class << self
167
+ FOO = 4
168
+ @foo = 5
169
+ end
170
+
171
+ # for testing cvar
172
+ # (can't be in base class due to change in 1.9 of class var lookup)
173
+ @@a = 42
174
+ end
175
+
176
+ @@test_class = TestClass
177
+
178
+ def setup
179
+ self.class.instance_eval do
180
+ remove_const :TestClass if defined?(TestClass)
181
+ const_set :TestClass, @@test_class
182
+ end
183
+ end
184
+
185
+ def test_marshal_class
186
+ begin
187
+ assert_equal 5, TestClass.singleton_class.instance_eval('@foo')
188
+ assert_equal 2, TestClass.instance_eval('@foo')
189
+
190
+ d = Marshal.dump(TestClass)
191
+
192
+ # Thread critical should have been reset by the class restorer
193
+ if not defined?(VM) then
194
+ assert_equal false, Thread.critical
195
+ end
196
+
197
+ # Make sure the class instance variables are still set
198
+ assert_equal 5, TestClass.singleton_class.instance_eval('@foo')
199
+ assert_equal 2, TestClass.instance_eval('@foo')
200
+
201
+ self.class.instance_eval { remove_const :TestClass }
202
+
203
+ Marshal.load(d)
204
+ c = TestClass
205
+ assert_equal Class, c.class
206
+ a = c.ancestors
207
+ assert a.include?(Object)
208
+ assert a.include?(Kernel)
209
+ assert a.include?(Foo)
210
+ assert a.include?(c)
211
+
212
+ # Constant lookup
213
+ assert_equal 1, c::FOO
214
+
215
+ # Constant lookup in singleton class
216
+ result = class << c
217
+ FOO
218
+ end
219
+ assert_equal 4, result
220
+
221
+ # Class instance variable lookup
222
+ result = c.instance_eval do
223
+ @foo
224
+ end
225
+ assert_equal 2, result
226
+
227
+ # Singleton class instance variable lookup
228
+ result = class << c
229
+ @foo
230
+ end
231
+ assert_equal 5, result
232
+
233
+ # Class variable lookup
234
+ # This is a little bit messy, but it was the only way I could figure
235
+ # to get at @@foo
236
+ self.class.instance_eval do
237
+ remove_const :Tmp_Foo
238
+ const_set :Tmp_Foo, c
239
+ end
240
+ eval "class Tmp_Foo; $at_at_foo = @@foo; end"
241
+ result = $at_at_foo
242
+ assert_equal 3, result
243
+
244
+ # Test method call
245
+ f = c.new
246
+ assert_equal 42, f.foo()
247
+ assert_equal 42*42, f.foo(42)
248
+
249
+ # Thread critical should have been reset by the class restorer
250
+ if not defined?(VM) then
251
+ assert_equal false, Thread.critical
252
+ end
253
+
254
+ # Also make sure the class instance variables are still set
255
+ assert_equal 5, TestClass.singleton_class.instance_eval('@foo')
256
+ assert_equal 2, TestClass.instance_eval('@foo')
257
+
258
+ ensure
259
+ if not defined?(VM) then
260
+ Thread.critical = false
261
+ end
262
+ end
263
+ end
264
+
265
+ extend Test::Unit::Assertions
266
+
267
+ Method_Node_Samples.each do |node_name, sample_code|
268
+ p = proc {
269
+ c = TestClass.dup
270
+ c.class_eval <<-END_DEF
271
+ def foo
272
+ #{sample_code}
273
+ end
274
+ END_DEF
275
+ TC_Nodewrap.const_set("TestClass__#{node_name}", c)
276
+
277
+ o = c.new
278
+ m = o.method(:foo)
279
+ n = m.body
280
+ # puts "dumping first method"
281
+ # pp o.method(:foo).body
282
+ d = Marshal.dump(n)
283
+ n2 = Marshal.load(d)
284
+
285
+ klass2 = Class.new(TestClassBase)
286
+ klass2.class_eval do
287
+ # for testing cvar
288
+ # (can't be in base class due to change in 1.9 of class var lookup)
289
+ @@a = 42
290
+ add_method(:foo, n2, Noex::PUBLIC)
291
+ end
292
+ obj1 = o
293
+ obj2 = klass2.new
294
+
295
+ orig_result = nil
296
+ orig_exc = nil
297
+ begin
298
+ orig_result = o.foo() { 17 }
299
+ rescue Exception => exc
300
+ orig_exc = exc
301
+ end
302
+
303
+ # puts "getting obj2 method"
304
+ # m = obj2.method(:foo)
305
+ # puts "getting obj2 method body"
306
+ # b = m.body
307
+ # puts "getting type"
308
+ # p b.class
309
+ # p b.members
310
+ # p b.rval
311
+ # p b.next
312
+ # p b.tbl
313
+ # puts "dumping second method"
314
+ # pp obj2.method(:foo).body
315
+ dup_result = nil
316
+ dup_exc = nil
317
+ begin
318
+ dup_result = obj2.foo() { 17 }
319
+ rescue Exception => exc
320
+ dup_exc = exc
321
+ end
322
+
323
+ assert_equal orig_exc, dup_exc
324
+ assert_equal orig_result, dup_result
325
+ }
326
+ define_method "test_dump_method_#{node_name}", p
327
+ end
328
+
329
+ Proc_Node_Samples.each do |node_name, sample_code|
330
+ p = proc {
331
+ p_orig = eval <<-END_DEF
332
+ proc {
333
+ #{sample_code}
334
+ }
335
+ END_DEF
336
+
337
+ #puts "dumping"
338
+ d = Marshal.dump(p_orig)
339
+ #puts "loading"
340
+ u = Marshal.load(d)
341
+ p_new = u.bind(binding)
342
+
343
+ orig_result = nil
344
+ orig_exc = nil
345
+ begin
346
+ orig_result = p_orig.call
347
+ rescue Exception => exc
348
+ orig_exc = exc
349
+ end
350
+
351
+ dup_result = nil
352
+ dup_exc = nil
353
+ begin
354
+ dup_result = p_new.call
355
+ rescue Exception => exc
356
+ dup_exc = exc
357
+ end
358
+
359
+ assert_equal orig_exc, dup_exc
360
+ assert_equal orig_result, dup_result
361
+ }
362
+ define_method "test_dump_proc_#{node_name}", p
363
+ end
364
+ end
365
+
366
+ if __FILE__ == $0 then
367
+ exit Test::Unit::AutoRunner.run
368
+ end
369
+