Browse files

unified most everything. call nilling seems brokey. checking in for eric

[git-p4: depot-paths = "//src/heckle/dev/": change = 3478]
  • Loading branch information...
1 parent bb34a2f commit c8eb983598d27ab9af007e7fe28a6f7c8a59bfc8 @zenspider zenspider committed Aug 8, 2007
Showing with 339 additions and 333 deletions.
  1. +1 −1 Rakefile
  2. +38 −35 lib/heckle.rb
  3. +300 −297 test/test_heckle.rb
View
2 Rakefile
@@ -14,7 +14,7 @@ Hoe.new('heckle', Heckle::VERSION) do |p|
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
- p.extra_deps << ['ruby2ruby', '>= 1.1.7']
+ p.extra_deps << ['ruby2ruby', '>= 1.1.6']
p.extra_deps << ['ZenTest', '>= 3.5.2']
end
View
73 lib/heckle.rb
@@ -1,5 +1,6 @@
require 'rubygems'
require 'parse_tree'
+require 'unified_ruby'
require 'ruby2ruby'
require 'timeout'
require 'tempfile'
@@ -15,6 +16,8 @@ def to_class
class Heckle < SexpProcessor
+ include UnifiedRuby
+
##
# The version of Heckle you are using.
@@ -110,7 +113,7 @@ def initialize(klass_name = nil, method_name = nil,
self.strict = false
self.auto_shift_type = true
- self.expected = Array
+ self.expected = Sexp
@mutatees = Hash.new
@mutation_count = Hash.new
@@ -220,8 +223,7 @@ def process_call(exp)
meth = exp.shift
args = process(exp.shift)
- out = [:call, recv, meth]
- out << args if args
+ out = s(:call, recv, meth, args)
stack = caller.map { |s| s[/process_\w+/] }.compact
@@ -238,12 +240,12 @@ def process_call(exp)
# Replaces the call node with nil.
def mutate_call(node)
- [:nil]
+ s(:nil)
end
def process_defn(exp)
self.method = exp.shift
- result = [:defn, method]
+ result = s(:defn, method)
result << process(exp.shift) until exp.empty?
heckle(result) if method == method_name
@@ -254,12 +256,12 @@ def process_defn(exp)
end
def process_defs(exp)
- defs_klass = exp.shift.first
- defs_method = exp.shift
+ recv = process exp.shift
+ meth = exp.shift
- self.method = "#{defs_klass}.#{defs_method}".intern
-
- result = [:defs, [klass], defs_method]
+ self.method = "#{recv}.#{meth}".intern
+
+ result = s(:defs, recv, meth)
result << process(exp.shift) until exp.empty?
heckle(result) if method == method_name
@@ -274,28 +276,28 @@ def process_defs(exp)
# So process_call works correctly
def process_iter(exp)
- [:iter, process(exp.shift), process(exp.shift), process(exp.shift)]
+ s(:iter, process(exp.shift), process(exp.shift), process(exp.shift))
end
def process_asgn(type, exp)
var = exp.shift
if exp.empty? then
- mutate_node [type, var]
+ mutate_node s(type, var)
else
- mutate_node [type, var, process(exp.shift)]
+ mutate_node s(type, var, process(exp.shift))
end
end
def mutate_asgn(node)
type = node.shift
var = node.shift
if node.empty? then
- [:lasgn, :_heckle_dummy]
+ s(:lasgn, :_heckle_dummy)
else
if node.last.first == :nil then
- [type, var, [:lit, 42]]
+ s(type, var, s(:lit, 42))
else
- [type, var, [:nil]]
+ s(type, var, s(:nil))
end
end
end
@@ -361,7 +363,7 @@ def process_lasgn(exp)
alias mutate_lasgn mutate_asgn
def process_lit(exp)
- mutate_node [:lit, exp.shift]
+ mutate_node s(:lit, exp.shift)
end
##
@@ -370,82 +372,82 @@ def process_lit(exp)
def mutate_lit(exp)
case exp[1]
when Fixnum, Float, Bignum
- [:lit, exp[1] + rand_number]
+ s(:lit, exp[1] + rand_number)
when Symbol
- [:lit, rand_symbol]
+ s(:lit, rand_symbol)
when Regexp
- [:lit, Regexp.new(Regexp.escape(rand_string.gsub(/\//, '\\/')))]
+ s(:lit, Regexp.new(Regexp.escape(rand_string.gsub(/\//, '\\/'))))
when Range
- [:lit, rand_range]
+ s(:lit, rand_range)
end
end
def process_str(exp)
- mutate_node [:str, exp.shift]
+ mutate_node s(:str, exp.shift)
end
##
# Replaces the value of the :str node with a random value.
def mutate_str(node)
- [:str, rand_string]
+ s(:str, rand_string)
end
def process_if(exp)
- mutate_node [:if, process(exp.shift), process(exp.shift), process(exp.shift)]
+ mutate_node s(:if, process(exp.shift), process(exp.shift), process(exp.shift))
end
##
# Swaps the then and else parts of the :if node.
def mutate_if(node)
- [:if, node[1], node[3], node[2]]
+ s(:if, node[1], node[3], node[2])
end
def process_true(exp)
- mutate_node [:true]
+ mutate_node s(:true)
end
##
# Swaps for a :false node.
def mutate_true(node)
- [:false]
+ s(:false)
end
def process_false(exp)
- mutate_node [:false]
+ mutate_node s(:false)
end
##
# Swaps for a :true node.
def mutate_false(node)
- [:true]
+ s(:true)
end
def process_while(exp)
cond, body, head_controlled = grab_conditional_loop_parts(exp)
- mutate_node [:while, cond, body, head_controlled]
+ mutate_node s(:while, cond, body, head_controlled)
end
##
# Swaps for a :until node.
def mutate_while(node)
- [:until, node[1], node[2], node[3]]
+ s(:until, node[1], node[2], node[3])
end
def process_until(exp)
cond, body, head_controlled = grab_conditional_loop_parts(exp)
- mutate_node [:until, cond, body, head_controlled]
+ mutate_node s(:until, cond, body, head_controlled)
end
##
# Swaps for a :while node.
def mutate_until(node)
- [:while, node[1], node[2], node[3]]
+ s(:while, node[1], node[2], node[3])
end
def mutate_node(node)
@@ -468,7 +470,7 @@ def walk_and_push(node)
return if node.is_a? String
node.each { |child| walk_and_push(child) }
if @mutatable_nodes.include? node.first
- @mutatees[node.first.to_sym].push(node)
+ @mutatees[node.first].push(node)
mutation_count[node] = 0
end
end
@@ -478,7 +480,7 @@ def grab_mutatees
end
def current_tree
- ParseTree.translate(klass_name.to_class, method_name)
+ rewrite Sexp.from_array(ParseTree.translate(klass_name.to_class, method_name))
end
def reset
@@ -541,6 +543,7 @@ def should_heckle?(exp)
return false unless method == method_name
mutation_count[exp] = 0 if mutation_count[exp].nil?
return false if node_count[exp] <= mutation_count[exp]
+
( mutatees[exp.first.to_sym] || [] ).include?(exp) && !already_mutated?
end
View
597 test/test_heckle.rb
@@ -40,7 +40,7 @@ def teardown
class LiteralHeckleTestCase < HeckleTestCase
def setup
- @nodes = [:lit, :str]
+ @nodes = s(:lit, :str)
super
end
@@ -72,73 +72,77 @@ def test_should_iterate_mutations
class TestHeckle < HeckleTestCase
def test_should_set_original_tree
- expected = [:defn, :uses_many_things,
- [:fbody,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :i, [:lit, 1]],
- [:while,
- [:call, [:lvar, :i], :<, [:array, [:lit, 10]]],
- [:block,
- [:lasgn, :i, [:call, [:lvar, :i], :+, [:array, [:lit, 1]]]],
- [:until, [:vcall, :some_func],
- [:vcall, :some_other_func], true],
- [:if,
- [:call, [:str, "hi there"], :==,
- [:array, [:str, "changeling"]]],
- [:return, [:true]],
- nil],
- [:return, [:false]]],
- true],
- [:lvar, :i]]]]]
+ expected = s(:defn, :uses_many_things,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :i, s(:lit, 1)),
+ s(:while,
+ s(:call, s(:lvar, :i), :<, s(:array, s(:lit, 10))),
+ s(:block,
+ s(:lasgn, :i, s(:call, s(:lvar, :i), :+, s(:array, s(:lit, 1)))),
+ s(:until, s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)), true),
+ s(:if,
+ s(:call, s(:str, "hi there"), :==,
+ s(:array, s(:str, "changeling"))),
+ s(:return, s(:true)),
+ nil),
+ s(:return, s(:false))),
+ true),
+ s(:lvar, :i))))
assert_equal expected, @heckler.original_tree
end
def test_should_grab_mutatees_from_method
# expected is from tree of uses_while
expected = {
- :call => [[:call, [:lvar, :i], :<, [:array, [:lit, 10]]],
- [:call, [:lvar, :i], :+, [:array, [:lit, 1]]],
- [:call, [:str, "hi there"], :==,
- [:array, [:str, "changeling"]]]],
- :cvasgn => [], # no cvasgns here
- :dasgn => [], # no dasgns here
+ :call => [s(:call, s(:lvar, :i), :<, s(:array, s(:lit, 10))),
+ s(:call, s(:lvar, :i), :+, s(:array, s(:lit, 1))),
+ s(:call, nil, :some_func, s(:arglist)), # FIX: why added?
+ s(:call, nil, :some_other_func, s(:arglist)), # FIX: why added?
+ s(:call, s(:str, "hi there"), :==,
+ s(:array, s(:str, "changeling")))],
+ :cvasgn => [], # no cvasgns here
+ :dasgn => [], # no dasgns here
:dasgn_curr => [], # no dasgn_currs here
- :iasgn => [], # no iasgns here
- :gasgn => [], # no gasgns here
- :lasgn => [[:lasgn, :i, [:lit, 1]],
- [:lasgn, :i, [:call, [:lvar, :i], :+, [:array, [:lit, 1]]]]],
- :lit => [[:lit, 1], [:lit, 10], [:lit, 1]],
- :if => [[:if,
- [:call, [:str, "hi there"], :==, [:array, [:str, "changeling"]]],
- [:return, [:true]],
- nil]],
- :str => [[:str, "hi there"], [:str, "changeling"]],
- :true => [[:true]],
- :false => [[:false]],
- :while => [[:while,
- [:call, [:lvar, :i], :<, [:array, [:lit, 10]]],
- [:block,
- [:lasgn, :i, [:call, [:lvar, :i], :+, [:array, [:lit, 1]]]],
- [:until, [:vcall, :some_func],
- [:vcall, :some_other_func], true],
- [:if,
- [:call, [:str, "hi there"], :==,
- [:array, [:str, "changeling"]]],
- [:return, [:true]],
- nil],
- [:return, [:false]]],
- true]],
- :until => [[:until, [:vcall, :some_func], [:vcall, :some_other_func], true]]
+ :iasgn => [], # no iasgns here
+ :gasgn => [], # no gasgns here
+ :lasgn => [s(:lasgn, :i, s(:lit, 1)),
+ s(:lasgn, :i, s(:call, s(:lvar, :i), :+, s(:array, s(:lit, 1))))],
+ :lit => [s(:lit, 1), s(:lit, 10), s(:lit, 1)],
+ :if => [s(:if,
+ s(:call, s(:str, "hi there"), :==, s(:array, s(:str, "changeling"))),
+ s(:return, s(:true)),
+ nil)],
+ :str => [s(:str, "hi there"), s(:str, "changeling")],
+ :true => [s(:true)],
+ :false => [s(:false)],
+ :while => [s(:while,
+ s(:call, s(:lvar, :i), :<, s(:array, s(:lit, 10))),
+ s(:block,
+ s(:lasgn, :i, s(:call, s(:lvar, :i), :+, s(:array, s(:lit, 1)))),
+ s(:until, s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)), true),
+ s(:if,
+ s(:call, s(:str, "hi there"), :==,
+ s(:array, s(:str, "changeling"))),
+ s(:return, s(:true)),
+ nil),
+ s(:return, s(:false))),
+ true)],
+ :until => [s(:until,
+ s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)),
+ true)],
}
assert_equal expected, @heckler.mutatees
end
def test_should_count_mutatees_left
- assert_equal 15, @heckler.mutations_left
+ assert_equal 17, @heckler.mutations_left # FIX WHY?!?
end
def test_reset
@@ -151,7 +155,7 @@ def test_reset
assert_not_equal original_mutatees, @heckler.mutatees
@heckler.reset
- assert_equal original_tree[2], @heckler.current_tree[2][1]
+ assert_equal original_tree[2], @heckler.current_tree[2]
assert_equal original_mutatees, @heckler.mutatees
end
@@ -203,124 +207,124 @@ def toggle(value, toggle)
end
def util_expected(n)
- [:defn, :uses_numeric_literals,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :i, [:lit, toggle(1, 1 == n)]],
- [:lasgn, :i, [:call, [:lvar, :i], :+,
- [:array, [:lit, toggle(2147483648, 2 == n)]]]],
- [:lasgn, :i, [:call, [:lvar, :i], :-, [:array, [:lit, toggle(3.5, 3 == n)]]]]]]]
+ s(:defn, :uses_numeric_literals,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :i, s(:lit, toggle(1, 1 == n))),
+ s(:lasgn, :i, s(:call, s(:lvar, :i), :+,
+ s(:array, s(:lit, toggle(2147483648, 2 == n))))),
+ s(:lasgn, :i, s(:call, s(:lvar, :i), :-, s(:array, s(:lit, toggle(3.5, 3 == n))))))))
end
end
class TestHeckleSymbols < LiteralHeckleTestCase
TOGGLE_VALUE = :"l33t h4x0r"
def util_expected(n = nil)
- [:defn, :uses_symbols,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :i, [:lit, toggle(:blah, n == 1)]],
- [:lasgn, :i, [:lit, toggle(:blah, n == 2)]],
- [:lasgn, :i, [:lit, toggle(:and_blah, n == 3)]]]]]
+ s(:defn, :uses_symbols,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :i, s(:lit, toggle(:blah, n == 1))),
+ s(:lasgn, :i, s(:lit, toggle(:blah, n == 2))),
+ s(:lasgn, :i, s(:lit, toggle(:and_blah, n == 3))))))
end
end
class TestHeckleRegexes < LiteralHeckleTestCase
TOGGLE_VALUE = /l33t\ h4x0r/
def util_expected(n = nil)
- [:defn, :uses_regexes,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :i, [:lit, toggle(/a.*/, n == 1)]],
- [:lasgn, :i, [:lit, toggle(/c{2,4}+/, n == 2)]],
- [:lasgn, :i, [:lit, toggle(/123/, n == 3)]]]]]
+ s(:defn, :uses_regexes,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :i, s(:lit, toggle(/a.*/, n == 1))),
+ s(:lasgn, :i, s(:lit, toggle(/c{2,4}+/, n == 2))),
+ s(:lasgn, :i, s(:lit, toggle(/123/, n == 3))))))
end
end
class TestHeckleRanges < LiteralHeckleTestCase
TOGGLE_VALUE = 5..10
def util_expected(n = nil)
- [:defn, :uses_ranges,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :i, [:lit, toggle(6..100, n == 1)]],
- [:lasgn, :i, [:lit, toggle(-1..9, n == 2)]],
- [:lasgn, :i, [:lit, toggle(1..4, n == 3)]]]]]
+ s(:defn, :uses_ranges,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :i, s(:lit, toggle(6..100, n == 1))),
+ s(:lasgn, :i, s(:lit, toggle(-1..9, n == 2))),
+ s(:lasgn, :i, s(:lit, toggle(1..4, n == 3))))))
end
end
class TestHeckleSameLiteral < LiteralHeckleTestCase
TOGGLE_VALUE = 6
def util_expected(n = nil)
- [:defn, :uses_same_literal,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :i, [:lit, toggle(1, n == 1)]],
- [:lasgn, :i, [:lit, toggle(1, n == 2)]],
- [:lasgn, :i, [:lit, toggle(1, n == 3)]]]]]
+ s(:defn, :uses_same_literal,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :i, s(:lit, toggle(1, n == 1))),
+ s(:lasgn, :i, s(:lit, toggle(1, n == 2))),
+ s(:lasgn, :i, s(:lit, toggle(1, n == 3))))))
end
end
class TestHeckleStrings < LiteralHeckleTestCase
TOGGLE_VALUE = "l33t h4x0r"
def util_expected(n = nil)
- [:defn, :uses_strings,
- [:scope,
- [:block,
- [:args],
- [:call, [:ivar, :@names], :<<, [:array, [:str, toggle("Hello, Robert", n == 1)]]],
- [:call, [:ivar, :@names], :<<, [:array, [:str, toggle("Hello, Jeff", n == 2)]]],
- [:call, [:ivar, :@names], :<<, [:array, [:str, toggle("Hi, Frank", n == 3)]]]]]]
+ s(:defn, :uses_strings,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:call, s(:ivar, :@names), :<<, s(:array, s(:str, toggle("Hello, Robert", n == 1)))),
+ s(:call, s(:ivar, :@names), :<<, s(:array, s(:str, toggle("Hello, Jeff", n == 2)))),
+ s(:call, s(:ivar, :@names), :<<, s(:array, s(:str, toggle("Hi, Frank", n == 3)))))))
end
end
class TestHeckleIf < HeckleTestCase
def test_default_structure
- expected = [:defn, :uses_if,
- [:scope,
- [:block,
- [:args],
- [:if,
- [:vcall, :some_func],
- [:if, [:vcall, :some_other_func], [:return], nil],
- nil]]]]
+ expected = s(:defn, :uses_if,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:if,
+ s(:call, nil, :some_func, s(:arglist)),
+ s(:if, s(:call, nil, :some_other_func, s(:arglist)), s(:return), nil),
+ nil))))
assert_equal expected, @heckler.current_tree
end
def test_should_flip_if_to_unless
- expected = [:defn, :uses_if,
- [:scope,
- [:block,
- [:args],
- [:if,
- [:vcall, :some_func],
- [:if, [:vcall, :some_other_func], nil, [:return]],
- nil]]]]
+ expected = s(:defn, :uses_if,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:if,
+ s(:call, nil, :some_func, s(:arglist)),
+ s(:if, s(:call, nil, :some_other_func, s(:arglist)), nil, s(:return)),
+ nil))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
@heckler.reset_tree
- expected = [:defn, :uses_if,
- [:scope,
- [:block,
- [:args],
- [:if,
- [:vcall, :some_func],
- nil,
- [:if, [:vcall, :some_other_func], [:return], nil]]]]]
+ expected = s(:defn, :uses_if,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:if,
+ s(:call, nil, :some_func, s(:arglist)),
+ nil,
+ s(:if, s(:call, nil, :some_other_func, s(:arglist)), s(:return), nil)))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
@@ -330,7 +334,7 @@ def test_should_flip_if_to_unless
class TestHeckleBoolean < HeckleTestCase
def setup
- @nodes = [:true, :false]
+ @nodes = s(:true, :false)
super
end
@@ -339,12 +343,12 @@ def toggle(value, toggle)
end
def util_expected(n = nil)
- [:defn, :uses_boolean,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :a, [toggle(true, n == 1)]],
- [:lasgn, :b, [toggle(false, n == 2)]]]]]
+ s(:defn, :uses_boolean,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :a, s(toggle(true, n == 1))),
+ s(:lasgn, :b, s(toggle(false, n == 2))))))
end
def test_default_structure
@@ -364,45 +368,45 @@ def test_should_flip_true_to_false_and_false_to_true
class TestHeckleWhile < HeckleTestCase
def test_default_structure
- expected = [:defn, :uses_while,
- [:scope,
- [:block,
- [:args],
- [:while, [:vcall, :some_func],
- [:vcall, :some_other_func], true]]]]
+ expected = s(:defn, :uses_while,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:while, s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)), true))))
assert_equal expected, @heckler.current_tree
end
def test_flips_while_to_until
- expected = [:defn, :uses_while,
- [:scope,
- [:block,
- [:args],
- [:until, [:vcall, :some_func],
- [:vcall, :some_other_func], true]]]]
+ expected = s(:defn, :uses_while,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:until, s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)), true))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
end
class TestHeckleUntil < HeckleTestCase
def test_default_structure
- expected = [:defn, :uses_until,
- [:scope,
- [:block,
- [:args],
- [:until, [:vcall, :some_func],
- [:vcall, :some_other_func], true]]]]
+ expected = s(:defn, :uses_until,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:until, s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)), true))))
assert_equal expected, @heckler.current_tree
end
def test_flips_until_to_while
- expected = [:defn, :uses_until,
- [:scope,
- [:block,
- [:args],
- [:while, [:vcall, :some_func],
- [:vcall, :some_other_func], true]]]]
+ expected = s(:defn, :uses_until,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:while, s(:call, nil, :some_func, s(:arglist)),
+ s(:call, nil, :some_other_func, s(:arglist)), true))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
@@ -411,26 +415,25 @@ def test_flips_until_to_while
class TestHeckleCall < HeckleTestCase
def test_call_deleted
- expected = [:defn, :uses_call,
- [:scope,
- [:block,
- [:args],
- [:nil]]]]
+ expected = s(:defn, :uses_call,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:nil))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
def test_default_structure
- expected = [:defn, :uses_call,
- [:fbody,
- [:scope,
- [:block,
- [:args],
- [:call,
- [:vcall, :some_func],
- :+,
- [:array, [:vcall, :some_other_func]]]]]]]
+ expected = s(:defn, :uses_call,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:call,
+ s(:call, nil, :some_func, s(:arglist)),
+ :+,
+ s(:array, s(:call, nil, :some_other_func, s(:arglist)))))))
assert_equal expected, @heckler.current_tree
end
@@ -440,16 +443,16 @@ def test_default_structure
class TestHeckleCallblock < HeckleTestCase
def setup
- @nodes = [:call]
+ @nodes = s(:call)
super
end
def test_callblock_deleted
- expected = [:defn, :uses_callblock,
- [:scope,
- [:block,
- [:args],
- [:iter, [:call, [:vcall, :x], :y], nil, [:lit, 1]]]]]
+ expected = s(:defn, :uses_callblock,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iter, s(:call, s(:call, nil, :x, s(:arglist)), :y), nil, s(:lit, 1)))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
@@ -461,26 +464,26 @@ class TestHeckleClassMethod < Test::Unit::TestCase
def setup
@heckler = TestHeckler.new("Heckled", "self.is_a_klass_method?")
end
-
+
def teardown
@heckler.reset
end
-
+
def test_default_structure
- expected = [:defs, [:self], :is_a_klass_method?,
- [:scope,
- [:block,
- [:args],
- [:true]]]]
+ expected = s(:defs, s(:self), :is_a_klass_method?,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:true))))
assert_equal expected, @heckler.current_tree
end
-
+
def test_heckle_class_methods
- expected = [:defs, [:self], :is_a_klass_method?,
- [:scope,
- [:block,
- [:args],
- [:false]]]]
+ expected = s(:defs, s(:self), :is_a_klass_method?,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:false))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
@@ -489,29 +492,29 @@ def test_heckle_class_methods
class TestHeckleCvasgn < HeckleTestCase
def setup
- @nodes = [:cvasgn]
+ @nodes = s(:cvasgn)
super
end
def test_cvasgn_val
- expected = [:defn, :uses_cvasgn,
- [:scope,
- [:block,
- [:args],
- [:cvasgn, :@@cvar, [:nil]],
- [:cvasgn, :@@cvar, [:nil]]]]]
+ expected = s(:defn, :uses_cvasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:cvasgn, :@@cvar, s(:nil)),
+ s(:cvasgn, :@@cvar, s(:nil)))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
def test_cvasgn_nil
- expected = [:defn, :uses_cvasgn,
- [:scope,
- [:block,
- [:args],
- [:cvasgn, :@@cvar, [:lit, 5]],
- [:cvasgn, :@@cvar, [:lit, 42]]]]]
+ expected = s(:defn, :uses_cvasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:cvasgn, :@@cvar, s(:lit, 5)),
+ s(:cvasgn, :@@cvar, s(:lit, 42)))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -524,43 +527,43 @@ def test_cvasgn_nil
class TestHeckleDasgn < HeckleTestCase
def setup
- @nodes = [:dasgn]
+ @nodes = s(:dasgn)
super
end
def test_dasgn_val
- expected = [:defn, :uses_dasgn,
- [:scope,
- [:block,
- [:args],
- [:iter,
- [:fcall, :loop],
- [:dasgn_curr, :dvar],
- [:iter,
- [:fcall, :loop],
- nil,
- [:block,
- [:dasgn, :dvar, [:nil]],
- [:dasgn, :dvar, [:nil]]]]]]]]
+ expected = s(:defn, :uses_dasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iter,
+ s(:call, nil, :loop, s(:arglist)),
+ s(:dasgn_curr, :dvar),
+ s(:iter,
+ s(:call, nil, :loop, s(:arglist)),
+ nil,
+ s(:block,
+ s(:dasgn, :dvar, s(:nil)),
+ s(:dasgn, :dvar, s(:nil))))))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
def test_dasgn_nil
- expected = [:defn, :uses_dasgn,
- [:scope,
- [:block,
- [:args],
- [:iter,
- [:fcall, :loop],
- [:dasgn_curr, :dvar],
- [:iter,
- [:fcall, :loop],
- nil,
- [:block,
- [:dasgn, :dvar, [:lit, 5]],
- [:dasgn, :dvar, [:lit, 42]]]]]]]]
+ expected = s(:defn, :uses_dasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iter,
+ s(:call, nil, :loop, s(:arglist)),
+ s(:dasgn_curr, :dvar),
+ s(:iter,
+ s(:call, nil, :loop, s(:arglist)),
+ nil,
+ s(:block,
+ s(:dasgn, :dvar, s(:lit, 5)),
+ s(:dasgn, :dvar, s(:lit, 42))))))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -573,21 +576,21 @@ def test_dasgn_nil
class TestHeckleDasgncurr < HeckleTestCase
def setup
- @nodes = [:dasgn_curr]
+ @nodes = s(:dasgn_curr)
super
end
def test_dasgn_curr_val
- expected = [:defn, :uses_dasgncurr,
- [:scope,
- [:block,
- [:args],
- [:iter,
- [:fcall, :loop],
- [:dasgn_curr, :dvar],
- [:block,
- [:dasgn_curr, :dvar, [:nil]],
- [:dasgn_curr, :dvar, [:nil]]]]]]]
+ expected = s(:defn, :uses_dasgncurr,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iter,
+ s(:call, nil, :loop, s(:arglist)),
+ s(:dasgn_curr, :dvar),
+ s(:block,
+ s(:dasgn_curr, :dvar, s(:nil)),
+ s(:dasgn_curr, :dvar, s(:nil)))))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -596,16 +599,16 @@ def test_dasgn_curr_val
end
def test_dasgn_curr_nil
- expected = [:defn, :uses_dasgncurr,
- [:scope,
- [:block,
- [:args],
- [:iter,
- [:fcall, :loop],
- [:dasgn_curr, :dvar],
- [:block,
- [:dasgn_curr, :dvar, [:lit, 5]],
- [:dasgn_curr, :dvar, [:lit, 42]]]]]]]
+ expected = s(:defn, :uses_dasgncurr,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iter,
+ s(:call, nil, :loop, s(:arglist)),
+ s(:dasgn_curr, :dvar),
+ s(:block,
+ s(:dasgn_curr, :dvar, s(:lit, 5)),
+ s(:dasgn_curr, :dvar, s(:lit, 42)))))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -620,29 +623,29 @@ def test_dasgn_curr_nil
class TestHeckleIasgn < HeckleTestCase
def setup
- @nodes = [:iasgn]
+ @nodes = s(:iasgn)
super
end
def test_iasgn_val
- expected = [:defn, :uses_iasgn,
- [:scope,
- [:block,
- [:args],
- [:iasgn, :@ivar, [:nil]],
- [:iasgn, :@ivar, [:nil]]]]]
+ expected = s(:defn, :uses_iasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iasgn, :@ivar, s(:nil)),
+ s(:iasgn, :@ivar, s(: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]]]]]
+ expected = s(:defn, :uses_iasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:iasgn, :@ivar, s(:lit, 5)),
+ s(:iasgn, :@ivar, s(:lit, 42)))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -655,29 +658,29 @@ def test_iasgn_nil
class TestHeckleGasgn < HeckleTestCase
def setup
- @nodes = [:gasgn]
+ @nodes = s(:gasgn)
super
end
def test_gasgn_val
- expected = [:defn, :uses_gasgn,
- [:scope,
- [:block,
- [:args],
- [:gasgn, :$gvar, [:nil]],
- [:gasgn, :$gvar, [:nil]]]]]
+ expected = s(:defn, :uses_gasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:gasgn, :$gvar, s(:nil)),
+ s(:gasgn, :$gvar, s(:nil)))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
def test_gasgn_nil
- expected = [:defn, :uses_gasgn,
- [:scope,
- [:block,
- [:args],
- [:gasgn, :$gvar, [:lit, 5]],
- [:gasgn, :$gvar, [:lit, 42]]]]]
+ expected = s(:defn, :uses_gasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:gasgn, :$gvar, s(:lit, 5)),
+ s(:gasgn, :$gvar, s(:lit, 42)))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -690,29 +693,29 @@ def test_gasgn_nil
class TestHeckleLasgn < HeckleTestCase
def setup
- @nodes = [:lasgn]
+ @nodes = s(:lasgn)
super
end
def test_lasgn_val
- expected = [:defn, :uses_lasgn,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :lvar, [:nil]],
- [:lasgn, :lvar, [:nil]]]]]
+ expected = s(:defn, :uses_lasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :lvar, s(:nil)),
+ s(:lasgn, :lvar, s(:nil)))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree
end
def test_lasgn_nil
- expected = [:defn, :uses_lasgn,
- [:scope,
- [:block,
- [:args],
- [:lasgn, :lvar, [:lit, 5]],
- [:lasgn, :lvar, [:lit, 42]]]]]
+ expected = s(:defn, :uses_lasgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:lasgn, :lvar, s(:lit, 5)),
+ s(:lasgn, :lvar, s(:lit, 42)))))
@heckler.process(@heckler.current_tree)
@heckler.reset_tree
@@ -725,21 +728,21 @@ def test_lasgn_nil
class TestHeckleMasgn < HeckleTestCase
def setup
- @nodes = [:dasgn, :dasgn_curr, :iasgn, :gasgn, :lasgn]
+ @nodes = s(:dasgn, :dasgn_curr, :iasgn, :gasgn, :lasgn)
super
end
def test_masgn
- expected = [:defn, :uses_masgn,
- [:scope,
- [:block,
- [:args],
- [:masgn,
- [:array,
- [:lasgn, :_heckle_dummy],
- [:gasgn, :$b],
- [:lasgn, :c]],
- [:array, [:lit, 5], [:lit, 6], [:lit, 7]]]]]]
+ expected = s(:defn, :uses_masgn,
+ s(:args),
+ s(:scope,
+ s(:block,
+ s(:masgn,
+ s(:array,
+ s(:lasgn, :_heckle_dummy),
+ s(:gasgn, :$b),
+ s(:lasgn, :c)),
+ s(:array, s(:lit, 5), s(:lit, 6), s(:lit, 7))))))
@heckler.process(@heckler.current_tree)
assert_equal expected, @heckler.current_tree

0 comments on commit c8eb983

Please sign in to comment.