ruby-decompiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,267 @@
1
+ require 'test/unit'
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $:.unshift(dir) if not $:.include?(dir)
5
+ $:.unshift("#{dir}/../lib") if not $:.include?("#{dir}/../lib")
6
+ $:.unshift("#{dir}/../ext") if not $:.include?("#{dir}/../ext")
7
+
8
+ require 'internal/method/signature'
9
+
10
+ $stdout.sync = true
11
+ $stderr.sync = true
12
+
13
+ class TC_Methodsig < Test::Unit::TestCase
14
+ def check_args(expected_arg_info, sig)
15
+ expected_arg_info.each do |name, value|
16
+ assert_equal name, sig.args[name].name
17
+ assert_equal value, sig.args[name].to_s
18
+ if value =~ /=/ then
19
+ default = value.sub(/.*=/, '')
20
+ assert_equal default, sig.args[name].default
21
+ assert_equal true, sig.args[name].optional?
22
+ assert_equal false, sig.args[name].required?
23
+ assert_equal false, sig.args[name].rest?
24
+ assert_equal false, sig.args[name].block?
25
+ elsif ?* == value[0] then
26
+ assert_equal nil, sig.args[name].default
27
+ assert_equal true, sig.args[name].optional?
28
+ assert_equal false, sig.args[name].required?
29
+ assert_equal true, sig.args[name].rest?
30
+ assert_equal false, sig.args[name].block?
31
+ elsif ?& == value[0] then
32
+ assert_equal nil, sig.args[name].default
33
+ assert_equal true, sig.args[name].optional?
34
+ assert_equal false, sig.args[name].required?
35
+ assert_equal false, sig.args[name].rest?
36
+ assert_equal true, sig.args[name].block?
37
+ else
38
+ assert_equal nil, sig.args[name].default
39
+ assert_equal false, sig.args[name].optional?
40
+ assert_equal true, sig.args[name].required?
41
+ assert_equal false, sig.args[name].rest?
42
+ assert_equal false, sig.args[name].block?
43
+ end
44
+ end
45
+ assert_equal expected_arg_info.size, sig.args.size
46
+ end
47
+
48
+ def no_args_no_parens
49
+ end
50
+
51
+ def test_no_args_no_parens
52
+ name = :no_args_no_parens
53
+ sig = method(name).signature
54
+ assert_equal self.class, sig.origin_class
55
+ assert_equal name.to_s, sig.name
56
+ assert_equal [], sig.arg_names
57
+ check_args({}, sig)
58
+ assert_equal "#{self.class.name}##{name}()", sig.to_s
59
+ end
60
+
61
+ def no_args_with_parens()
62
+ end
63
+
64
+ def test_no_args_with_parens
65
+ name = :no_args_with_parens
66
+ sig = method(name).signature
67
+ assert_equal self.class, sig.origin_class
68
+ assert_equal name.to_s, sig.name
69
+ assert_equal [], sig.arg_names
70
+ check_args({}, sig)
71
+ assert_equal "#{self.class.name}##{name}()", sig.to_s
72
+ end
73
+
74
+ def one_arg(a)
75
+ end
76
+
77
+ def test_one_arg
78
+ name = :one_arg
79
+ sig = method(name).signature
80
+ assert_equal self.class, sig.origin_class
81
+ assert_equal name.to_s, sig.name
82
+ assert_equal [:a], sig.arg_names
83
+ check_args({:a => "a"}, sig)
84
+ assert_equal "#{self.class.name}##{name}(a)", sig.to_s
85
+ end
86
+
87
+ def two_args(a, b)
88
+ end
89
+
90
+ def test_two_args
91
+ name = :two_args
92
+ sig = method(name).signature
93
+ assert_equal self.class, sig.origin_class
94
+ assert_equal name.to_s, sig.name
95
+ assert_equal [:a, :b], sig.arg_names
96
+ check_args({:a=>"a", :b=>"b"}, sig)
97
+ assert_equal "#{self.class.name}##{name}(a, b)", sig.to_s
98
+ end
99
+
100
+ def two_args_with_locals(a, b)
101
+ x = 1
102
+ y = 2
103
+ end
104
+
105
+ def test_two_args_with_locals
106
+ name = :two_args_with_locals
107
+ sig = method(name).signature
108
+ assert_equal self.class, sig.origin_class
109
+ assert_equal name.to_s, sig.name
110
+ assert_equal [:a, :b], sig.arg_names
111
+ check_args({:a=>"a", :b=>"b"}, sig)
112
+ assert_equal "#{self.class.name}##{name}(a, b)", sig.to_s
113
+ end
114
+
115
+ def three_args(a, b, c)
116
+ end
117
+
118
+ def test_three_args
119
+ name = :three_args
120
+ sig = method(name).signature
121
+ assert_equal self.class, sig.origin_class
122
+ assert_equal name.to_s, sig.name
123
+ assert_equal [:a, :b, :c], sig.arg_names
124
+ check_args({:a=>"a", :b=>"b", :c=>"c"}, sig)
125
+ assert_equal "#{self.class.name}##{name}(a, b, c)", sig.to_s
126
+ end
127
+
128
+ def block_arg(&b)
129
+ end
130
+
131
+ def test_block_arg
132
+ name = :block_arg
133
+ sig = method(name).signature
134
+ assert_equal self.class, sig.origin_class
135
+ assert_equal name.to_s, sig.name
136
+ assert_equal [:b], sig.arg_names
137
+ check_args({:b=>"&b"}, sig)
138
+ assert_equal "#{self.class.name}##{name}(&b)", sig.to_s
139
+ end
140
+
141
+ def rest_arg(*r)
142
+ end
143
+
144
+ def test_rest_arg
145
+ name = :rest_arg
146
+ sig = method(name).signature
147
+ assert_equal self.class, sig.origin_class
148
+ assert_equal name.to_s, sig.name
149
+ assert_equal [:r], sig.arg_names
150
+ check_args({:r=>"*r"}, sig)
151
+ assert_equal "#{self.class.name}##{name}(*r)", sig.to_s
152
+ end
153
+
154
+ def block_and_rest_arg(*r, &b)
155
+ end
156
+
157
+ def test_block_and_rest_arg
158
+ name = :block_and_rest_arg
159
+ sig = method(name).signature
160
+ assert_equal self.class, sig.origin_class
161
+ assert_equal name.to_s, sig.name
162
+ assert_equal [:r, :b], sig.arg_names
163
+ check_args({:r=>"*r", :b=>"&b"}, sig)
164
+ assert_equal "#{self.class.name}##{name}(*r, &b)", sig.to_s
165
+ end
166
+
167
+ def default_arg(a = 1)
168
+ end
169
+
170
+ def test_default_arg
171
+ name = :default_arg
172
+ sig = method(name).signature
173
+ assert_equal self.class, sig.origin_class
174
+ assert_equal name.to_s, sig.name
175
+ assert_equal [:a], sig.arg_names
176
+ check_args({:a=>"a=1"}, sig)
177
+ assert_equal "#{self.class.name}##{name}(a=1)", sig.to_s
178
+ end
179
+
180
+ def default_and_nondefault_arg(a, b = 42)
181
+ end
182
+
183
+ def test_default_and_nondefault_arg
184
+ name = :default_and_nondefault_arg
185
+ sig = method(name).signature
186
+ assert_equal self.class, sig.origin_class
187
+ assert_equal name.to_s, sig.name
188
+ assert_equal [:a, :b], sig.arg_names
189
+ check_args({:a=>"a", :b=>"b=42"}, sig)
190
+ assert_equal "#{self.class.name}##{name}(a, b=42)", sig.to_s
191
+ end
192
+
193
+ def default_and_rest(a = 42, *r)
194
+ end
195
+
196
+ def test_default_and_rest
197
+ name = :default_and_rest
198
+ sig = method(name).signature
199
+ assert_equal self.class, sig.origin_class
200
+ assert_equal name.to_s, sig.name
201
+ assert_equal [:a, :r], sig.arg_names
202
+ check_args({:a=>"a=42", :r=>"*r"}, sig)
203
+ assert_equal "#{self.class.name}##{name}(a=42, *r)", sig.to_s
204
+ end
205
+
206
+ def default_and_rest_and_block(a = 42, *r, &b)
207
+ end
208
+
209
+ def test_default_and_rest_and_block
210
+ name = :default_and_rest_and_block
211
+ sig = method(name).signature
212
+ assert_equal self.class, sig.origin_class
213
+ assert_equal name.to_s, sig.name
214
+ assert_equal [:a, :r, :b], sig.arg_names
215
+ check_args({:a=>"a=42", :r=>"*r", :b=>"&b"}, sig)
216
+ assert_equal "#{self.class.name}##{name}(a=42, *r, &b)", sig.to_s
217
+ end
218
+
219
+ def nondefault_and_default_and_rest_and_block(a, b = 42, *r, &block)
220
+ end
221
+
222
+ def test_nondefault_and_default_and_rest_and_block
223
+ name = :nondefault_and_default_and_rest_and_block
224
+ sig = method(name).signature
225
+ assert_equal self.class, sig.origin_class
226
+ assert_equal name.to_s, sig.name
227
+ assert_equal [:a, :b, :r, :block], sig.arg_names
228
+ check_args({:a=>"a", :b=>"b=42", :r=>"*r", :block=>"&block"}, sig)
229
+ assert_equal "#{self.class.name}##{name}(a, b=42, *r, &block)", sig.to_s
230
+ end
231
+
232
+ def nondefault_and_default_and_rest_and_block_with_locals(a, b = 42, *r, &block)
233
+ x = 1
234
+ y = 2
235
+ end
236
+
237
+ def test_nondefault_and_default_and_rest_and_block_with_locals
238
+ name = :nondefault_and_default_and_rest_and_block_with_locals
239
+ sig = method(name).signature
240
+ assert_equal self.class, sig.origin_class
241
+ assert_equal name.to_s, sig.name
242
+ assert_equal [:a, :b, :r, :block], sig.arg_names
243
+ check_args({:a=>"a", :b=>"b=42", :r=>"*r", :block=>"&block"}, sig)
244
+ assert_equal "#{self.class.name}##{name}(a, b=42, *r, &block)", sig.to_s
245
+ end
246
+
247
+ def three_default_and_rest_and_block_with_locals(a = 42, b = 43, c = 44, *r, &block)
248
+ x = 1
249
+ y = 2
250
+ end
251
+
252
+ def test_three_default_and_rest_and_block_with_locals
253
+ name = :three_default_and_rest_and_block_with_locals
254
+ sig = method(name).signature
255
+ assert_equal self.class, sig.origin_class
256
+ assert_equal name.to_s, sig.name
257
+ assert_equal [:a, :b, :c, :r, :block], sig.arg_names
258
+ check_args({:a=>"a=42", :b=>"b=43", :c=>"c=44", :r=>"*r", :block=>"&block"}, sig)
259
+ assert_equal "#{self.class.name}##{name}(a=42, b=43, c=44, *r, &block)", sig.to_s
260
+ end
261
+ end
262
+
263
+ if __FILE__ == $0 then
264
+ require 'test_helpers'
265
+ run_all_tests()
266
+ end
267
+
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-decompiler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Paul Brannan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-11 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ruby-internal
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 57
29
+ segments:
30
+ - 0
31
+ - 8
32
+ - 3
33
+ version: 0.8.3
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: |
37
+ Ruby-decompiler is a decompiler for ruby code. Use it to deconstruct
38
+ method signatures and decompile bytecode (1.9.x) or the AST (1.8.x).
39
+
40
+ email: curlypaul924@gmail.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files:
46
+ - README.rdoc
47
+ files:
48
+ - lib/decompiler/node/as_code.rb
49
+ - lib/decompiler/node/as_expression.rb
50
+ - lib/decompiler/vm/iseq/as_code.rb
51
+ - lib/decompiler/vm/iseq/as_expression.rb
52
+ - lib/decompiler/vm/bytedecoder.rb
53
+ - lib/decompiler/method/origin.rb
54
+ - lib/decompiler/method/signature.rb
55
+ - lib/decompiler/method/signature/signature.rb
56
+ - lib/decompiler/method/signature/argument.rb
57
+ - lib/decompiler/method/signature/iseq.rb
58
+ - lib/decompiler/method/signature/node.rb
59
+ - lib/decompiler/method/as_code.rb
60
+ - lib/decompiler/method/as_expression.rb
61
+ - lib/decompiler/module/as_code.rb
62
+ - lib/decompiler/proc/signature.rb
63
+ - lib/decompiler/proc/as_code.rb
64
+ - lib/decompiler/proc/as_expression.rb
65
+ - README.rdoc
66
+ - test/test_methodsig.rb
67
+ - test/test_as_code.rb
68
+ - test/test_as_expression.rb
69
+ homepage: http://github.com/cout/ruby-decompiler/
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: A decompiler for ruby (both YARV and MRI)
102
+ test_files:
103
+ - test/test_methodsig.rb
104
+ - test/test_as_code.rb
105
+ - test/test_as_expression.rb