ParseTree 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
@@ -18,14 +18,24 @@ class SomethingWithInitialize
18
18
  def protected_meth; end
19
19
  end
20
20
 
21
+ $verbose_methods = {
22
+ "test_begin_rescue_twice" => true,
23
+ "test_block_stmt_after" => true,
24
+ "test_block_stmt_both" => true,
25
+ }
26
+
21
27
  class ParseTree
22
- def process(input) # makes it play with with ParseTreeTestCase (FIX?)
28
+ def process(input, verbose = nil) # TODO: remove
29
+
30
+ test_method = caller[0][/\`(.*)\'/, 1]
31
+ verbose = $verbose_methods[test_method]
32
+
23
33
  # um. kinda stupid, but cleaner
24
34
  case input
25
35
  when Array then
26
36
  ParseTree.translate(*input)
27
37
  else
28
- ParseTree.translate(input)
38
+ self.parse_tree_for_string(input, '(string)', 1, verbose).first
29
39
  end
30
40
  end
31
41
  end
@@ -77,7 +87,7 @@ class TestParseTree < ParseTreeTestCase
77
87
  def test_parse_tree_for_string_with_newlines
78
88
  @processor = ParseTree.new(true)
79
89
  actual = @processor.parse_tree_for_string "1 +\n nil", 'test.rb', 5
80
- expected = [[:newline, 6, "test.rb",
90
+ expected = [[:newline, 6, "test.rb",
81
91
  [:call, [:lit, 1], :+, [:array, [:nil]]]]]
82
92
 
83
93
  assert_equal expected, actual
@@ -171,7 +181,6 @@ class TestParseTree < ParseTreeTestCase
171
181
  :unknown_args,
172
182
  [:array, [:lit, 4], [:str, "known"]]]]]]]]
173
183
 
174
-
175
184
  @@attrasgn = [:defn,
176
185
  :attrasgn,
177
186
  [:scope,
@@ -188,7 +197,7 @@ class TestParseTree < ParseTreeTestCase
188
197
  Something.instance_methods(false).sort.each do |meth|
189
198
  if class_variables.include?("@@#{meth}") then
190
199
  @@__all << eval("@@#{meth}")
191
- eval "def test_#{meth}; assert_equal @@#{meth}, @processor.parse_tree_for_method(Something, :#{meth}); end"
200
+ eval "def test_#{meth}; assert_equal @@#{meth}, @processor.parse_tree_for_method(Something, :#{meth}, false, false); end"
192
201
  else
193
202
  eval "def test_#{meth}; flunk \"You haven't added @@#{meth} yet\"; end"
194
203
  end
@@ -207,7 +216,7 @@ class TestParseTree < ParseTreeTestCase
207
216
  def test_missing
208
217
  assert_equal(@@missing,
209
218
  @processor.parse_tree_for_method(Something, :missing),
210
- "Must return -3 for missing methods")
219
+ "Must return #{@@missing.inspect} for missing methods")
211
220
  end
212
221
 
213
222
  def test_whole_class
@@ -10,6 +10,12 @@ require 'pp'
10
10
 
11
11
  class SexpTestCase < Test::Unit::TestCase
12
12
 
13
+ unless defined? Mini then
14
+ alias :refute_nil :assert_not_nil
15
+ alias :refute_equal :assert_not_equal
16
+ alias :assert_raises :assert_raise
17
+ end
18
+
13
19
  # KEY for regex tests
14
20
  # :a == no change
15
21
  # :b == will change (but sometimes ONLY once)
@@ -19,12 +25,12 @@ class SexpTestCase < Test::Unit::TestCase
19
25
 
20
26
  def util_equals(x, y)
21
27
  result = x == y
22
- assert_not_nil result, "#{x.inspect} does not === #{y.inspect}"
28
+ refute_nil result, "#{x.inspect} does not === #{y.inspect}"
23
29
  end
24
30
 
25
31
  def util_equals3(x, y)
26
32
  result = x === y
27
- assert_not_nil result, "#{x.inspect} does not === #{y.inspect}"
33
+ refute_nil result, "#{x.inspect} does not === #{y.inspect}"
28
34
  end
29
35
 
30
36
  def setup
@@ -96,8 +102,8 @@ class TestSexp < SexpTestCase # ZenTest FULL
96
102
 
97
103
  def test_equals2_array
98
104
  # can't use assert_equals because it uses array as receiver
99
- assert_not_equal(@sexp, [1, 2, 3],
100
- "Sexp must not be equal to equivalent array")
105
+ refute_equal(@sexp, [1, 2, 3],
106
+ "Sexp must not be equal to equivalent array")
101
107
  # both directions just in case
102
108
  # HACK - this seems to be a bug in ruby as far as I'm concerned
103
109
  # assert_not_equal([1, 2, 3], @sexp,
@@ -106,24 +112,13 @@ class TestSexp < SexpTestCase # ZenTest FULL
106
112
 
107
113
  def test_equals2_not_body
108
114
  sexp2 = s(1, 2, 5)
109
- assert_not_equal(@sexp, sexp2)
115
+ refute_equal(@sexp, sexp2)
110
116
  end
111
117
 
112
118
  def test_equals2_sexp
113
119
  sexp2 = s(1, 2, 3)
114
- if @sexp.class == Sexp then
115
- # sexp3 = t(1, 2, 3, Type.str)
116
- # case @sexp
117
- # when TypedSexp
118
- # assert_equal(@sexp, sexp3)
119
- # assert_not_equal(@sexp, sexp2)
120
- # when Sexp
121
- assert_equal(@sexp, sexp2)
122
- # assert_not_equal(@sexp, sexp3)
123
- else
124
- assert_not_equal(@sexp, sexp2)
125
- # else
126
- # flunk "unknown type"
120
+ unless @sexp.class == Sexp then
121
+ refute_equal(@sexp, sexp2)
127
122
  end
128
123
  end
129
124
 
@@ -169,8 +164,8 @@ class TestSexp < SexpTestCase # ZenTest FULL
169
164
  # end
170
165
 
171
166
  def test_equalstilde_fancy
172
- assert_nil s(:b) =~ s(:a, s(:b), :c)
173
- assert_not_nil s(:a, s(:b), :c) =~ s(:b)
167
+ assert_nil s(:b) =~ s(:a, s(:b), :c)
168
+ refute_nil s(:a, s(:b), :c) =~ s(:b)
174
169
  end
175
170
 
176
171
  def test_equalstilde_plain
@@ -256,7 +251,7 @@ class TestSexp < SexpTestCase # ZenTest FULL
256
251
  assert_equal(2, @sexp.shift)
257
252
  assert_equal(3, @sexp.shift)
258
253
 
259
- assert_raise(RuntimeError) do
254
+ assert_raises(RuntimeError) do
260
255
  @sexp.shift
261
256
  end
262
257
  end
@@ -123,7 +123,7 @@ class TestSexpProcessor < Test::Unit::TestCase
123
123
  @processor = TestProcessor.new
124
124
  @processor.warn_on_default = false
125
125
 
126
- assert_raises(SexpTypeError) do
126
+ assert_raises SexpTypeError do
127
127
  @processor.process([:broken, 1, 2, 3])
128
128
  end
129
129
  end
@@ -132,7 +132,7 @@ class TestSexpProcessor < Test::Unit::TestCase
132
132
  @processor = TestProcessor.new
133
133
  @processor.unsupported << :strip
134
134
 
135
- assert_raises(UnsupportedNodeError) do
135
+ assert_raises UnsupportedNodeError do
136
136
  @processor.process([:whatever])
137
137
  end
138
138
  end
@@ -140,14 +140,14 @@ class TestSexpProcessor < Test::Unit::TestCase
140
140
  def test_unsupported_equal
141
141
  @processor.strict = true
142
142
  @processor.unsupported = [ :unsupported ]
143
- assert_raises(UnsupportedNodeError) do
143
+ assert_raises UnsupportedNodeError do
144
144
  @processor.process([:unsupported, 42])
145
145
  end
146
146
  end
147
147
 
148
148
  def test_strict
149
149
  @processor.strict = true
150
- assert_raise(UnknownNodeError) do
150
+ assert_raises UnknownNodeError do
151
151
  @processor.process([:blah, 1, 2, 3])
152
152
  end
153
153
  end
@@ -156,13 +156,11 @@ class TestSexpProcessor < Test::Unit::TestCase
156
156
  def test_require_empty_false
157
157
  @processor.require_empty = false
158
158
 
159
- assert_nothing_raised do
160
- @processor.process([:nonempty, 1, 2, 3])
161
- end
159
+ @processor.process([:nonempty, 1, 2, 3])
162
160
  end
163
161
 
164
162
  def test_require_empty_true
165
- assert_raise(NotEmptyError) do
163
+ assert_raises NotEmptyError do
166
164
  @processor.process([:nonempty, 1, 2, 3])
167
165
  end
168
166
  end
@@ -241,13 +239,11 @@ class TestSexpProcessor < Test::Unit::TestCase
241
239
  end
242
240
 
243
241
  def test_assert_type_hit
244
- assert_nothing_raised do
245
- @processor.assert_type([:blah, 1, 2, 3], :blah)
246
- end
242
+ @processor.assert_type([:blah, 1, 2, 3], :blah)
247
243
  end
248
244
 
249
245
  def test_assert_type_miss
250
- assert_raise(SexpTypeError) do
246
+ assert_raises SexpTypeError do
251
247
  @processor.assert_type([:thingy, 1, 2, 3], :blah)
252
248
  end
253
249
  end
@@ -274,7 +270,7 @@ class TestSexpProcessor < Test::Unit::TestCase
274
270
 
275
271
  def test_expected
276
272
  assert_equal Sexp, @processor.expected
277
- assert_raises(SexpTypeError) do
273
+ assert_raises SexpTypeError do
278
274
  @processor.process([:expected]) # should raise
279
275
  end
280
276
 
@@ -284,7 +280,7 @@ class TestSexpProcessor < Test::Unit::TestCase
284
280
  assert_equal Hash, @processor.expected
285
281
  assert !(Hash === s()), "Hash === s() should not be true"
286
282
 
287
- assert_raises(SexpTypeError) do
283
+ assert_raises SexpTypeError do
288
284
  @processor.process(s(:string, "string")) # should raise
289
285
  end
290
286
 
@@ -31,17 +31,6 @@ class TestUnifiedRuby < Test::Unit::TestCase
31
31
  assert_equal @expect, @sp.process(@insert)
32
32
  end
33
33
 
34
- def test_argscat
35
- @insert = s(:argscat,
36
- s(:array, s(:lvar, :container), s(:lvar, :point)),
37
- s(:lvar, :args))
38
- @expect = s(:argscat,
39
- s(:arglist, s(:lvar, :container), s(:lvar, :point)),
40
- s(:lvar, :args))
41
-
42
- doit
43
- end
44
-
45
34
  def test_call_args
46
35
  @insert = s(:call, s(:lit, 42), :y, s(:array, s(:lit, 24)))
47
36
  @expect = s(:call, s(:lit, 42), :y, s(:arglist, s(:lit, 24)))
@@ -75,6 +64,15 @@ class TestUnifiedRuby < Test::Unit::TestCase
75
64
  doit
76
65
  end
77
66
 
67
+ # [:proc, [:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]]]
68
+
69
+ # proc { |x,y| x + y }
70
+ # =
71
+ # s(:iter,
72
+ # s(:fcall, :proc),
73
+ # s(:masgn, s(:array, s(:dasgn_curr, :x), s(:dasgn_curr, :y))),
74
+ # s(:call, s(:dvar, :x), :+, s(:array, s(:dvar, :y))))
75
+
78
76
  def test_rewrite_bmethod_noargs
79
77
  @insert = s(:bmethod,
80
78
  nil,
@@ -179,20 +177,6 @@ class TestUnifiedRuby < Test::Unit::TestCase
179
177
  doit
180
178
  end
181
179
 
182
- def test_rewrite_fbody
183
- @insert = s(:fbody,
184
- s(:scope,
185
- s(:block,
186
- s(:args, :x),
187
- s(:call, s(:lvar, :x), :+, s(:array, s(:lit, 1))))))
188
- @expect = s(:scope,
189
- s(:block,
190
- s(:args, :x),
191
- s(:call, s(:lvar, :x), :+, s(:arglist, s(:lit, 1)))))
192
-
193
- doit
194
- end
195
-
196
180
  def test_rewrite_fcall
197
181
  @insert = s(:fcall, :puts, s(:array, s(:lit, :blah)))
198
182
  @expect = s(:call, nil, :puts, s(:arglist, s(:lit, :blah)))
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ParseTree
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-22 00:00:00 -08:00
12
+ date: 2008-06-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,10 +28,11 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 1.4.0
31
+ version: 1.5.3
32
32
  version:
33
- 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. As an example: def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end becomes: [:defn, :conditional1, [:scope, [:block, [:args, :arg1], [:if, [:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]], [:return, [:lit, 1]], nil], [:return, [:lit, 0]]]]] * Uses RubyInline, so it just drops in. * Includes SexpProcessor and CompositeSexpProcessor. * Allows you to write very clean filters. * Includes UnifiedRuby, allowing you to automatically rewrite ruby quirks. * ParseTree#parse_tree_for_string lets you parse arbitrary strings of ruby. * Includes parse_tree_show, which lets you quickly snoop code. * echo \"1+1\" | parse_tree_show -f for quick snippet output. * Includes parse_tree_abc, which lets you get abc metrics on code. * abc metrics = numbers of assignments, branches, and calls. * whitespace independent metric for method complexity. * Includes parse_tree_deps, which shows you basic class level dependencies. * Does not work on the core classes, as they are not ruby (yet)."
34
- email: ryand-ruby@zenspider.com
33
+ 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. As an example: def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end becomes: [:defn, :conditional1, [:scope, [:block, [:args, :arg1], [:if, [:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]], [:return, [:lit, 1]], nil], [:return, [:lit, 0]]]]]"
34
+ email:
35
+ - ryand-ruby@zenspider.com
35
36
  executables:
36
37
  - parse_tree_abc
37
38
  - parse_tree_audit
@@ -69,7 +70,7 @@ files:
69
70
  - test/test_unified_ruby.rb
70
71
  - validate.sh
71
72
  has_rdoc: true
72
- homepage: http://www.zenspider.com/ZSS/Products/ParseTree/
73
+ homepage: http://rubyforge.org/projects/parsetree/
73
74
  post_install_message:
74
75
  rdoc_options:
75
76
  - --main
@@ -92,9 +93,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  requirements: []
93
94
 
94
95
  rubyforge_project: parsetree
95
- rubygems_version: 1.0.1
96
+ rubygems_version: 1.1.1
96
97
  signing_key:
97
98
  specification_version: 2
98
- summary: 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.
99
+ summary: 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
99
100
  test_files:
100
101
  - test/test_all.rb