Skip to content

Commit

Permalink
Heckle iasgn.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/heckle/dev/": change = 3178]
  • Loading branch information
drbrain committed May 18, 2007
1 parent 4882680 commit c3ee53e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -3,6 +3,7 @@
* N major enhancements:
* :call nodes are now heckled.
* :lasgn nodes are now heckled.
* :iasgn nodes are now heckled.
* N minor enhancements:
* Added focus mode to feel the Eye of Sauron.

Expand Down
20 changes: 20 additions & 0 deletions lib/heckle.rb
Expand Up @@ -260,6 +260,26 @@ def process_defn(exp)
reset_node_count
end

def process_iasgn(exp)
mutate_node [:iasgn, exp.shift, process(exp.shift)]
end

##
# Replaces the value of the iasgn with nil if its some value, and 42 if its
# nil.

def mutate_iasgn(node)
node.shift
var = node.shift
val = node.last

if val.first == :nil then
[:iasgn, var, [:lit, 42]]
else
[:iasgn, var, [:nil]]
end
end

def process_lasgn(exp)
mutate_node [:lasgn, exp.shift, process(exp.shift)]
end
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/heckled.rb
Expand Up @@ -9,6 +9,11 @@ def uses_call
some_func + some_other_func
end

def uses_iasgn
@ivar = 5
@ivar = nil
end

def uses_lasgn
lvar = 5
lvar = nil
Expand Down
35 changes: 35 additions & 0 deletions test/test_heckle.rb
Expand Up @@ -461,6 +461,41 @@ def test_heckle_class_methods
end
end

class TestHeckleIasgn < HeckleTestCase

def setup
@nodes = [:iasgn]
super
end

def test_iasgn_val
expected = [:defn, :uses_iasgn,
[:scope,
[:block,
[:args],
[:iasgn, :@ivar, [:nil]],
[:iasgn, :@ivar, [:nil]]]]]

@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end

def test_iasgn_nil
expected = [:defn, :uses_iasgn,
[:scope,
[:block,
[:args],
[:iasgn, :@ivar, [:lit, 5]],
[:iasgn, :@ivar, [:lit, 42]]]]]

@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end

end

class TestHeckleLasgn < HeckleTestCase

def setup
Expand Down

0 comments on commit c3ee53e

Please sign in to comment.