Skip to content
Browse files

Added .autotest to help with test mappings.

   Added test case submitted by Matthew Denner, already passing tho.

[git-p4: depot-paths = "//src/heckle/dev/": change = 3779]
  • Loading branch information...
1 parent 2c99d2d commit d177d5fa643f859c50006df32ba3adcccd0f8d47 @zenspider zenspider committed Jan 21, 2008
Showing with 51 additions and 2 deletions.
  1. +5 −0 .autotest
  2. +6 −2 test/fixtures/heckled.rb
  3. +40 −0 test/test_heckle.rb
View
5 .autotest
@@ -0,0 +1,5 @@
+# -*- ruby -*-
+
+Autotest.add_hook :initialize do |at|
+ at.extra_class_map["TestHeckleIter"] = "test/test_heckle.rb"
+end
View
8 test/fixtures/heckled.rb
@@ -143,11 +143,15 @@ def uses_ranges
def uses_nothing
end
-
+
+ def uses_iter
+ x = [ 1, 2, 3 ]
+ x.each { |y| y }
+ end
+
def self.is_a_klass_method?
true
end
-
private
def some_func; end
View
40 test/test_heckle.rb
@@ -786,3 +786,43 @@ def test_masgn
end
+class TestHeckleIter < HeckleTestCase
+ def setup
+ @nodes = [ :call, :lasgn ]
+ super
+ end
+
+ def test_iter
+ expected = s(:defn, :uses_iter,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :x, s(:nil)),
+ s(:iter,
+ s(:call, s(:lvar, :x), :each, s(:arglist)),
+ s(:dasgn_curr, :y),
+ s(:dvar, :y)))))
+
+ # This call causes the replacement of [:lasgn, :x...] above to
+ # become [:lasgn, :nil]. We then reset the tree to ensure that
+ # the original method is maintained. We are really trying to test
+ # the reset_tree method here, not the actual changes.
+
+ @heckler.process(@heckler.current_tree)
+ assert_equal(expected, @heckler.current_tree)
+
+ @heckler.reset_tree
+ expected = s(:defn, :uses_iter,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :x, s(:array, s(:lit, 1), s(:lit, 2), s(:lit, 3))),
+ s(:iter,
+ s(:call, s(:lvar, :x), :each, s(:arglist)),
+ s(:dasgn_curr, :y),
+ s(:dvar, :y)))))
+
+ @heckler.process(@heckler.current_tree)
+ assert_equal(expected, @heckler.current_tree)
+ end
+end

0 comments on commit d177d5f

Please sign in to comment.
Something went wrong with that request. Please try again.