Skip to content

Commit

Permalink
Update to support pry 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
seikichi committed Mar 25, 2020
1 parent 7d9dcf1 commit 6a1ab01
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pry-inline.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.require_paths = ['lib']

spec.add_dependency 'pry', '> 0.10.0', '<= 0.12.2'
spec.add_dependency 'pry', '> 0.10.0', '<= 0.13'
spec.add_dependency 'unicode', '~> 0.4.4'
spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 12.3'
Expand Down
60 changes: 40 additions & 20 deletions test/test_inline.rb
Expand Up @@ -14,13 +14,14 @@ def greet
end

actual = output_of_whereami { greet }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def greet
message = 'Hello, world!' # message: "Hello, world!"
@binding = binding
message
end
EOF
assert { actual.end_with?(expected) }
end

test 'multiple assignment of local variables' do
Expand All @@ -30,12 +31,13 @@ def multiple_assign
end

actual = output_of_whereami { multiple_assign }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def multiple_assign
x, y = 10, 20 # x: 10, y: 20
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'operator assign of local variables' do
Expand All @@ -48,7 +50,7 @@ def opassign
end

actual = output_of_whereami { opassign }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def opassign
x, y, z = 1, 2, false
x += 10 # x: 11
Expand All @@ -57,6 +59,7 @@ def opassign
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'parameters of block' do
Expand All @@ -67,13 +70,14 @@ def block_parameters
end

actual = output_of_whereami { block_parameters }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def block_parameters
(1..10).each do |i| # i: 5
@binding = binding if i == 5
end
end
EOF
assert { actual.end_with?(expected) }
end

test 'assignment of instance variable' do
Expand All @@ -84,13 +88,14 @@ def assign_instance_variable
end

actual = output_of_whereami { assign_instance_variable }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def assign_instance_variable
@x = [1, 2, 3] # @x: [1, 2, 3]
@binding = binding
@y = [4, 5, 6]
end
EOF
assert { actual.end_with?(expected) }
end

test 'assignment of class variable' do
Expand All @@ -100,12 +105,13 @@ def assign_class_variable
end

actual = output_of_whereami { assign_class_variable }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def assign_class_variable
@@var = { x: 10 } # @@var: {:x=>10}
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'assignment of global variable' do
Expand All @@ -115,12 +121,13 @@ def assign_class_variable
end

actual = output_of_whereami { assign_class_variable }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def assign_class_variable
$var = { x: 10 } # $var: {:x=>10}
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'assignment of var args' do
Expand All @@ -129,11 +136,12 @@ def use_var_args(*args)
end

actual = output_of_whereami { use_var_args(1, 2, 3) }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def use_var_args(*args) # args: [1, 2, 3]
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'assignment after binding.pry' do
Expand All @@ -144,13 +152,14 @@ def assignment_after_binding
end

actual = output_of_whereami { assignment_after_binding }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def assignment_after_binding
x = 10 # x: 10
@binding = binding
y = 10
end
EOF
assert { actual.end_with?(expected) }
end

test 'keyword arguments' do
Expand All @@ -159,11 +168,12 @@ def keyword_arguments(a: 10, b: 20)
end

actual = output_of_whereami { keyword_arguments(b: 100) }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def keyword_arguments(a: 10, b: 20) # a: 10, b: 100
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'combinations of arguments' do
Expand All @@ -176,11 +186,12 @@ def f(a, m = 1, *rest, x, k: 1, **kwrest) # a: "a", m: 2, rest: ["f", "b"], x: "
end
EOF
actual = output_of_whereami { f('a', 2, 'f', 'b', 'x', k: 42, u: 'u') }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def f(a, m = 1, *rest, x, k: 1, **kwrest) # a: "a", m: 2, rest: ["f", "b"], x: "x", k: 42, kwrest: {:u=>"u"}
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'too long function' do
Expand Down Expand Up @@ -217,7 +228,7 @@ def too_long_function
i += 1
end
actual = output_of_whereami { too_long_function }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def too_long_function
i = 0
i += 1
Expand All @@ -230,6 +241,7 @@ def too_long_function
i += 1
i += 1
EOF
assert { actual.end_with?(expected) }
end

test 'line number' do
Expand All @@ -241,13 +253,14 @@ def greet_with_line_number

actual = output_of_whereami(with_line_number: true) { greet_with_line_number }
lineno = method(:greet_with_line_number).source_location[1]
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
#{lineno + 0}: def greet_with_line_number
#{lineno + 1}: message = 'Hello, world!' # message: "Hello, world!"
=> #{lineno + 2}: @binding = binding
#{lineno + 3}: message
#{lineno + 4}: end
EOF
assert { actual.end_with?(expected) }
end

test 'too long debug info' do
Expand All @@ -258,12 +271,13 @@ def too_long_debug_info

actual = output_of_whereami(terminal_width: 40) { too_long_debug_info }
# <= 40
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def too_long_debug_info
message = '0' * 100 # message: "000000
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'too long debug info and line number' do
Expand All @@ -276,12 +290,13 @@ def too_long_debug_info_and_line_number
too_long_debug_info_and_line_number
end
lineno = method(:too_long_debug_info_and_line_number).source_location[1]
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
#{lineno + 0}: def too_long_debug_info_and_line_number
#{lineno + 1}: message = '0' * 100 # message
=> #{lineno + 2}: @binding = binding
#{lineno + 3}: end
EOF
assert { actual.end_with?(expected) }
end

test 'too long debug info including wide characters' do
Expand All @@ -294,12 +309,13 @@ def too_long_debug_info_including_wide_characters
too_long_debug_info_including_wide_characters
end
# <= 40
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def too_long_debug_info_including_wide_characters
a = 'あa' * 100 # a: "あaあaあaあaあa
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'too long debug info including ambigous characters' do
Expand All @@ -312,12 +328,13 @@ def too_long_debug_info_including_wide_characters
too_long_debug_info_including_wide_characters
end
# <= 41
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def too_long_debug_info_including_wide_characters
a = 'あa☆' * 100 # a: "あa☆あa☆あa☆
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'min debug info width option' do
Expand All @@ -330,12 +347,13 @@ def min_debug_info
min_debug_info
end
# <= 40
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def min_debug_info
message = '0' * 100 # message: "0000000000000000000000000000000000000000000000
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

test 'first statement' do
Expand All @@ -352,7 +370,7 @@ def foo(x)
end

actual = output_of_whereami { foo(3) }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def foo(x)
x += 9 # x: 12
@binding = binding
Expand All @@ -361,6 +379,7 @@ def foo(x)
x
end
EOF
assert { actual.end_with?(expected) }
end

test 'rescue variable' do
Expand All @@ -371,13 +390,14 @@ def cause_error
end

actual = output_of_whereami { cause_error }
assert_equal <<EOF.chomp, actual
expected = <<EOF.chomp
def cause_error
raise 'Hello, world!'
rescue => e # e: #<RuntimeError: Hello, world!>
@binding = binding
end
EOF
assert { actual.end_with?(expected) }
end

private
Expand Down

0 comments on commit 6a1ab01

Please sign in to comment.