mvz-live_ast 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53bc1d58d2c1645ff3d34a4f5f6df3e34a8fb352
4
- data.tar.gz: 6e52ea854d98d13be30b16bd6e3e2acb9933b9ba
3
+ metadata.gz: 472b7811ce8f32d847e2dc967886bc0372a933f8
4
+ data.tar.gz: 2452449770fda858623be66f038b76857b660473
5
5
  SHA512:
6
- metadata.gz: 139a51f52879ec099027541c3826d807eafff81b0e2d06352d7c62ba5d971c143608224213e7fa2a6f1273a5b4eff5d4c2456c7c56e2614714489d9ffc44e5d0
7
- data.tar.gz: 9c7397ca3f90654b71cc0ef9c904f7432e5548a249a1c69200eda4f17e8ade860fd0c4f1ac59cac8c0f93d6ddfe1d268986468220f31cdfe422bb4674fc14461
6
+ metadata.gz: 7f5de1c4c34338e0ece217cea927e9fcde1ae26e6626f9d34624c98de5045456485b2fd54738bf2b2ec4d1248b12a9a458d70193015049d432644376eb1854e3
7
+ data.tar.gz: fc475c11107bc9bef4d8957cc59e82826717c2482bb4e6e7c3feb7ede7586d12e135b950d260cd74745391428e4f73263273ab8a26c9323b6f2a59e99ae7cf6c
@@ -1,6 +1,12 @@
1
1
 
2
2
  = live_ast Changes
3
3
 
4
+ == Version 1.2.0
5
+
6
+ * Drop support for Rubies below 2.1
7
+ * Handle multi-line definitions in IRB correctly
8
+ * Tighten and update dependencies
9
+
4
10
  == Version 1.1.3
5
11
 
6
12
  * Keep ASTs in the cache when they are fetched, allowing aliased methods to
@@ -25,11 +25,11 @@ Live abstract syntax trees of methods and procs. Fork of +live_ast+
25
25
 
26
26
  f = lambda { "foo" }
27
27
  p f.to_ast
28
- # => s(:iter, s(:call, nil, :lambda), s(:args), s(:str, "foo"))
28
+ # => s(:iter, s(:call, nil, :lambda), 0, s(:str, "foo"))
29
29
 
30
30
  def query(&block)
31
31
  p block.to_ast
32
- # => s(:iter, s(:call, nil, :query), s(:args), s(:str, "bar"))
32
+ # => s(:iter, s(:call, nil, :query), 0, s(:str, "bar"))
33
33
  end
34
34
 
35
35
  query do
@@ -40,7 +40,7 @@ Live abstract syntax trees of methods and procs. Fork of +live_ast+
40
40
 
41
41
  u = ast_eval "lambda { 'dynamic3' }", binding
42
42
  p u.to_ast
43
- # => s(:iter, s(:call, nil, :lambda), s(:args), s(:str, "dynamic3"))
43
+ # => s(:iter, s(:call, nil, :lambda), 0, s(:str, "dynamic3"))
44
44
 
45
45
  ast_eval "def v ; 'dynamic4' ; end", binding
46
46
  p method(:v).to_ast
@@ -52,7 +52,7 @@ Live abstract syntax trees of methods and procs. Fork of +live_ast+
52
52
 
53
53
  f = eval "lambda { 'dynamic1' }"
54
54
  p f.to_ast
55
- # => s(:iter, s(:call, nil, :lambda), s(:args), s(:str, "dynamic1"))
55
+ # => s(:iter, s(:call, nil, :lambda), 0, s(:str, "dynamic1"))
56
56
 
57
57
  eval "def g ; 'dynamic2' ; end"
58
58
  p method(:g).to_ast
@@ -80,7 +80,7 @@ sexps used by tools such as <code>ruby2ruby</code>.
80
80
 
81
81
  LiveAST is thread-safe.
82
82
 
83
- Ruby 1.9.2 or higher is required.
83
+ Ruby 2.1.0 or higher is required.
84
84
 
85
85
  == Links
86
86
 
@@ -124,7 +124,7 @@ semantics as +eval+ except that the binding argument is required.
124
124
 
125
125
  u = ast_eval "lambda { 'dynamic3' }", binding
126
126
  p u.to_ast
127
- # => s(:iter, s(:call, nil, :lambda), s(:args), s(:str, "dynamic3"))
127
+ # => s(:iter, s(:call, nil, :lambda), 0, s(:str, "dynamic3"))
128
128
 
129
129
  == Full Integration
130
130
 
@@ -146,7 +146,7 @@ below for details).
146
146
 
147
147
  f = eval "lambda { 'dynamic1' }"
148
148
  p f.to_ast
149
- # => s(:iter, s(:call, nil, :lambda), s(:args), s(:str, "dynamic1"))
149
+ # => s(:iter, s(:call, nil, :lambda), 0, s(:str, "dynamic1"))
150
150
 
151
151
  Since LiveAST itself is pure ruby, any platforms supported by
152
152
  +binding_of_caller+ should work with <code>live_ast/full</code>.
@@ -277,12 +277,12 @@ The following alternative interface is available.
277
277
  # => s(:defn, :f, s(:args), s(:str, "A#f"))
278
278
 
279
279
  p LiveAST.ast(lambda { })
280
- # => s(:iter, s(:call, nil, :lambda), s(:args))
280
+ # => s(:iter, s(:call, nil, :lambda), 0)
281
281
 
282
282
  f = LiveAST.eval("lambda { }", binding)
283
283
 
284
284
  p LiveAST.ast(f)
285
- # => s(:iter, s(:call, nil, :lambda), s(:args))
285
+ # => s(:iter, s(:call, nil, :lambda), 0)
286
286
 
287
287
  ast_eval # => raises NameError
288
288
 
@@ -9,16 +9,16 @@ require 'live_ast/error'
9
9
  require 'live_ast/irb_spy' if defined?(IRB)
10
10
 
11
11
  module LiveAST
12
- NATIVE_EVAL = Kernel.method(:eval) #:nodoc:
12
+ NATIVE_EVAL = Kernel.method(:eval) #:nodoc:
13
13
 
14
14
  class << self
15
- attr_writer :parser #:nodoc:
15
+ attr_writer :parser #:nodoc:
16
16
 
17
- def parser #:nodoc:
18
- @parser ||= (
17
+ def parser #:nodoc:
18
+ @parser ||= begin
19
19
  require 'live_ast/ruby_parser'
20
20
  LiveAST::RubyParser
21
- )
21
+ end
22
22
  end
23
23
 
24
24
  #
@@ -26,7 +26,7 @@ module LiveAST
26
26
  #
27
27
  # Equivalent to <code>obj.to_ast</code>.
28
28
  #
29
- def ast(obj) #:nodoc:
29
+ def ast(obj) #:nodoc:
30
30
  case obj
31
31
  when Method, UnboundMethod
32
32
  Linker.find_method_ast(obj.owner, obj.name, *obj.source_location)
@@ -50,7 +50,7 @@ module LiveAST
50
50
  #
51
51
  # Equivalent to <code>Kernel#ast_eval</code>.
52
52
  #
53
- def eval(*args) #:nodoc:
53
+ def eval(*args) #:nodoc:
54
54
  Evaler.eval(args[0], *args)
55
55
  end
56
56
 
@@ -59,14 +59,14 @@ module LiveAST
59
59
  #
60
60
  # Equivalent to <code>Kernel#ast_load</code>.
61
61
  #
62
- def load(file, wrap = false) #:nodoc:
62
+ def load(file, wrap = false) #:nodoc:
63
63
  Loader.load(file, wrap)
64
64
  end
65
65
 
66
66
  #
67
67
  # strip the revision token from a string
68
68
  #
69
- def strip_token(file) #:nodoc:
69
+ def strip_token(file) #:nodoc:
70
70
  file.sub(/#{Regexp.quote Linker::REVISION_TOKEN}[a-z]+/, "")
71
71
  end
72
72
  end
@@ -8,11 +8,7 @@ module LiveAST
8
8
  rescue NameError
9
9
  thing = arg.nil? ? nil : arg.class
10
10
 
11
- message = if RUBY_VERSION < "2.0.0"
12
- "can't convert #{thing.inspect} into String"
13
- else
14
- "no implicit conversion of #{thing.inspect} into String"
15
- end
11
+ message = "no implicit conversion of #{thing.inspect} into String"
16
12
  raise TypeError, message
17
13
  end
18
14
 
@@ -21,17 +17,18 @@ module LiveAST
21
17
 
22
18
  range = 0 if range == (0..0)
23
19
 
24
- raise ArgumentError,
25
- "wrong number of arguments (#{args.size} for #{range})"
20
+ message = if RUBY_VERSION < "2.3.0"
21
+ "wrong number of arguments (#{args.size} for #{range})"
22
+ else
23
+ "wrong number of arguments (given #{args.size}, expected #{range})"
24
+ end
25
+ raise ArgumentError, message
26
26
  end
27
27
 
28
28
  def check_is_binding(obj)
29
29
  return if obj.is_a? Binding
30
- message = if RUBY_VERSION < "2.1.0"
31
- "wrong argument type #{obj.class} (expected Binding)"
32
- else
33
- "wrong argument type #{obj.class} (expected binding)"
34
- end
30
+
31
+ message = "wrong argument type #{obj.class} (expected binding)"
35
32
  raise TypeError, message
36
33
  end
37
34
 
@@ -1,5 +1,5 @@
1
1
  module LiveAST
2
- class MultipleDefinitionsOnSameLineError < ScriptError
2
+ class MultipleDefinitionsOnSameLineError < RuntimeError
3
3
  def message
4
4
  "AST requested for a method or block that shares a line " \
5
5
  "with another method or block."
@@ -9,7 +9,7 @@ module LiveAST
9
9
  file, line = location_for_eval(bind, *rest)
10
10
  file = LiveAST.strip_token(file)
11
11
 
12
- key, _ = Linker.new_cache_synced(parser_source, file, line, false)
12
+ key, = Linker.new_cache_synced(parser_source, file, line, false)
13
13
 
14
14
  begin
15
15
  NATIVE_EVAL.call(evaler_source, bind, key, line)
@@ -7,20 +7,23 @@ module LiveAST
7
7
  attr_writer :history
8
8
 
9
9
  def code_at(line)
10
- unless @history
11
- raise NotImplementedError,
12
- "LiveAST cannot access history for this IRB input method"
10
+ code = ""
11
+ checked_history[line..-1].each do |code_line|
12
+ code << code_line << "\n"
13
+ return code if can_parse code
13
14
  end
14
- grow = 0
15
- begin
16
- code = @history[line..(line + grow)].join
17
- LiveAST.parser.new.parse(code) or raise "#{LiveAST.parser} error"
18
- rescue
19
- grow += 1
20
- retry if line + grow < @history.size
21
- raise
22
- end
23
- code
15
+ end
16
+
17
+ def can_parse(code)
18
+ LiveAST.parser.new.parse(code)
19
+ rescue StandardError
20
+ false
21
+ end
22
+
23
+ def checked_history
24
+ return @history if @history
25
+ raise NotImplementedError,
26
+ "LiveAST cannot access history for this IRB input method"
24
27
  end
25
28
  end
26
29
  end
@@ -41,7 +41,7 @@ module LiveAST
41
41
  end
42
42
 
43
43
  module Linker
44
- REVISION_TOKEN = "|ast@"
44
+ REVISION_TOKEN = "|ast@".freeze
45
45
 
46
46
  @caches = {}
47
47
  @counter = "a"
@@ -18,15 +18,12 @@ module LiveAST
18
18
  end
19
19
 
20
20
  def header_footer(wrap)
21
- if wrap
22
- return "class << Object.new;", ";end", true
23
- else
24
- locals = NATIVE_EVAL.call("local_variables", TOPLEVEL_BINDING)
21
+ return "class << Object.new;", ";end", true if wrap
22
+ locals = NATIVE_EVAL.call("local_variables", TOPLEVEL_BINDING)
25
23
 
26
- params = locals.empty? ? "" : ("|;" + locals.join(",") + "|")
24
+ params = locals.empty? ? "" : ("|;" + locals.join(",") + "|")
27
25
 
28
- return "lambda do #{params}", ";end.call", locals.empty?
29
- end
26
+ return "lambda do #{params}", ";end.call", locals.empty?
30
27
  end
31
28
 
32
29
  def suppress_warnings
@@ -1,4 +1,5 @@
1
1
  # encoding: us-ascii
2
+
2
3
  module LiveAST
3
4
  module Reader
4
5
  UTF8_BOM = /\A\xef\xbb\xbf/
@@ -32,31 +32,10 @@ module LiveAST
32
32
  private
33
33
 
34
34
  def handle_args(args)
35
- if RUBY_VERSION < '2.0.0'
36
- handle_args_pre_20(args)
37
- else
38
- handle_args_20(args)
39
- end
40
- end
41
-
42
- def handle_args_20(args)
43
35
  LiveAST::Common.check_arity(args, 1..3)
44
36
  args[0] = Common.arg_to_str(args[0])
45
37
  args[1] = Common.arg_to_str(args[1]) if args.length > 1
46
38
  end
47
-
48
- def handle_args_pre_20(args)
49
- raise ArgumentError, "block not supplied" if args.empty?
50
-
51
- args[0] = Common.arg_to_str(args[0])
52
-
53
- unless (1..3).include? args.size
54
- raise ArgumentError,
55
- "wrong number of arguments: instance_eval(src) or instance_eval{..}"
56
- end
57
-
58
- args[1] = Common.arg_to_str(args[1]) if args.length > 1
59
- end
60
39
  end
61
40
  end
62
41
 
@@ -67,23 +46,24 @@ end
67
46
  # Override for Kernel#eval and Kernel.eval
68
47
  module Kernel
69
48
  class << self
70
- alias_method :live_ast_original_singleton_eval, :eval
49
+ alias live_ast_original_singleton_eval eval
71
50
  end
72
51
 
73
- alias_method :live_ast_original_eval, :eval
52
+ alias live_ast_original_eval eval
74
53
 
75
54
  def eval(*args)
76
55
  LiveAST::Common.check_arity(args, 1..4)
77
56
  LiveAST.eval(
78
57
  args[0],
79
58
  args[1] || binding.of_caller(1),
80
- *LiveAST::Common.location_for_eval(*args[1..3]))
59
+ *LiveAST::Common.location_for_eval(*args[1..3])
60
+ )
81
61
  end
82
62
  end
83
63
 
84
64
  # Override for Binding#eval
85
65
  class Binding
86
- alias_method :live_ast_original_binding_eval, :eval
66
+ alias live_ast_original_binding_eval eval
87
67
 
88
68
  def eval(*args)
89
69
  LiveAST.eval(args[0], self, *args[1..-1])
@@ -92,21 +72,24 @@ end
92
72
 
93
73
  # Override for BasicObject#instance_eval
94
74
  class BasicObject
95
- alias_method :live_ast_original_instance_eval, :instance_eval
75
+ alias live_ast_original_instance_eval instance_eval
96
76
 
97
77
  def instance_eval(*args, &block)
98
78
  if block
99
79
  live_ast_original_instance_eval(*args, &block)
100
80
  else
101
81
  ::LiveAST::ReplaceEval.
102
- module_or_instance_eval(:instance, self, ::Kernel.binding.of_caller(1), args)
82
+ module_or_instance_eval(:instance,
83
+ self,
84
+ ::Kernel.binding.of_caller(1),
85
+ args)
103
86
  end
104
87
  end
105
88
  end
106
89
 
107
90
  # Overrides for Module#module_eval and Module#class_eval
108
91
  class Module
109
- alias_method :live_ast_original_module_eval, :module_eval
92
+ alias live_ast_original_module_eval module_eval
110
93
 
111
94
  def module_eval(*args, &block)
112
95
  if block
@@ -118,5 +101,5 @@ class Module
118
101
  end
119
102
 
120
103
  remove_method :class_eval
121
- alias_method :class_eval, :module_eval
104
+ alias class_eval module_eval
122
105
  end
@@ -1,7 +1,7 @@
1
1
  require 'live_ast/base'
2
2
 
3
3
  module Kernel
4
- alias_method :live_ast_original_load, :load
4
+ alias live_ast_original_load load
5
5
 
6
6
  def load(file, wrap = false)
7
7
  LiveAST.load(file, wrap)
@@ -3,7 +3,7 @@ require 'live_ast/base'
3
3
  module Kernel
4
4
  private
5
5
 
6
- alias_method :live_ast_original_raise, :raise
6
+ alias live_ast_original_raise raise
7
7
 
8
8
  def raise(*args)
9
9
  ex = begin
@@ -15,11 +15,10 @@ module LiveAST
15
15
  @defs
16
16
  end
17
17
 
18
+ STOREABLE_SEXP_TYPES = [:defn, :defs, :iter].freeze
19
+
18
20
  def process(sexp)
19
- case sexp.first
20
- when :defn, :defs, :iter
21
- store_sexp(sexp, sexp.line)
22
- end
21
+ store_sexp(sexp, sexp.line) if STOREABLE_SEXP_TYPES.include? sexp.first
23
22
 
24
23
  sexp.each do |elem|
25
24
  process(elem) if elem.is_a? Sexp
@@ -134,7 +134,7 @@ module LiveAST
134
134
  # foo { "bar" }
135
135
  #
136
136
  def no_arg_block(name, ret)
137
- s(:iter, s(:call, nil, name), s(:args), s(:str, ret))
137
+ s(:iter, s(:call, nil, name), 0, s(:str, ret))
138
138
  end
139
139
 
140
140
  #
@@ -173,8 +173,8 @@ module LiveAST
173
173
  def nested_lambdas(str)
174
174
  s(:iter,
175
175
  s(:call, nil, :lambda),
176
- s(:args),
177
- s(:iter, s(:call, nil, :lambda), s(:args), s(:str, str)))
176
+ 0,
177
+ s(:iter, s(:call, nil, :lambda), 0, s(:str, str)))
178
178
  end
179
179
 
180
180
  # nested_defs(:f, :g, "foo") returns the ast of
@@ -193,7 +193,7 @@ module LiveAST
193
193
  s(:args),
194
194
  s(:iter,
195
195
  s(:call, s(:const, :Class), :new),
196
- s(:args),
196
+ 0,
197
197
  s(:defn, v, s(:args), s(:str, str))))
198
198
  end
199
199
  end
@@ -2,7 +2,7 @@ require 'live_ast/base'
2
2
 
3
3
  [Method, UnboundMethod, Proc].each do |klass|
4
4
  klass.class_eval do
5
- def to_ruby #:nodoc:
5
+ def to_ruby #:nodoc:
6
6
  LiveAST.parser::Unparser.unparse(LiveAST.ast(self))
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module LiveAST
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0".freeze
3
3
  end
@@ -21,4 +21,3 @@ class AliasTest < RegularTest
21
21
  assert_equal expected, A.new.method(:g).to_ast
22
22
  end
23
23
  end
24
-
@@ -14,7 +14,7 @@ class AstLoadTest < BaseTest
14
14
  end
15
15
 
16
16
  def noninvasive_ast_reload
17
- code_1 = %{
17
+ code1 = %{
18
18
  class AstLoadTest::B
19
19
  def f
20
20
  "first B#f"
@@ -22,7 +22,7 @@ class AstLoadTest < BaseTest
22
22
  end
23
23
  }
24
24
 
25
- code_2 = %{
25
+ code2 = %{
26
26
  class AstLoadTest::B
27
27
  def f
28
28
  "second B#f"
@@ -30,12 +30,12 @@ class AstLoadTest < BaseTest
30
30
  end
31
31
  }
32
32
 
33
- temp_file code_1 do |file|
33
+ temp_file code1 do |file|
34
34
  load file
35
35
 
36
36
  LiveAST.ast(B.instance_method(:f))
37
37
 
38
- write_file file, code_2
38
+ write_file file, code2
39
39
  ast_load file
40
40
 
41
41
  assert_equal no_arg_def(:f, "second B#f"),
@@ -150,7 +150,7 @@ define_unsorted_test_case "BacktraceTest", RegularTest do
150
150
 
151
151
  def test_tokens_stripped
152
152
  lines = exception_backtrace do
153
- ast_eval %{ ast_eval %{ ast_eval %{raise}, binding }, binding }, binding
153
+ ast_eval %{ ast_eval ' ast_eval "raise", binding ', binding }, binding
154
154
  end
155
155
  lines.each do |line|
156
156
  assert_nil line.index(LiveAST::Linker::REVISION_TOKEN)
@@ -8,7 +8,7 @@ class ReloadTest < BaseTest
8
8
  end
9
9
 
10
10
  def raw_reload
11
- code_1 = %{
11
+ code1 = %{
12
12
  class ReloadTest::A
13
13
  def f
14
14
  "first A#f"
@@ -16,7 +16,7 @@ class ReloadTest < BaseTest
16
16
  end
17
17
  }
18
18
 
19
- code_2 = %{
19
+ code2 = %{
20
20
  class ReloadTest::A
21
21
  def f
22
22
  "second A#f"
@@ -24,12 +24,12 @@ class ReloadTest < BaseTest
24
24
  end
25
25
  }
26
26
 
27
- temp_file code_1 do |file|
27
+ temp_file code1 do |file|
28
28
  load file
29
29
 
30
30
  LiveAST.ast(A.instance_method(:f))
31
31
 
32
- write_file file, code_2
32
+ write_file file, code2
33
33
  load file
34
34
 
35
35
  # forced a raw-reload inconsistency -- verify bogus
@@ -1,29 +1,23 @@
1
1
  require_relative 'main'
2
2
 
3
3
  class AllEncodingTest < RegularTest
4
- ENC_TESTS = Hash[*%w(
5
- default US-ASCII
6
- usascii US-ASCII
7
- utf8 UTF-8
8
- utf8unix UTF-8
9
- utf8mac UTF-8
10
- utf8mac_alt UTF8-MAC
11
- utf8dos UTF-8
12
- utf8bom UTF-8
13
- utf8bom_only UTF-8
14
- usascii_with_utf8bom US-ASCII
15
- koi8_with_utf8bom KOI8-R
16
- cp932 Windows-31J
17
- eucjp EUC-JP
18
- koi8 KOI8-R
19
- koi8_shebang KOI8-R
20
- )]
21
-
22
- if RUBY_VERSION < '2.0.0'
23
- ENC_TESTS['default'] = 'US-ASCII'
24
- else
25
- ENC_TESTS['default'] = 'UTF-8'
26
- end
4
+ ENC_TESTS = {
5
+ default: "UTF-8",
6
+ usascii: "US-ASCII",
7
+ utf8: "UTF-8",
8
+ utf8unix: "UTF-8",
9
+ utf8mac: "UTF-8",
10
+ utf8mac_alt: "UTF8-MAC",
11
+ utf8dos: "UTF-8",
12
+ utf8bom: "UTF-8",
13
+ utf8bom_only: "UTF-8",
14
+ usascii_with_utf8bom: "US-ASCII",
15
+ koi8_with_utf8bom: "KOI8-R",
16
+ cp932: "Windows-31J",
17
+ eucjp: "EUC-JP",
18
+ koi8: "KOI8-R",
19
+ koi8_shebang: "KOI8-R"
20
+ }.freeze
27
21
 
28
22
  ENC_TESTS.each_pair do |abbr, name|
29
23
  define_method "test_#{abbr}" do
@@ -8,7 +8,7 @@ class ASTReloadTest < ReplaceEvalTest
8
8
  end
9
9
 
10
10
  def ast_reload
11
- code_1 = %{
11
+ code1 = %{
12
12
  class ASTReloadTest::C
13
13
  def f
14
14
  "first C#f"
@@ -16,7 +16,7 @@ class ASTReloadTest < ReplaceEvalTest
16
16
  end
17
17
  }
18
18
 
19
- code_2 = %{
19
+ code2 = %{
20
20
  class ASTReloadTest::C
21
21
  def f
22
22
  "second C#f"
@@ -24,12 +24,12 @@ class ASTReloadTest < ReplaceEvalTest
24
24
  end
25
25
  }
26
26
 
27
- temp_file code_1 do |file|
27
+ temp_file code1 do |file|
28
28
  load file
29
29
 
30
30
  LiveAST.ast(C.instance_method(:f))
31
31
 
32
- write_file file, code_2
32
+ write_file file, code2
33
33
  load file
34
34
 
35
35
  assert_equal no_arg_def(:f, "second C#f"),
@@ -174,10 +174,16 @@ class FullReplaceEvalTest < ReplaceEvalTest
174
174
  require 'live_ast/full'
175
175
  end
176
176
 
177
- let(:orig) { assert_raises(ArgumentError, TypeError) {
178
- Object.new.live_ast_original_instance_eval(*args) } }
179
- let(:live) { assert_raises(ArgumentError, TypeError) {
180
- Object.new.instance_eval(*args) } }
177
+ let(:orig) {
178
+ assert_raises(ArgumentError, TypeError) do
179
+ Object.new.live_ast_original_instance_eval(*args)
180
+ end
181
+ }
182
+ let(:live) {
183
+ assert_raises(ArgumentError, TypeError) do
184
+ Object.new.instance_eval(*args)
185
+ end
186
+ }
181
187
 
182
188
  describe "when the second argument is nil" do
183
189
  let(:args) { ['1', nil] }
@@ -354,7 +360,7 @@ class FullReplaceEvalTest < ReplaceEvalTest
354
360
 
355
361
  x = 5
356
362
  eval %{
357
- assert_equal(3, eval(%{ eval("1 + 2") }))
363
+ assert_equal(3, eval(' eval("1 + 2") '))
358
364
  x = 6
359
365
  }
360
366
  assert_equal 6, x
@@ -1,4 +1,5 @@
1
1
  require_relative 'main'
2
+ require 'live_ast/irb_spy'
2
3
 
3
4
  class IRBTest < RegularTest
4
5
  def with_module(parent, child)
@@ -10,16 +11,31 @@ class IRBTest < RegularTest
10
11
  end
11
12
  end
12
13
 
13
- def test_irb
14
+ def setup
15
+ LiveAST::IRBSpy.history = [
16
+ nil,
17
+ "class Foo; def bar; 'bar'; end; end",
18
+ "class Bar",
19
+ " def foo",
20
+ " 'foo'",
21
+ " end",
22
+ "end"
23
+ ]
24
+ end
25
+
26
+ def test_single_line
27
+ with_module(Object, :IRB) do
28
+ expected = no_arg_def(:bar, "bar")
29
+ result = LiveAST::Linker.fetch_from_cache("(irb)", 1)
30
+ assert_equal expected, result
31
+ end
32
+ end
33
+
34
+ def test_multiple_lines
14
35
  with_module(Object, :IRB) do
15
- with_module(LiveAST, :IRBSpy) do
16
- LiveAST::IRBSpy.class_eval do
17
- def self.code_at(_line)
18
- "def f ; end"
19
- end
20
- end
21
- LiveAST::Linker.fetch_from_cache("(irb)", 1)
22
- end
36
+ expected = no_arg_def(:foo, "foo")
37
+ result = LiveAST::Linker.fetch_from_cache("(irb)", 3)
38
+ assert_equal expected, result
23
39
  end
24
40
  end
25
41
  end
@@ -19,7 +19,7 @@ class LoadPathTest < BaseTest
19
19
  end
20
20
 
21
21
  def test_chdir
22
- mkdir DATA_DIR, verbose: false rescue nil
22
+ mkdir DATA_DIR, verbose: false
23
23
  Dir.chdir(DATA_DIR) do
24
24
  check_load
25
25
  check_errors
@@ -27,32 +27,30 @@ class LoadPathTest < BaseTest
27
27
  end
28
28
 
29
29
  def check_load
30
- code_1 = %{
30
+ code1 = %{
31
31
  def hello
32
32
  "password"
33
33
  end
34
34
  }
35
35
 
36
- code_2 = %{
36
+ code2 = %{
37
37
  def goodbye
38
38
  "bubbleboy"
39
39
  end
40
40
  }
41
41
 
42
- temp_file code_1, "foo.rb" do |path|
43
- Object.send(:remove_method, :hello) rescue nil
42
+ temp_file code1, "foo.rb" do |path|
44
43
  load "foo.rb"
45
44
  assert_equal "password", hello
46
45
 
47
- write_file path, code_2
46
+ write_file path, code2
48
47
 
49
- Object.send(:remove_method, :goodbye) rescue nil
50
48
  LiveAST.load "foo.rb"
51
49
  assert_equal "bubbleboy", goodbye
52
50
  end
53
51
  ensure
54
- Object.send(:remove_method, :hello) rescue nil
55
- Object.send(:remove_method, :goodbye) rescue nil
52
+ Object.send(:remove_method, :hello)
53
+ Object.send(:remove_method, :goodbye)
56
54
  end
57
55
 
58
56
  def compare_load_errors(file)
@@ -36,8 +36,8 @@ class JLMiniTest < MiniTest::Test
36
36
 
37
37
  def mu_pp(obj)
38
38
  delim("_") <<
39
- obj.pretty_inspect.chomp <<
40
- delim("=")
39
+ obj.pretty_inspect.chomp <<
40
+ delim("=")
41
41
  end
42
42
 
43
43
  def unfixable
@@ -49,7 +49,7 @@ class JLMiniTest < MiniTest::Test
49
49
  def assert_nothing_raised
50
50
  yield
51
51
  assert_nil nil
52
- rescue => ex
52
+ rescue StandardError => ex
53
53
  raise MiniTest::Assertion,
54
54
  exception_details(ex, "Expected nothing raised, but got:")
55
55
  end
@@ -81,7 +81,7 @@ class BaseTest < JLMiniTest
81
81
  yield path
82
82
  ensure
83
83
  FileUtils.rm_f path
84
- FileUtils.rmdir DATA_DIR rescue nil
84
+ FileUtils.rmdir DATA_DIR
85
85
  end
86
86
  end
87
87
 
@@ -99,8 +99,7 @@ class BaseTest < JLMiniTest
99
99
  e.backtrace
100
100
  end
101
101
 
102
- def ignore(*_args)
103
- end
102
+ def ignore(*_args); end
104
103
  end
105
104
 
106
105
  class RegularTest < BaseTest
@@ -4,36 +4,38 @@ require_relative '../devel/levitate'
4
4
  #
5
5
  # Tests against rubyspec branch which discards '|ast@' tokens
6
6
  #
7
- class RubySpecTest < RegularTest
8
- FILES = [
9
- 'core/basicobject/instance_eval_spec.rb',
10
- 'core/binding/eval_spec.rb',
11
- 'core/kernel/eval_spec.rb',
12
- 'core/kernel/instance_eval_spec.rb',
13
- 'core/module/class_eval_spec.rb',
14
- 'core/module/module_eval_spec.rb',
15
- ]
7
+ if ENV["LIVE_AST_RUBYSPEC_HOME"]
8
+ class RubySpecTest < RegularTest
9
+ FILES = [
10
+ 'core/basicobject/instance_eval_spec.rb',
11
+ 'core/binding/eval_spec.rb',
12
+ 'core/kernel/eval_spec.rb',
13
+ 'core/kernel/instance_eval_spec.rb',
14
+ 'core/module/class_eval_spec.rb',
15
+ 'core/module/module_eval_spec.rb',
16
+ ].freeze
16
17
 
17
- def setup
18
- super
19
- puts "\n==== rubyspec"
20
- end
18
+ def setup
19
+ super
20
+ puts "\n==== rubyspec"
21
+ end
21
22
 
22
- FILES.each do |file|
23
- mname = "test_" + file.gsub("/", "_").chop!.chop!.chop!
24
- define_method mname do
25
- Dir.chdir ENV["LIVE_AST_RUBYSPEC_HOME"] do
26
- cmd =
27
- ["mspec", "-t", Levitate.ruby_bin] +
23
+ FILES.each do |file|
24
+ mname = "test_" + file.tr("/", "_").chop!.chop!.chop!
25
+ define_method mname do
26
+ Dir.chdir ENV["LIVE_AST_RUBYSPEC_HOME"] do
27
+ cmd =
28
+ ["mspec", "-t", Levitate.ruby_bin] +
28
29
 
29
- (["-T"] * Levitate.ruby_opts.size).
30
- zip(Levitate.ruby_opts).
31
- flatten +
30
+ (["-T"] * Levitate.ruby_opts.size).
31
+ zip(Levitate.ruby_opts).
32
+ flatten +
32
33
 
33
- [file]
34
+ [file]
34
35
 
35
- assert system(*cmd)
36
+ assert system(*cmd)
37
+ end
36
38
  end
37
39
  end
38
40
  end
39
- end if ENV["LIVE_AST_RUBYSPEC_HOME"]
41
+ end
@@ -33,7 +33,7 @@ class ThreadTest < RegularTest
33
33
  sleep(0.2)
34
34
  stop = true
35
35
 
36
- workers.each { |t| t.join }
36
+ workers.each(&:join)
37
37
 
38
38
  assert_equal num_threads, results.size
39
39
  results.each { |result|
@@ -1,97 +1,99 @@
1
1
  require 'main'
2
2
 
3
- class ToRubyTest < RegularTest
4
- def setup
5
- super
6
- require 'live_ast/to_ruby'
3
+ if LiveAST.parser::Test.respond_to?(:unparser_matches_ruby2ruby?) &&
4
+ LiveAST.parser::Test.unparser_matches_ruby2ruby?
5
+ class ToRubyTest < RegularTest
6
+ def setup
7
+ super
8
+ require 'live_ast/to_ruby'
9
+ end
10
+
11
+ def test_lambda_0
12
+ src = %{lambda { "moo" }}
13
+ dst = ast_eval(src, binding).to_ruby
14
+ assert_equal src, dst
15
+ end
16
+
17
+ def test_lambda_1
18
+ src = %{lambda { |x| (x ** 2) }}
19
+ dst = ast_eval(src, binding).to_ruby
20
+ assert_equal src, dst
21
+ end
22
+
23
+ def test_lambda_2
24
+ src = %{lambda { |x, y| (x + y) }}
25
+ dst = ast_eval(src, binding).to_ruby
26
+ assert_equal src, dst
27
+ end
28
+
29
+ def test_proc_0
30
+ src = %{proc { "moo" }}
31
+ dst = ast_eval(src, binding).to_ruby
32
+ assert_equal src, dst
33
+ end
34
+
35
+ def test_proc_1
36
+ src = %{proc { |x| (x ** 2) }}
37
+ dst = ast_eval(src, binding).to_ruby
38
+ assert_equal src, dst
39
+ end
40
+
41
+ def test_proc_2
42
+ src = %{proc { |x, y| (x * y) }}
43
+ dst = ast_eval(src, binding).to_ruby
44
+ assert_equal src, dst
45
+ end
46
+
47
+ def test_block_0
48
+ src = %{return_block { "moo" }}
49
+ dst = ast_eval(src, binding).to_ruby
50
+ assert_equal src, dst
51
+ end
52
+
53
+ def test_block_1
54
+ src = %{return_block { |x| (x ** 2) }}
55
+ dst = ast_eval(src, binding).to_ruby
56
+ assert_equal src, dst
57
+ end
58
+
59
+ def test_block_2
60
+ src = %{return_block { |x, y| (x - y) }}
61
+ dst = ast_eval(src, binding).to_ruby
62
+ assert_equal src, dst
63
+ end
64
+
65
+ def test_method_0
66
+ src = %{def f\n "moo"\nend}
67
+ dst = Class.new do
68
+ ast_eval(src, binding)
69
+ end.instance_method(:f).to_ruby
70
+ assert_equal src, dst
71
+ end
72
+
73
+ def test_method_1
74
+ src = %{def f(x)\n (x ** 2)\nend}
75
+ dst = Class.new do
76
+ ast_eval(src, binding)
77
+ end.instance_method(:f).to_ruby
78
+ assert_equal src, dst
79
+ end
80
+
81
+ def test_method_2
82
+ src = %{def f(x, y)\n (x / y)\nend}
83
+ dst = Class.new do
84
+ ast_eval(src, binding)
85
+ end.instance_method(:f).to_ruby
86
+ assert_equal src, dst
87
+ end
88
+
89
+ def test_to_ast_after_to_ruby
90
+ src = %{lambda { "moo" }}
91
+ expected_ast = ast_eval(src, binding).to_ast
92
+
93
+ lmb = ast_eval(src, binding)
94
+ lmb.to_ruby
95
+
96
+ assert_equal expected_ast, lmb.to_ast
97
+ end
7
98
  end
8
-
9
- def test_lambda_0
10
- src = %{lambda { "moo" }}
11
- dst = ast_eval(src, binding).to_ruby
12
- assert_equal src, dst
13
- end
14
-
15
- def test_lambda_1
16
- src = %{lambda { |x| (x ** 2) }}
17
- dst = ast_eval(src, binding).to_ruby
18
- assert_equal src, dst
19
- end
20
-
21
- def test_lambda_2
22
- src = %{lambda { |x, y| (x + y) }}
23
- dst = ast_eval(src, binding).to_ruby
24
- assert_equal src, dst
25
- end
26
-
27
- def test_proc_0
28
- src = %{proc { "moo" }}
29
- dst = ast_eval(src, binding).to_ruby
30
- assert_equal src, dst
31
- end
32
-
33
- def test_proc_1
34
- src = %{proc { |x| (x ** 2) }}
35
- dst = ast_eval(src, binding).to_ruby
36
- assert_equal src, dst
37
- end
38
-
39
- def test_proc_2
40
- src = %{proc { |x, y| (x * y) }}
41
- dst = ast_eval(src, binding).to_ruby
42
- assert_equal src, dst
43
- end
44
-
45
- def test_block_0
46
- src = %{return_block { "moo" }}
47
- dst = ast_eval(src, binding).to_ruby
48
- assert_equal src, dst
49
- end
50
-
51
- def test_block_1
52
- src = %{return_block { |x| (x ** 2) }}
53
- dst = ast_eval(src, binding).to_ruby
54
- assert_equal src, dst
55
- end
56
-
57
- def test_block_2
58
- src = %{return_block { |x, y| (x - y) }}
59
- dst = ast_eval(src, binding).to_ruby
60
- assert_equal src, dst
61
- end
62
-
63
- def test_method_0
64
- src = %{def f\n "moo"\nend}
65
- dst = Class.new do
66
- ast_eval(src, binding)
67
- end.instance_method(:f).to_ruby
68
- assert_equal src, dst
69
- end
70
-
71
- def test_method_1
72
- src = %{def f(x)\n (x ** 2)\nend}
73
- dst = Class.new do
74
- ast_eval(src, binding)
75
- end.instance_method(:f).to_ruby
76
- assert_equal src, dst
77
- end
78
-
79
- def test_method_2
80
- src = %{def f(x, y)\n (x / y)\nend}
81
- dst = Class.new do
82
- ast_eval(src, binding)
83
- end.instance_method(:f).to_ruby
84
- assert_equal src, dst
85
- end
86
-
87
- def test_to_ast_after_to_ruby
88
- src = %{lambda { "moo" }}
89
- expected_ast = ast_eval(src, binding).to_ast
90
-
91
- lmb = ast_eval(src, binding)
92
- lmb.to_ruby
93
-
94
- assert_equal expected_ast, lmb.to_ast
95
- end
96
- end if LiveAST.parser::Test.respond_to?(:unparser_matches_ruby2ruby?) &&
97
- LiveAST.parser::Test.unparser_matches_ruby2ruby?
99
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvz-live_ast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-23 00:00:00.000000000 Z
12
+ date: 2017-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby_parser
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '3.3'
20
+ version: 3.10.1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '3.3'
27
+ version: 3.10.1
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: ruby2ruby
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 2.4.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 2.4.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: binding_of_caller
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 0.7.2
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 0.7.2
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ">="
215
215
  - !ruby/object:Gem::Version
216
- version: 1.9.2
216
+ version: 2.1.0
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="
@@ -221,59 +221,58 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  version: '0'
222
222
  requirements: []
223
223
  rubyforge_project:
224
- rubygems_version: 2.4.1
224
+ rubygems_version: 2.6.13
225
225
  signing_key:
226
226
  specification_version: 4
227
227
  summary: Live abstract syntax trees of methods and procs.
228
228
  test_files:
229
- - test/covert_define_method_test.rb
230
- - test/singleton_test.rb
231
- - test/to_ast/to_ast_feature_test.rb
232
- - test/irb_test.rb
229
+ - test/readme_test.rb
230
+ - test/rubyspec_test.rb
231
+ - test/lambda_test.rb
232
+ - test/redefine_method_test.rb
233
233
  - test/stdlib_test.rb
234
- - test/rubygems_test.rb
235
234
  - test/full/replace_eval_test.rb
236
235
  - test/full/ast_reload_test.rb
237
236
  - test/to_ruby/to_ruby_test.rb
238
237
  - test/to_ruby/to_ruby_feature_test.rb
239
- - test/flush_cache_test.rb
240
- - test/eval_test.rb
241
- - test/ast_eval/ast_eval_test.rb
242
- - test/readme_test.rb
243
- - test/def_test.rb
244
- - test/attr_test.rb
245
- - test/thread_test.rb
246
- - test/load_path_test.rb
247
- - test/ast_load/ast_load_test.rb
248
- - test/alias_test.rb
249
- - test/rubyspec_test.rb
250
- - test/redefine_method_test.rb
251
- - test/lambda_test.rb
252
- - test/error_test.rb
253
- - test/recursive_eval_test.rb
254
- - test/define_singleton_method_test.rb
255
- - test/encoding_test/utf8bom_only.rb
256
- - test/encoding_test/utf8unix.rb
257
- - test/encoding_test/eucjp.rb
258
- - test/encoding_test/usascii_with_utf8bom.rb
259
- - test/encoding_test/utf8bom.rb
238
+ - test/to_ast/to_ast_feature_test.rb
260
239
  - test/encoding_test/utf8mac_alt.rb
261
- - test/encoding_test/default.rb
262
240
  - test/encoding_test/usascii.rb
263
- - test/encoding_test/cp932.rb
264
- - test/encoding_test/koi8_shebang.rb
265
- - test/encoding_test/utf8.rb
241
+ - test/encoding_test/default.rb
242
+ - test/encoding_test/utf8dos.rb
243
+ - test/encoding_test/eucjp.rb
266
244
  - test/encoding_test/bad.rb
267
- - test/encoding_test/utf8mac.rb
268
245
  - test/encoding_test/koi8_with_utf8bom.rb
269
- - test/encoding_test/utf8dos.rb
246
+ - test/encoding_test/utf8bom_only.rb
247
+ - test/encoding_test/koi8_shebang.rb
248
+ - test/encoding_test/utf8unix.rb
249
+ - test/encoding_test/cp932.rb
250
+ - test/encoding_test/utf8.rb
270
251
  - test/encoding_test/koi8.rb
252
+ - test/encoding_test/utf8bom.rb
253
+ - test/encoding_test/usascii_with_utf8bom.rb
254
+ - test/encoding_test/utf8mac.rb
255
+ - test/encoding_test.rb
256
+ - test/alias_test.rb
257
+ - test/rubygems_test.rb
258
+ - test/define_singleton_method_test.rb
259
+ - test/covert_define_method_test.rb
260
+ - test/ast_load/ast_load_test.rb
261
+ - test/backtrace_test.rb
271
262
  - test/load_test.rb
263
+ - test/singleton_test.rb
264
+ - test/recursive_eval_test.rb
265
+ - test/base/reload_test.rb
266
+ - test/base/noninvasive_test.rb
267
+ - test/define_method_test.rb
268
+ - test/eval_test.rb
269
+ - test/attr_test.rb
270
+ - test/irb_test.rb
271
+ - test/load_path_test.rb
272
272
  - test/nested_test.rb
273
+ - test/def_test.rb
274
+ - test/thread_test.rb
275
+ - test/flush_cache_test.rb
276
+ - test/error_test.rb
277
+ - test/ast_eval/ast_eval_test.rb
273
278
  - test/main.rb
274
- - test/define_method_test.rb
275
- - test/backtrace_test.rb
276
- - test/base/noninvasive_test.rb
277
- - test/base/reload_test.rb
278
- - test/encoding_test.rb
279
- has_rdoc: