Module: LiveAST::RubyParser::Test

Defined in:
lib/live_ast/ruby_parser/test.rb

Overview

Used by the LiveAST test suite.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.unified_sexp?Boolean

Whether this is Ryan Davis’s unified sexp format.

Returns:

  • (Boolean)


10
11
12
# File 'lib/live_ast/ruby_parser/test.rb', line 10

def unified_sexp?
  true
end

.unparser_matches_ruby2ruby?Boolean

Whether the unparser output matches that of ruby2ruby.

Returns:

  • (Boolean)


17
18
19
# File 'lib/live_ast/ruby_parser/test.rb', line 17

def unparser_matches_ruby2ruby?
  true
end

Instance Method Details

#binop_block(name, op) ⇒ Object

binop_block(:foo, :+) returns the ast of

foo { |x, y| x + y }


143
144
145
146
147
148
# File 'lib/live_ast/ruby_parser/test.rb', line 143

def binop_block(name, op)
  s(:iter,
    s(:call, nil, name),
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#binop_def(name, op) ⇒ Object

binop_def(:f, :+) returns the ast of

def f(x, y)
  x + y
end


58
59
60
61
62
63
# File 'lib/live_ast/ruby_parser/test.rb', line 58

def binop_def(name, op)
  s(:defn,
    name,
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#binop_define_method(name, op, using = :define_method) ⇒ Object

binop_define_method(:f, :*) returns the ast of

define_method :f do |x, y|
  x * y
end

binop_define_method(:f, :-, :my_def) returns the ast of

my_def :f do |x, y|
  x - y
end


93
94
95
96
97
98
# File 'lib/live_ast/ruby_parser/test.rb', line 93

def binop_define_method(name, op, using = :define_method)
  s(:iter,
    s(:call, nil, using, s(:lit, name)),
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#binop_define_method_with_var(var_name, op) ⇒ Object

binop_define_method_with_var(:method_name, :/) returns the ast of

define_method method_name do |x, y|
  x / y
end


107
108
109
110
111
112
# File 'lib/live_ast/ruby_parser/test.rb', line 107

def binop_define_method_with_var(var_name, op)
  s(:iter,
    s(:call, nil, :define_method, s(:lvar, var_name)),
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#binop_define_singleton_method(name, op, receiver) ⇒ Object

binop_define_singleton_method(:f, :+, :a) returns the ast of

a.define_singleton_method :f do |x, y|
  x + y
end


121
122
123
124
125
126
127
# File 'lib/live_ast/ruby_parser/test.rb', line 121

def binop_define_singleton_method(name, op, receiver)
  s(:iter,
    s(:call, s(:lvar, receiver), :define_singleton_method,
      s(:lit, name)),
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#binop_proc_new(op) ⇒ Object

binop_proc_new(:*) returns the ast of

Proc.new { |x, y| x * y }


155
156
157
158
159
160
# File 'lib/live_ast/ruby_parser/test.rb', line 155

def binop_proc_new(op)
  s(:iter,
    s(:call, s(:const, :Proc), :new),
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#nested_defs(u, v, str) ⇒ Object

nested_defs(:f, :g, “foo”) returns the ast of

def f
  Class.new do
    def g
      "foo"
    end
  end
end


188
189
190
191
192
193
194
195
196
# File 'lib/live_ast/ruby_parser/test.rb', line 188

def nested_defs(u, v, str)
  s(:defn,
    u,
    s(:args),
    s(:iter,
      s(:call, s(:const, :Class), :new),
      s(:args),
      s(:defn, v, s(:args), s(:str, str))))
end

#nested_lambdas(str) ⇒ Object

nested_lambdas(“foo”) returns the ast of

lambda {
  lambda {
    "foo"
  }
}


171
172
173
174
175
176
# File 'lib/live_ast/ruby_parser/test.rb', line 171

def nested_lambdas(str)
  s(:iter,
    s(:call, nil, :lambda),
    s(:args),
    s(:iter, s(:call, nil, :lambda), s(:args), s(:str, str)))
end

#no_arg_block(name, ret) ⇒ Object

no_arg_block(:foo, “bar”) returns the ast of

foo { "bar" }


134
135
136
# File 'lib/live_ast/ruby_parser/test.rb', line 134

def no_arg_block(name, ret)
  s(:iter, s(:call, nil, name), s(:args), s(:str, ret))
end

#no_arg_def(name, ret) ⇒ Object

no_arg_def(:f, “A#f”) returns the ast of

def f
  "A#f"
end


29
30
31
# File 'lib/live_ast/ruby_parser/test.rb', line 29

def no_arg_def(name, ret)
  s(:defn, name, s(:args), s(:str, ret))
end

#no_arg_def_return(ast) ⇒ Object

no_arg_def_return(no_arg_def(:f, “A#f”)) == “A#f”



47
48
49
# File 'lib/live_ast/ruby_parser/test.rb', line 47

def no_arg_def_return(ast)
  ast[3][1]
end

#singleton_binop_def(const, name, op) ⇒ Object

singleton_binop_def(:A, :f, :+) returns the ast of

def A.f(x, y)
  x + y
end


72
73
74
75
76
77
78
# File 'lib/live_ast/ruby_parser/test.rb', line 72

def singleton_binop_def(const, name, op)
  s(:defs,
    s(:const, const),
    name,
    s(:args, :x, :y),
    s(:call, s(:lvar, :x), op, s(:lvar, :y)))
end

#singleton_no_arg_def(name, ret) ⇒ Object

singleton_no_arg_def(:f, “foo”) returns the ast of

def self.f
  "foo"
end


40
41
42
# File 'lib/live_ast/ruby_parser/test.rb', line 40

def singleton_no_arg_def(name, ret)
  s(:defs, s(:self), name, s(:args), s(:str, ret))
end