pry 0.9.10pre1-i386-mingw32 → 0.9.11-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG +63 -2
- data/CONTRIBUTORS +43 -25
- data/Gemfile +7 -0
- data/Guardfile +62 -0
- data/README.markdown +4 -4
- data/Rakefile +34 -35
- data/lib/pry.rb +107 -54
- data/lib/pry/cli.rb +34 -11
- data/lib/pry/code.rb +165 -182
- data/lib/pry/code/code_range.rb +70 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +153 -0
- data/lib/pry/command.rb +160 -22
- data/lib/pry/command_set.rb +37 -26
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +53 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +78 -0
- data/lib/pry/commands/cat/file_formatter.rb +84 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +30 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/deprecated_commands.rb +2 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +206 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
- data/lib/pry/commands/edit/method_patcher.rb +122 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +24 -0
- data/lib/pry/commands/find_method.rb +199 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +29 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +95 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +161 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +51 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/ls.rb +339 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +69 -0
- data/lib/pry/commands/pry_backtrace.rb +26 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +39 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +56 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +43 -0
- data/lib/pry/commands/shell_mode.rb +27 -0
- data/lib/pry/commands/show_doc.rb +78 -0
- data/lib/pry/commands/show_info.rb +139 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +37 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +20 -0
- data/lib/pry/commands/whereami.rb +114 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/completion.rb +120 -46
- data/lib/pry/config.rb +11 -0
- data/lib/pry/core_extensions.rb +30 -19
- data/lib/pry/editor.rb +129 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +89 -119
- data/lib/pry/helpers/command_helpers.rb +7 -122
- data/lib/pry/helpers/table.rb +100 -0
- data/lib/pry/helpers/text.rb +4 -4
- data/lib/pry/history_array.rb +5 -0
- data/lib/pry/hooks.rb +1 -3
- data/lib/pry/indent.rb +104 -30
- data/lib/pry/method.rb +66 -22
- data/lib/pry/module_candidate.rb +26 -15
- data/lib/pry/pager.rb +70 -0
- data/lib/pry/plugins.rb +1 -2
- data/lib/pry/pry_class.rb +63 -22
- data/lib/pry/pry_instance.rb +58 -37
- data/lib/pry/rubygem.rb +74 -0
- data/lib/pry/terminal_info.rb +43 -0
- data/lib/pry/test/helper.rb +185 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +58 -24
- data/pry.gemspec +21 -37
- data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
- data/spec/code_object_spec.rb +277 -0
- data/{test/test_code.rb → spec/code_spec.rb} +19 -1
- data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
- data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
- data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
- data/{test/test_command.rb → spec/command_spec.rb} +250 -149
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +19 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +727 -0
- data/spec/commands/exit_all_spec.rb +34 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +34 -0
- data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +75 -0
- data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
- data/spec/commands/hist_spec.rb +181 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +177 -0
- data/spec/commands/play_spec.rb +140 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +378 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +597 -0
- data/spec/commands/whereami_spec.rb +154 -0
- data/spec/completion_spec.rb +233 -0
- data/spec/control_d_handler_spec.rb +58 -0
- data/spec/editor_spec.rb +79 -0
- data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
- data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
- data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
- data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/{test → spec/fixtures}/testrc +0 -0
- data/{test → spec/fixtures}/testrcbad +0 -0
- data/spec/helper.rb +34 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +43 -0
- data/spec/helpers/table_spec.rb +83 -0
- data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
- data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
- data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
- data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
- data/{test/test_method.rb → spec/method_spec.rb} +65 -1
- data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
- data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
- data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
- data/spec/pry_output_spec.rb +95 -0
- data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
- data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
- data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
- data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
- metadata +239 -115
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/test/helper.rb +0 -223
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/test_cd.rb +0 -321
- data/test/test_default_commands/test_context.rb +0 -288
- data/test/test_default_commands/test_documentation.rb +0 -315
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_pry_output.rb +0 -41
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# []
|
2
|
+
class A # ["class A"]
|
3
|
+
def a; end # ["class A"]
|
4
|
+
class B; def b; end; end # ["class A", "class B"]
|
5
|
+
end # []
|
6
|
+
# []
|
7
|
+
class << A # ["class << A"]
|
8
|
+
class B # ["class << A", "class B"]
|
9
|
+
def c; end # ["class << A", "class B"]
|
10
|
+
end # ["class << A"]
|
11
|
+
# ["class << A"]
|
12
|
+
module F::B # ["class << A", "module F::B"]
|
13
|
+
def foo; end # ["class << A", "module F::B"]
|
14
|
+
end # ["class << A"]
|
15
|
+
end # []
|
16
|
+
# []
|
17
|
+
module (:symbol.class)::Exciting #
|
18
|
+
def foo; end #
|
19
|
+
class B #
|
20
|
+
def goo; end #
|
21
|
+
end #
|
22
|
+
end # []
|
23
|
+
# []
|
24
|
+
module C # ["module C"]
|
25
|
+
class D # ["module C", "class D"]
|
26
|
+
def guh; foo.end; end # ["module C", "class D"]
|
27
|
+
end # ["module C"]
|
28
|
+
def bar; :end; end # ["module C"]
|
29
|
+
class << new.bar; end # ["module C"]
|
30
|
+
class << new.bar; def f; end; end #
|
31
|
+
# ["module C"]
|
32
|
+
class << self; def mug; end; end # ["module C", "class << self"]
|
33
|
+
end # []
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# used by test_show_source.rb and test_documentation.rb
|
2
|
+
class TestClassForShowSource
|
3
|
+
def alpha
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class TestClassForShowSourceClassEval
|
8
|
+
def alpha
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestClassForShowSourceInstanceEval
|
13
|
+
def alpha
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
File without changes
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
unless Object.const_defined? 'Pry'
|
2
|
+
$:.unshift File.expand_path '../../lib', __FILE__
|
3
|
+
require 'pry'
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'mocha/api'
|
7
|
+
|
8
|
+
require 'pry/test/helper'
|
9
|
+
require 'helpers/bacon'
|
10
|
+
require 'helpers/mock_pry'
|
11
|
+
|
12
|
+
class Module
|
13
|
+
public :remove_const
|
14
|
+
public :remove_method
|
15
|
+
end
|
16
|
+
|
17
|
+
# turn warnings off (esp for Pry::Hooks which will generate warnings
|
18
|
+
# in tests)
|
19
|
+
$VERBOSE = nil
|
20
|
+
|
21
|
+
Pad = OpenStruct.new
|
22
|
+
def Pad.clear
|
23
|
+
@table = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# to help with tracking down bugs that cause an infinite loop in the test suite
|
27
|
+
if ENV["SET_TRACE_FUNC"]
|
28
|
+
require 'set_trace' if Pry::Helpers::BaseHelpers.rbx?
|
29
|
+
set_trace_func proc { |event, file, line, id, binding, classname|
|
30
|
+
STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Slop v#{Slop::VERSION}"
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Colorize output (based on greeneggs (c) 2009 Michael Fleet)
|
2
|
+
# TODO: Make own gem (assigned to rking)
|
3
|
+
module Bacon
|
4
|
+
class Context
|
5
|
+
include PryTestHelpers
|
6
|
+
end
|
7
|
+
|
8
|
+
COLORS = {'F' => 31, 'E' => 35, 'M' => 33, '.' => 32}
|
9
|
+
USE_COLOR = !(ENV['NO_PRY_COLORED_BACON'] == 'true') && Pry::Helpers::BaseHelpers.use_ansi_codes?
|
10
|
+
|
11
|
+
module TestUnitOutput
|
12
|
+
def handle_requirement(description)
|
13
|
+
error = yield
|
14
|
+
|
15
|
+
if error.empty?
|
16
|
+
print colorize_string('.')
|
17
|
+
else
|
18
|
+
print colorize_string(error[0..0])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle_summary
|
23
|
+
puts
|
24
|
+
puts ErrorLog if Backtraces
|
25
|
+
|
26
|
+
out = "%d tests, %d assertions, %d failures, %d errors" %
|
27
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
28
|
+
|
29
|
+
if Counter.values_at(:failed, :errors).inject(:+) > 0
|
30
|
+
puts colorize_string(out, 'F')
|
31
|
+
else
|
32
|
+
puts colorize_string(out, '.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def colorize_string(text, color = nil)
|
37
|
+
if USE_COLOR
|
38
|
+
"\e[#{ COLORS[color || text] }m#{ text }\e[0m"
|
39
|
+
else
|
40
|
+
text
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Reset top-level binding at the beginning of each test case.
|
47
|
+
module Bacon
|
48
|
+
class Context
|
49
|
+
def it_with_reset_binding(description, &block)
|
50
|
+
Pry.toplevel_binding = nil
|
51
|
+
it_without_reset_binding(description, &block)
|
52
|
+
end
|
53
|
+
alias it_without_reset_binding it
|
54
|
+
alias it it_with_reset_binding
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Support mocha
|
59
|
+
# mocha-on-bacon (c) Copyright (C) 2011, Eloy Durán <eloy.de.enige@gmail.com>
|
60
|
+
module Bacon
|
61
|
+
module MochaRequirementsCounter
|
62
|
+
def self.increment
|
63
|
+
Counter[:requirements] += 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Context
|
68
|
+
include Mocha::API
|
69
|
+
|
70
|
+
def it_with_mocha(description, &block)
|
71
|
+
it_without_mocha(description) do
|
72
|
+
begin
|
73
|
+
mocha_setup
|
74
|
+
block.call
|
75
|
+
mocha_verify(MochaRequirementsCounter)
|
76
|
+
rescue Mocha::ExpectationError => e
|
77
|
+
raise Error.new(:failed, e.message)
|
78
|
+
ensure
|
79
|
+
mocha_teardown
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
alias it_without_mocha it
|
84
|
+
alias it it_with_mocha
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
def mock_pry(*args)
|
2
|
+
args.flatten!
|
3
|
+
binding = args.first.is_a?(Binding) ? args.shift : binding()
|
4
|
+
|
5
|
+
input = InputTester.new(*args)
|
6
|
+
output = StringIO.new
|
7
|
+
|
8
|
+
redirect_pry_io(input, output) do
|
9
|
+
binding.pry
|
10
|
+
end
|
11
|
+
|
12
|
+
output.string
|
13
|
+
end
|
14
|
+
|
15
|
+
# Set I/O streams. Out defaults to an anonymous StringIO.
|
16
|
+
def redirect_pry_io(new_in, new_out = StringIO.new)
|
17
|
+
old_in = Pry.input
|
18
|
+
old_out = Pry.output
|
19
|
+
|
20
|
+
Pry.input = new_in
|
21
|
+
Pry.output = new_out
|
22
|
+
begin
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
Pry.input = old_in
|
26
|
+
Pry.output = old_out
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class InputTester
|
31
|
+
def initialize(*actions)
|
32
|
+
@orig_actions = actions.dup
|
33
|
+
@actions = actions
|
34
|
+
end
|
35
|
+
|
36
|
+
def readline(*)
|
37
|
+
@actions.shift
|
38
|
+
end
|
39
|
+
|
40
|
+
def rewind
|
41
|
+
@actions = @orig_actions.dup
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe 'Formatting Table' do
|
4
|
+
it 'knows about colorized fitting' do
|
5
|
+
t = Pry::Helpers::Table.new %w(hihi), :column_count => 1
|
6
|
+
t.fits_on_line?(4).should == true
|
7
|
+
t.items = []
|
8
|
+
t.fits_on_line?(4).should == true
|
9
|
+
|
10
|
+
t.items = %w(hi hi)
|
11
|
+
t.fits_on_line?(4).should == true
|
12
|
+
t.column_count = 2
|
13
|
+
t.fits_on_line?(4).should == false
|
14
|
+
|
15
|
+
t.items = %w(
|
16
|
+
a ccc
|
17
|
+
bb dddd
|
18
|
+
).sort
|
19
|
+
t.fits_on_line?(8).should == true
|
20
|
+
t.fits_on_line?(7).should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'formatting - should order downward and wrap to columns' do
|
24
|
+
FAKE_COLUMNS = 62
|
25
|
+
def try_round_trip(expected)
|
26
|
+
things = expected.split(/\s+/).sort
|
27
|
+
actual = Pry::Helpers.tablify(things, FAKE_COLUMNS).to_s.strip
|
28
|
+
[expected, actual].each{|e| e.gsub! /\s+$/, ''}
|
29
|
+
if actual != expected
|
30
|
+
bar = '-'*25
|
31
|
+
puts \
|
32
|
+
bar+'expected'+bar,
|
33
|
+
expected,
|
34
|
+
bar+'actual'+bar,
|
35
|
+
actual
|
36
|
+
end
|
37
|
+
actual.should == expected
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should handle a tiny case' do
|
41
|
+
try_round_trip(<<-eot)
|
42
|
+
asdf asfddd fdass
|
43
|
+
eot
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should handle the basic case' do
|
47
|
+
try_round_trip(<<-eot)
|
48
|
+
aadd ddasffssdad sdsaadaasd ssfasaafssd
|
49
|
+
adassdfffaasds f sdsfasddasfds ssssdaa
|
50
|
+
assfsafsfsds fsasa ssdsssafsdasdf
|
51
|
+
eot
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should handle... another basic case' do
|
55
|
+
try_round_trip(<<-EOT)
|
56
|
+
aaad dasaasffaasf fdasfdfss safdfdddsasd
|
57
|
+
aaadfasassdfff ddadadassasdf fddsasadfssdss sasf
|
58
|
+
aaddaafaf dddasaaaaaa fdsasad sddsa
|
59
|
+
aas dfsddffdddsdfd ff sddsfsaa
|
60
|
+
adasadfaaffds dsfafdsfdfssda ffadsfafsaafa ss
|
61
|
+
asddaadaaadfdd dssdss ffssfsfafaadss ssas
|
62
|
+
asdsdaa faadf fsddfff ssdfssff
|
63
|
+
asfadsssaaad fasfaafdssd s
|
64
|
+
EOT
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should handle colors' do
|
68
|
+
try_round_trip(<<-EOT)
|
69
|
+
\e[31maaaaaaaaaa\e[0m \e[31mccccccccccccccccccccccccccccc\e[0m
|
70
|
+
\e[31mbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\e[0m \e[31mddddddddddddd\e[0m
|
71
|
+
EOT
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should handle empty input' do
|
75
|
+
try_round_trip('')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should handle one-token input' do
|
79
|
+
try_round_trip('asdf')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -3,6 +3,7 @@ require 'helper'
|
|
3
3
|
describe Pry::HistoryArray do
|
4
4
|
before do
|
5
5
|
@array = Pry::HistoryArray.new 10
|
6
|
+
@populated = @array.dup << 1 << 2 << 3 << 4
|
6
7
|
end
|
7
8
|
|
8
9
|
it 'should have a maximum size specifed at creation time' do
|
@@ -10,49 +11,40 @@ describe Pry::HistoryArray do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
it 'should be able to be added objects to' do
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@array.to_a.should == [1, 2, 3]
|
14
|
+
@populated.size.should == 4
|
15
|
+
@populated.to_a.should == [1, 2, 3, 4]
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should be able to access single elements' do
|
19
|
-
@
|
20
|
-
@array[2].should == 3
|
19
|
+
@populated[2].should == 3
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'should be able to access negative indices' do
|
24
|
-
@
|
25
|
-
@array[-1].should == 3
|
23
|
+
@populated[-1].should == 4
|
26
24
|
end
|
27
25
|
|
28
26
|
it 'should be able to access ranges' do
|
29
|
-
@
|
30
|
-
@array[1..2].should == [2, 3]
|
27
|
+
@populated[1..2].should == [2, 3]
|
31
28
|
end
|
32
29
|
|
33
30
|
it 'should be able to access ranges starting from a negative index' do
|
34
|
-
@
|
35
|
-
@array[-2..3].should == [3, 4]
|
31
|
+
@populated[-2..3].should == [3, 4]
|
36
32
|
end
|
37
33
|
|
38
34
|
it 'should be able to access ranges ending at a negative index' do
|
39
|
-
@
|
40
|
-
@array[2..-1].should == [3, 4]
|
35
|
+
@populated[2..-1].should == [3, 4]
|
41
36
|
end
|
42
37
|
|
43
38
|
it 'should be able to access ranges using only negative indices' do
|
44
|
-
@
|
45
|
-
@array[-2..-1].should == [3, 4]
|
39
|
+
@populated[-2..-1].should == [3, 4]
|
46
40
|
end
|
47
41
|
|
48
42
|
it 'should be able to use range where end is excluded' do
|
49
|
-
@
|
50
|
-
@array[-2...-1].should == [3]
|
43
|
+
@populated[-2...-1].should == [3]
|
51
44
|
end
|
52
45
|
|
53
46
|
it 'should be able to access slices using a size' do
|
54
|
-
@
|
55
|
-
@array[-3, 2].should == [2, 3]
|
47
|
+
@populated[-3, 2].should == [2, 3]
|
56
48
|
end
|
57
49
|
|
58
50
|
it 'should remove older entries' do
|
@@ -62,4 +54,14 @@ describe Pry::HistoryArray do
|
|
62
54
|
@array[1].should == 1
|
63
55
|
@array[10].should == 10
|
64
56
|
end
|
57
|
+
|
58
|
+
it 'should not be larger than specified maximum size' do
|
59
|
+
12.times { |n| @array << n }
|
60
|
+
@array.entries.compact.size.should == 10
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should pop!' do
|
64
|
+
@populated.pop!
|
65
|
+
@populated.to_a.should == [1, 2, 3]
|
66
|
+
end
|
65
67
|
end
|
File without changes
|
@@ -150,6 +150,11 @@ TXT
|
|
150
150
|
@indent.indent(input).should == output
|
151
151
|
end
|
152
152
|
|
153
|
+
it "should correctly handle while <foo> do" do
|
154
|
+
input = "while 5 do\n5\nend"
|
155
|
+
@indent.indent(input).should == "while 5 do\n 5\nend"
|
156
|
+
end
|
157
|
+
|
153
158
|
it "should ident case statements" do
|
154
159
|
input = <<TXT.strip
|
155
160
|
case foo
|
@@ -274,4 +279,23 @@ OUTPUT
|
|
274
279
|
|
275
280
|
@indent.indent(input).should == output
|
276
281
|
end
|
282
|
+
|
283
|
+
describe "nesting" do
|
284
|
+
test = File.read("spec/fixtures/example_nesting.rb")
|
285
|
+
|
286
|
+
test.lines.each_with_index do |line, i|
|
287
|
+
result = line.split("#").last.strip
|
288
|
+
if result == ""
|
289
|
+
it "should fail to parse nesting on line #{i + 1} of example_nesting.rb" do
|
290
|
+
lambda {
|
291
|
+
Pry::Indent.nesting_at(test, i + 1)
|
292
|
+
}.should.raise(Pry::Indent::UnparseableNestingError)
|
293
|
+
end
|
294
|
+
else
|
295
|
+
it "should parse nesting on line #{i + 1} of example_nesting.rb" do
|
296
|
+
Pry::Indent.nesting_at(test, i + 1).should == eval(result)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
277
301
|
end
|
@@ -72,6 +72,10 @@ describe "Pry#input_stack" do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
if "".respond_to?(:encoding)
|
75
|
+
after do
|
76
|
+
Pry.line_buffer = [""]
|
77
|
+
Pry.current_line = 1
|
78
|
+
end
|
75
79
|
it "should pass strings to Pry in the right encoding" do
|
76
80
|
input1 = "'f。。'.encoding.name" # utf-8, see coding declaration
|
77
81
|
input2 = input1.encode('Shift_JIS')
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'set'
|
2
3
|
|
3
4
|
describe Pry::Method do
|
4
5
|
it "should use String names for compatibility" do
|
@@ -72,6 +73,16 @@ describe Pry::Method do
|
|
72
73
|
meth = Pry::Method.from_str("klass.meth#initialize", Pry.binding_for(binding))
|
73
74
|
meth.name.should == "initialize"
|
74
75
|
end
|
76
|
+
|
77
|
+
it 'should look up methods using instance::bar syntax' do
|
78
|
+
klass = Class.new{ def self.meth; Class.new; end }
|
79
|
+
meth = Pry::Method.from_str("klass::meth", Pry.binding_for(binding))
|
80
|
+
meth.name.should == "meth"
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not raise an exception if receiver does not exist' do
|
84
|
+
lambda { Pry::Method.from_str("random_klass.meth", Pry.binding_for(binding)) }.should.not.raise
|
85
|
+
end
|
75
86
|
end
|
76
87
|
|
77
88
|
describe '.from_binding' do
|
@@ -118,6 +129,17 @@ describe Pry::Method do
|
|
118
129
|
m.source_line.should == b.line
|
119
130
|
m.name.should == "gag"
|
120
131
|
end
|
132
|
+
|
133
|
+
if defined?(BasicObject) && !Pry::Helpers::BaseHelpers.rbx? # rubinius issue 1921
|
134
|
+
it "should find the right method from a BasicObject" do
|
135
|
+
a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end }
|
136
|
+
|
137
|
+
m = Pry::Method.from_binding(a.new.gag)
|
138
|
+
m.owner.should == a
|
139
|
+
m.source_file.should == __FILE__
|
140
|
+
m.source_line.should == a.line
|
141
|
+
end
|
142
|
+
end
|
121
143
|
end
|
122
144
|
|
123
145
|
describe 'super' do
|
@@ -397,5 +419,47 @@ describe Pry::Method do
|
|
397
419
|
meth.send(:method_name_from_first_line, "def obj_name.x").should == "x"
|
398
420
|
end
|
399
421
|
end
|
400
|
-
end
|
401
422
|
|
423
|
+
describe 'method aliases' do
|
424
|
+
before do
|
425
|
+
@class = Class.new {
|
426
|
+
def eat
|
427
|
+
end
|
428
|
+
|
429
|
+
alias fress eat
|
430
|
+
alias_method :omnomnom, :fress
|
431
|
+
|
432
|
+
def eruct
|
433
|
+
end
|
434
|
+
}
|
435
|
+
end
|
436
|
+
|
437
|
+
it 'should be able to find method aliases' do
|
438
|
+
meth = Pry::Method(@class.new.method(:eat))
|
439
|
+
aliases = Set.new(meth.aliases)
|
440
|
+
|
441
|
+
aliases.should == Set.new(["fress", "omnomnom"])
|
442
|
+
end
|
443
|
+
|
444
|
+
it 'should return an empty Array if cannot find aliases' do
|
445
|
+
meth = Pry::Method(@class.new.method(:eruct))
|
446
|
+
meth.aliases.should.be.empty
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'should not include the own name in the list of aliases' do
|
450
|
+
meth = Pry::Method(@class.new.method(:eat))
|
451
|
+
meth.aliases.should.not.include "eat"
|
452
|
+
end
|
453
|
+
|
454
|
+
unless Pry::Helpers::BaseHelpers.mri_18?
|
455
|
+
# Ruby 1.8 doesn't support this feature.
|
456
|
+
it 'should be able to find aliases for methods implemented in C' do
|
457
|
+
meth = Pry::Method(Hash.new.method(:key?))
|
458
|
+
aliases = Set.new(meth.aliases)
|
459
|
+
|
460
|
+
aliases.should == Set.new(["include?", "member?", "has_key?"])
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|
465
|
+
end
|