Class: R2RTestCase
- Inherits:
-
MiniTest::Unit::TestCase
- Object
- MiniTest::Unit::TestCase
- R2RTestCase
- Defined in:
- lib/parsetree/test/test_parse_tree_extensions.rb
Instance Method Summary collapse
-
#test_parse_tree_for_proc ⇒ Object
TODO: move?.
- #test_proc_to_ruby ⇒ Object
-
#test_proc_to_ruby_args_1 ⇒ Object
def test_proc_to_ruby_args_0 util_setup_inline block = proc { || puts 42 } assert_equal ‘proc { || puts(42) }’, block.to_ruby end.
- #test_proc_to_ruby_args_n ⇒ Object
- #test_proc_to_sexp ⇒ Object
-
#test_proc_to_sexp_args_1 ⇒ Object
def test_proc_to_sexp_args_0 util_setup_inline p = proc { || 1 + 1 } s = s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1)))) assert_equal s, p.to_sexp end.
- #test_proc_to_sexp_args_n ⇒ Object
- #test_unbound_method_to_ruby ⇒ Object
- #util_setup_inline ⇒ Object
Instance Method Details
#test_parse_tree_for_proc ⇒ Object
TODO: move?
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 79 def test_parse_tree_for_proc # TODO: move? p = proc {|a, b, c|} s = s(:iter, s(:call, nil, :proc, s(:arglist)), s(:masgn, s(:array, s(:lasgn, :a), s(:lasgn, :b), s(:lasgn, :c)))) pt = ParseTree.new(false) u = Unifier.new sexp = pt.parse_tree_for_proc p sexp = u.process(sexp) assert_equal s, sexp end |
#test_proc_to_ruby ⇒ Object
10 11 12 13 14 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 10 def test_proc_to_ruby util_setup_inline block = proc { puts "something" } assert_equal 'proc { puts("something") }', block.to_ruby end |
#test_proc_to_ruby_args_1 ⇒ Object
def test_proc_to_ruby_args_0
util_setup_inline
block = proc { || puts 42 }
assert_equal 'proc { || puts(42) }', block.to_ruby
end
23 24 25 26 27 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 23 def test_proc_to_ruby_args_1 util_setup_inline block = proc { |x| puts x } assert_equal 'proc { |x| puts(x) }', block.to_ruby end |
#test_proc_to_ruby_args_n ⇒ Object
29 30 31 32 33 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 29 def test_proc_to_ruby_args_n util_setup_inline block = proc { |x| puts x } assert_equal 'proc { |x| puts(x) }', block.to_ruby end |
#test_proc_to_sexp ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 35 def test_proc_to_sexp util_setup_inline p = proc { 1 + 1 } s = s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1)))) assert_equal s, p.to_sexp end |
#test_proc_to_sexp_args_1 ⇒ Object
def test_proc_to_sexp_args_0
util_setup_inline
p = proc { || 1 + 1 }
s = s(:iter,
s(:call, nil, :proc, s(:arglist)),
nil,
s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1))))
assert_equal s, p.to_sexp
end
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 56 def test_proc_to_sexp_args_1 util_setup_inline p = proc {|x| puts x } s = s(:iter, s(:call, nil, :proc, s(:arglist)), s(:lasgn, :x), s(:call, nil, :puts, s(:arglist, s(:lvar, :x)))) assert_equal s, p.to_sexp end |
#test_proc_to_sexp_args_n ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 67 def test_proc_to_sexp_args_n util_setup_inline p = proc {|x, y| puts x + y } s = s(:iter, s(:call, nil, :proc, s(:arglist)), s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))), s(:call, nil, :puts, s(:arglist, s(:call, s(:lvar, :x), :+, s(:arglist, s(:lvar, :y)))))) assert_equal s, p.to_sexp end |
#test_unbound_method_to_ruby ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 94 def test_unbound_method_to_ruby util_setup_inline r = "proc { ||\n util_setup_inline\n p = proc { (1 + 1) }\n s = s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, s(:lit, 1), :+, s(:arglist, s(:lit, 1))))\n assert_equal(s, p.to_sexp)\n}" m = self.class.instance_method(:test_proc_to_sexp) assert_equal r, m.to_ruby end |
#util_setup_inline ⇒ Object
102 103 104 105 106 |
# File 'lib/parsetree/test/test_parse_tree_extensions.rb', line 102 def util_setup_inline @rootdir = File.join(Dir.tmpdir, "test_ruby_to_ruby.#{$$}") Dir.mkdir @rootdir, 0700 unless test ?d, @rootdir ENV['INLINEDIR'] = @rootdir end |