ParseTree 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +16 -0
- data/Manifest.txt +2 -1
- data/Rakefile +18 -68
- data/bin/parse_tree_audit +28 -0
- data/lib/parse_tree.rb +124 -11
- data/lib/sexp_processor.rb +11 -1
- data/test/pt_testcase.rb +1378 -0
- data/test/something.rb +40 -2
- data/test/test_parse_tree.rb +123 -11
- data/test/test_sexp_processor.rb +9 -0
- metadata +16 -4
data/test/something.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
|
2
2
|
class Something
|
3
3
|
|
4
|
+
def self.classmethod
|
5
|
+
1 + 1
|
6
|
+
end
|
7
|
+
|
4
8
|
# basically: do we work at all?
|
5
9
|
def empty
|
6
10
|
end
|
@@ -56,13 +60,17 @@ class Something
|
|
56
60
|
def iteration1
|
57
61
|
array = [1, 2, 3]
|
58
62
|
array.each do |x|
|
59
|
-
|
63
|
+
y = x.to_s
|
64
|
+
puts(y)
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
63
68
|
def iteration2
|
64
69
|
array = [1, 2, 3]
|
65
|
-
array.each { |x|
|
70
|
+
array.each { |x|
|
71
|
+
y = x.to_s
|
72
|
+
puts(y)
|
73
|
+
}
|
66
74
|
end
|
67
75
|
|
68
76
|
def iteration3
|
@@ -185,6 +193,36 @@ class Something
|
|
185
193
|
end
|
186
194
|
end
|
187
195
|
|
196
|
+
def bbegin_no_exception
|
197
|
+
begin
|
198
|
+
5
|
199
|
+
rescue
|
200
|
+
6
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def op_asgn
|
205
|
+
a = 0
|
206
|
+
a ||= 1
|
207
|
+
a &&= 2
|
208
|
+
#a += 3 # doesn't use op_asgn
|
209
|
+
|
210
|
+
b = []
|
211
|
+
b[1] ||= 10
|
212
|
+
b[2] &&= 11
|
213
|
+
b[3] += 12
|
214
|
+
|
215
|
+
s = Struct.new :var
|
216
|
+
c = s.new nil
|
217
|
+
c.var ||= 20
|
218
|
+
c.var &&= 21
|
219
|
+
c.var += 22
|
220
|
+
|
221
|
+
c.d.e.f ||= 42
|
222
|
+
|
223
|
+
return a
|
224
|
+
end
|
225
|
+
|
188
226
|
def whiles
|
189
227
|
while false do
|
190
228
|
puts "false"
|
data/test/test_parse_tree.rb
CHANGED
@@ -28,8 +28,59 @@ class TestParseTree < Test::Unit::TestCase
|
|
28
28
|
assert_equal expected, tree
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_parse_tree_for_string
|
32
|
+
actual = @thing.parse_tree_for_string '1 + nil', '(string)', 1, false
|
33
|
+
expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]]
|
34
|
+
|
35
|
+
assert_equal expected, actual
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_parse_tree_for_string_with_newlines
|
39
|
+
actual = @thing.parse_tree_for_string "1 +\n nil", 'test.rb', 5, true
|
40
|
+
expected = [[:newline, 6, "test.rb"],
|
41
|
+
[:call, [:lit, 1], :+, [:array, [:nil]]]]
|
42
|
+
|
43
|
+
assert_equal expected, actual
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_parse_tree_for_str
|
47
|
+
actual = @thing.parse_tree_for_str '1 + nil', '(string)', 1, false
|
48
|
+
expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]]
|
49
|
+
|
50
|
+
assert_equal expected, actual
|
51
|
+
end
|
52
|
+
|
31
53
|
# TODO: need a test of interpolated strings
|
32
54
|
|
55
|
+
@@self_classmethod = [:defn, :"self.classmethod",
|
56
|
+
[:scope,
|
57
|
+
[:block,
|
58
|
+
[:args],
|
59
|
+
[:call, [:lit, 1], :+, [:array, [:lit, 1]]]]]]
|
60
|
+
|
61
|
+
@@self_bmethod_maker = [:defn,
|
62
|
+
:"self.bmethod_maker",
|
63
|
+
[:scope,
|
64
|
+
[:block,
|
65
|
+
[:args],
|
66
|
+
[:iter,
|
67
|
+
[:fcall, :define_method,
|
68
|
+
[:array, [:lit, :bmethod_added]]],
|
69
|
+
[:dasgn_curr, :x],
|
70
|
+
[:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]]]]
|
71
|
+
|
72
|
+
@@self_dmethod_maker = [:defn,
|
73
|
+
:"self.dmethod_maker",
|
74
|
+
[:scope,
|
75
|
+
[:block,
|
76
|
+
[:args],
|
77
|
+
[:fcall,
|
78
|
+
:define_method,
|
79
|
+
[:array,
|
80
|
+
[:lit, :dmethod_added],
|
81
|
+
[:call, [:self], :method,
|
82
|
+
[:array, [:lit, :bmethod_maker]]]]]]]]
|
83
|
+
|
33
84
|
@@missing = [nil]
|
34
85
|
@@empty = [:defn, :empty,
|
35
86
|
[:scope,
|
@@ -125,15 +176,19 @@ class TestParseTree < Test::Unit::TestCase
|
|
125
176
|
[:return, [:lit, 3]],
|
126
177
|
[:return, [:lit, 4]]]]]]]
|
127
178
|
@@iteration_body = [:scope,
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
179
|
+
[:block,
|
180
|
+
[:args],
|
181
|
+
[:lasgn, :array,
|
182
|
+
[:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
|
183
|
+
[:iter,
|
184
|
+
[:call,
|
185
|
+
[:lvar, :array], :each],
|
186
|
+
[:dasgn_curr, :x],
|
187
|
+
[:block,
|
188
|
+
[:dasgn_curr, :y],
|
189
|
+
[:dasgn_curr, :y, [:call, [:dvar, :x], :to_s]],
|
190
|
+
[:fcall, :puts, [:array, [:dvar, :y]]]]]]]
|
191
|
+
|
137
192
|
@@iteration1 = [:defn, :iteration1, @@iteration_body]
|
138
193
|
@@iteration2 = [:defn, :iteration2, @@iteration_body]
|
139
194
|
@@iteration3 = [:defn, :iteration3,
|
@@ -287,6 +342,38 @@ class TestParseTree < Test::Unit::TestCase
|
|
287
342
|
[:block, [:lasgn, :e2, [:gvar, :$!]], [:lit, 3]]]],
|
288
343
|
[:lit, 4]],
|
289
344
|
[:lit, 5]]]]]]
|
345
|
+
@@bbegin_no_exception = [:defn, :bbegin_no_exception,
|
346
|
+
[:scope,
|
347
|
+
[:block,
|
348
|
+
[:args],
|
349
|
+
[:begin,
|
350
|
+
[:rescue,
|
351
|
+
[:lit, 5],
|
352
|
+
[:resbody, nil, [:lit, 6]]]]]]]
|
353
|
+
@@op_asgn = [:defn, :op_asgn,
|
354
|
+
[:scope,
|
355
|
+
[:block,
|
356
|
+
[:args],
|
357
|
+
[:lasgn, :a, [:lit, 0]],
|
358
|
+
[:op_asgn_or, [:lvar, :a], [:lasgn, :a, [:lit, 1]]],
|
359
|
+
[:op_asgn_and, [:lvar, :a], [:lasgn, :a, [:lit, 2]]],
|
360
|
+
|
361
|
+
[:lasgn, :b, [:zarray]],
|
362
|
+
|
363
|
+
[:op_asgn1, [:lvar, :b], [:array, [:lit, 1]], :"||", [:lit, 10]],
|
364
|
+
[:op_asgn1, [:lvar, :b], [:array, [:lit, 2]], :"&&", [:lit, 11]],
|
365
|
+
[:op_asgn1, [:lvar, :b], [:array, [:lit, 3]], :+, [:lit, 12]],
|
366
|
+
|
367
|
+
[:lasgn, :s, [:call, [:const, :Struct], :new, [:array, [:lit, :var]]]],
|
368
|
+
[:lasgn, :c, [:call, [:lvar, :s], :new, [:array, [:nil]]]],
|
369
|
+
|
370
|
+
[:op_asgn2, [:lvar, :c], :var=, :"||", [:lit, 20]],
|
371
|
+
[:op_asgn2, [:lvar, :c], :var=, :"&&", [:lit, 21]],
|
372
|
+
[:op_asgn2, [:lvar, :c], :var=, :+, [:lit, 22]],
|
373
|
+
|
374
|
+
[:op_asgn2, [:call, [:call, [:lvar, :c], :d], :e], :f=, :"||", [:lit, 42]],
|
375
|
+
|
376
|
+
[:return, [:lvar, :a]]]]]
|
290
377
|
@@determine_args = [:defn, :determine_args,
|
291
378
|
[:scope,
|
292
379
|
[:block,
|
@@ -335,6 +422,18 @@ class TestParseTree < Test::Unit::TestCase
|
|
335
422
|
[:args],
|
336
423
|
[:while, [:false], [:fcall, :puts, [:array, [:str, "false"]]], true],
|
337
424
|
[:while, [:false], [:fcall, :puts, [:array, [:str, "true"]]], false]]]]
|
425
|
+
@@xstr = [:defn,
|
426
|
+
:xstr,
|
427
|
+
[:scope,
|
428
|
+
[:block,
|
429
|
+
[:args],
|
430
|
+
[:xstr, 'touch 5']]]]
|
431
|
+
@@dxstr = [:defn,
|
432
|
+
:dxstr,
|
433
|
+
[:scope,
|
434
|
+
[:block,
|
435
|
+
[:args],
|
436
|
+
[:dxstr, 'touch ', [:lit, 5]]]]]
|
338
437
|
|
339
438
|
@@__all = [:class, :Something, :Object]
|
340
439
|
|
@@ -342,7 +441,9 @@ class TestParseTree < Test::Unit::TestCase
|
|
342
441
|
@thing = ParseTree.new(false)
|
343
442
|
end
|
344
443
|
|
345
|
-
Something.instance_methods(false)
|
444
|
+
methods = Something.instance_methods(false)
|
445
|
+
|
446
|
+
methods.sort.each do |meth|
|
346
447
|
if class_variables.include?("@@#{meth}") then
|
347
448
|
@@__all << eval("@@#{meth}")
|
348
449
|
eval "def test_#{meth}; assert_equal @@#{meth}, @thing.parse_tree_for_method(Something, :#{meth}); end"
|
@@ -351,6 +452,18 @@ class TestParseTree < Test::Unit::TestCase
|
|
351
452
|
end
|
352
453
|
end
|
353
454
|
|
455
|
+
methods = Something.singleton_methods
|
456
|
+
|
457
|
+
# TODO: cleanup
|
458
|
+
methods.sort.each do |meth|
|
459
|
+
if class_variables.include?("@@self_#{meth}") then
|
460
|
+
@@__all << eval("@@self_#{meth}")
|
461
|
+
eval "def test_self_#{meth}; assert_equal @@self_#{meth}, @thing.parse_tree_for_method(Something, :#{meth}, true); end"
|
462
|
+
else
|
463
|
+
eval "def test_self_#{meth}; flunk \"You haven't added @@self_#{meth} yet\"; end"
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
354
467
|
def test_missing
|
355
468
|
assert_equal(@@missing,
|
356
469
|
@thing.parse_tree_for_method(Something, :missing),
|
@@ -362,6 +475,5 @@ class TestParseTree < Test::Unit::TestCase
|
|
362
475
|
@thing.parse_tree(Something),
|
363
476
|
"Must return a lot of shit")
|
364
477
|
end
|
365
|
-
|
366
478
|
end
|
367
479
|
|
data/test/test_sexp_processor.rb
CHANGED
@@ -137,6 +137,15 @@ class TestSexpProcessor < Test::Unit::TestCase
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
def test_process_unsupported_wrong
|
141
|
+
@processor = TestProcessor.new
|
142
|
+
@processor.unsupported << :strip
|
143
|
+
|
144
|
+
assert_raises(UnsupportedNodeError) do
|
145
|
+
@processor.process([:whatever])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
140
149
|
def test_unsupported_equal
|
141
150
|
@processor.strict = true
|
142
151
|
@processor.unsupported = [ :unsupported ]
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: ParseTree
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2006-
|
6
|
+
version: 1.5.0
|
7
|
+
date: 2006-09-24 00:00:00 -07:00
|
8
8
|
summary: Extract and enumerate ruby parse trees.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -13,7 +13,7 @@ email: ryand-ruby@zenspider.com
|
|
13
13
|
homepage: http://www.zenspider.com/ZSS/Products/ParseTree/
|
14
14
|
rubyforge_project: parsetree
|
15
15
|
description: ParseTree is a C extension (using RubyInline) that extracts the parse tree for an entire class or a specific method and returns it as a s-expression (aka sexp) using ruby's arrays, strings, symbols, and integers.
|
16
|
-
autorequire:
|
16
|
+
autorequire:
|
17
17
|
default_executable:
|
18
18
|
bindir: bin
|
19
19
|
has_rdoc: true
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- Manifest.txt
|
36
36
|
- README.txt
|
37
37
|
- bin/parse_tree_abc
|
38
|
+
- bin/parse_tree_audit
|
38
39
|
- bin/parse_tree_deps
|
39
40
|
- bin/parse_tree_show
|
40
41
|
- demo/printer.rb
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- lib/parse_tree.rb
|
43
44
|
- lib/sexp.rb
|
44
45
|
- lib/sexp_processor.rb
|
46
|
+
- test/pt_testcase.rb
|
45
47
|
- test/something.rb
|
46
48
|
- test/test_all.rb
|
47
49
|
- test/test_composite_sexp_processor.rb
|
@@ -57,6 +59,7 @@ extra_rdoc_files: []
|
|
57
59
|
|
58
60
|
executables:
|
59
61
|
- parse_tree_abc
|
62
|
+
- parse_tree_audit
|
60
63
|
- parse_tree_deps
|
61
64
|
- parse_tree_show
|
62
65
|
extensions: []
|
@@ -64,6 +67,15 @@ extensions: []
|
|
64
67
|
requirements: []
|
65
68
|
|
66
69
|
dependencies:
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: hoe
|
72
|
+
version_requirement:
|
73
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.0.0
|
78
|
+
version:
|
67
79
|
- !ruby/object:Gem::Dependency
|
68
80
|
name: RubyInline
|
69
81
|
version_requirement:
|