pry 0.10.pre.1-java → 0.10.0.pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +126 -182
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- 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 +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -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 +23 -0
- data/lib/pry/commands/find_method.rb +193 -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 +32 -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 +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -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 +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -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 +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- 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/completion.rb +0 -221
- data/lib/pry/custom_completions.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/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- 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_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/test/test_indent.rb
DELETED
@@ -1,277 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
# Please keep in mind that any hash signs ("#") in the heredoc strings are
|
4
|
-
# placed on purpose. Without these editors might remove the whitespace on empty
|
5
|
-
# lines.
|
6
|
-
describe Pry::Indent do
|
7
|
-
before do
|
8
|
-
@indent = Pry::Indent.new
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should indent an array' do
|
12
|
-
input = "array = [\n10,\n15\n]"
|
13
|
-
output = "array = [\n 10,\n 15\n]"
|
14
|
-
|
15
|
-
@indent.indent(input).should == output
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should indent a hash' do
|
19
|
-
input = "hash = {\n:name => 'Ruby'\n}"
|
20
|
-
output = "hash = {\n :name => 'Ruby'\n}"
|
21
|
-
|
22
|
-
@indent.indent(input).should == output
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should indent a function' do
|
26
|
-
input = "def\nreturn 10\nend"
|
27
|
-
output = "def\n return 10\nend"
|
28
|
-
|
29
|
-
@indent.indent(input).should == output
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should indent a module and class' do
|
33
|
-
input = "module Foo\n# Hello world\nend"
|
34
|
-
output = "module Foo\n # Hello world\nend"
|
35
|
-
input_class = "class Foo\n# Hello world\nend"
|
36
|
-
output_class = "class Foo\n # Hello world\nend"
|
37
|
-
|
38
|
-
@indent.indent(input).should == output
|
39
|
-
@indent.indent(input_class).should == output_class
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should indent separate lines' do
|
43
|
-
@indent.indent('def foo').should == 'def foo'
|
44
|
-
@indent.indent('return 10').should == ' return 10'
|
45
|
-
@indent.indent('end').should == 'end'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should not indent single line statements' do
|
49
|
-
input = <<TXT.strip
|
50
|
-
def hello; end
|
51
|
-
puts "Hello"
|
52
|
-
TXT
|
53
|
-
|
54
|
-
@indent.indent(input).should == input
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should handle multiple open and closing tokens on a line' do
|
58
|
-
input = <<TXT.strip
|
59
|
-
[10, 15].each do |num|
|
60
|
-
puts num
|
61
|
-
end
|
62
|
-
TXT
|
63
|
-
|
64
|
-
output = <<TXT.strip
|
65
|
-
[10, 15].each do |num|
|
66
|
-
puts num
|
67
|
-
end
|
68
|
-
TXT
|
69
|
-
|
70
|
-
@indent.indent(input).should == output
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should properly indent nested code' do
|
74
|
-
input = <<TXT.strip
|
75
|
-
module A
|
76
|
-
module B
|
77
|
-
class C
|
78
|
-
attr_accessor :test
|
79
|
-
# keep
|
80
|
-
def number
|
81
|
-
return 10
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
TXT
|
87
|
-
|
88
|
-
output = <<TXT.strip
|
89
|
-
module A
|
90
|
-
module B
|
91
|
-
class C
|
92
|
-
attr_accessor :test
|
93
|
-
# keep
|
94
|
-
def number
|
95
|
-
return 10
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
TXT
|
101
|
-
|
102
|
-
@indent.indent(input).should == output
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should indent statements such as if, else, etc' do
|
106
|
-
input = <<TXT.strip
|
107
|
-
if a == 10
|
108
|
-
#
|
109
|
-
elsif a == 15
|
110
|
-
#
|
111
|
-
else
|
112
|
-
#
|
113
|
-
end
|
114
|
-
#
|
115
|
-
while true
|
116
|
-
#
|
117
|
-
end
|
118
|
-
#
|
119
|
-
for num in [10, 15, 20]
|
120
|
-
#
|
121
|
-
end
|
122
|
-
#
|
123
|
-
for num in [10, 15, 20] do
|
124
|
-
#
|
125
|
-
end
|
126
|
-
TXT
|
127
|
-
|
128
|
-
output = <<TXT.strip
|
129
|
-
if a == 10
|
130
|
-
#
|
131
|
-
elsif a == 15
|
132
|
-
#
|
133
|
-
else
|
134
|
-
#
|
135
|
-
end
|
136
|
-
#
|
137
|
-
while true
|
138
|
-
#
|
139
|
-
end
|
140
|
-
#
|
141
|
-
for num in [10, 15, 20]
|
142
|
-
#
|
143
|
-
end
|
144
|
-
#
|
145
|
-
for num in [10, 15, 20] do
|
146
|
-
#
|
147
|
-
end
|
148
|
-
TXT
|
149
|
-
|
150
|
-
@indent.indent(input).should == output
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should ident case statements" do
|
154
|
-
input = <<TXT.strip
|
155
|
-
case foo
|
156
|
-
when 1
|
157
|
-
2
|
158
|
-
when 2
|
159
|
-
if 3
|
160
|
-
4
|
161
|
-
end
|
162
|
-
when 5
|
163
|
-
#
|
164
|
-
else
|
165
|
-
#
|
166
|
-
end
|
167
|
-
TXT
|
168
|
-
|
169
|
-
output = <<TXT.strip
|
170
|
-
case foo
|
171
|
-
when 1
|
172
|
-
2
|
173
|
-
when 2
|
174
|
-
if 3
|
175
|
-
4
|
176
|
-
end
|
177
|
-
when 5
|
178
|
-
#
|
179
|
-
else
|
180
|
-
#
|
181
|
-
end
|
182
|
-
TXT
|
183
|
-
|
184
|
-
@indent.indent(input).should == output
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should indent correctly with nesting" do
|
188
|
-
@indent.indent("[[\n[]]\n]").should == "[[\n []]\n]"
|
189
|
-
@indent.reset.indent("[[\n[]]\n]").should == "[[\n []]\n]"
|
190
|
-
@indent.reset.indent("[[{\n[] =>\n[]}]\n]").should == "[[{\n [] =>\n []}]\n]"
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should not indent single-line ifs" do
|
194
|
-
@indent.indent("foo if bar\n#").should == "foo if bar\n#"
|
195
|
-
@indent.reset.indent("foo() if bar\n#").should == "foo() if bar\n#"
|
196
|
-
@indent.reset.indent("foo 'hi' if bar\n#").should == "foo 'hi' if bar\n#"
|
197
|
-
@indent.reset.indent("foo 1 while bar\n#").should == "foo 1 while bar\n#"
|
198
|
-
@indent.reset.indent("super if true\n#").should == "super if true\n#"
|
199
|
-
@indent.reset.indent("true if false\n#").should == "true if false\n#"
|
200
|
-
@indent.reset.indent("String if false\n#").should == "String if false\n#"
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should indent cunningly disguised ifs" do
|
204
|
-
@indent.indent("{1 => if bar\n#").should == "{1 => if bar\n #"
|
205
|
-
@indent.reset.indent("foo(if bar\n#").should == "foo(if bar\n #"
|
206
|
-
@indent.reset.indent("bar(baz, if bar\n#").should == "bar(baz, if bar\n #"
|
207
|
-
@indent.reset.indent("[if bar\n#").should == "[if bar\n #"
|
208
|
-
@indent.reset.indent("true; while bar\n#").should == "true; while bar\n #"
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should differentiate single/multi-line unless" do
|
212
|
-
@indent.indent("foo unless bar\nunless foo\nbar\nend").should == "foo unless bar\nunless foo\n bar\nend"
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should not indent single/multi-line until" do
|
216
|
-
@indent.indent("%w{baz} until bar\nuntil foo\nbar\nend").should == "%w{baz} until bar\nuntil foo\n bar\nend"
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should indent begin rescue end" do
|
220
|
-
input = <<INPUT.strip
|
221
|
-
begin
|
222
|
-
doo :something => :wrong
|
223
|
-
rescue => e
|
224
|
-
doit :right
|
225
|
-
end
|
226
|
-
INPUT
|
227
|
-
output = <<OUTPUT.strip
|
228
|
-
begin
|
229
|
-
doo :something => :wrong
|
230
|
-
rescue => e
|
231
|
-
doit :right
|
232
|
-
end
|
233
|
-
OUTPUT
|
234
|
-
|
235
|
-
@indent.indent(input).should == output
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should not indent inside strings" do
|
239
|
-
@indent.indent(%(def a\n"foo\nbar"\n end)).should == %(def a\n "foo\nbar"\nend)
|
240
|
-
@indent.indent(%(def a\nputs %w(foo\nbar), 'foo\nbar'\n end)).should == %(def a\n puts %w(foo\nbar), 'foo\nbar'\nend)
|
241
|
-
end
|
242
|
-
|
243
|
-
it "should not indent inside HEREDOCs" do
|
244
|
-
@indent.indent(%(def a\nputs <<FOO\n bar\nFOO\nbaz\nend)).should == %(def a\n puts <<FOO\n bar\nFOO\n baz\nend)
|
245
|
-
@indent.indent(%(def a\nputs <<-'^^'\n bar\n\t^^\nbaz\nend)).should == %(def a\n puts <<-'^^'\n bar\n\t^^\n baz\nend)
|
246
|
-
end
|
247
|
-
|
248
|
-
it "should not indent nested HEREDOCs" do
|
249
|
-
input = <<INPUT.strip
|
250
|
-
def a
|
251
|
-
puts <<FOO, <<-BAR, "baz", <<-':p'
|
252
|
-
foo
|
253
|
-
FOO
|
254
|
-
bar
|
255
|
-
BAR
|
256
|
-
tongue
|
257
|
-
:p
|
258
|
-
puts :p
|
259
|
-
end
|
260
|
-
INPUT
|
261
|
-
|
262
|
-
output = <<OUTPUT.strip
|
263
|
-
def a
|
264
|
-
puts <<FOO, <<-BAR, "baz", <<-':p'
|
265
|
-
foo
|
266
|
-
FOO
|
267
|
-
bar
|
268
|
-
BAR
|
269
|
-
tongue
|
270
|
-
:p
|
271
|
-
puts :p
|
272
|
-
end
|
273
|
-
OUTPUT
|
274
|
-
|
275
|
-
@indent.indent(input).should == output
|
276
|
-
end
|
277
|
-
end
|
data/test/test_input_stack.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
describe "Pry#input_stack" do
|
5
|
-
before do
|
6
|
-
@str_output = StringIO.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should accept :input_stack as a config option' do
|
10
|
-
stack = [StringIO.new("test")]
|
11
|
-
Pry.new(:input_stack => stack).input_stack.should == stack
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should use defaults from Pry.config' do
|
15
|
-
Pry.config.input_stack = [StringIO.new("exit")]
|
16
|
-
Pry.new.input_stack.should == Pry.config.input_stack
|
17
|
-
Pry.config.input_stack = []
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should read from all input objects on stack and exit session (usingn repl)' do
|
21
|
-
stack = [b = StringIO.new(":cloister\nexit\n"), c = StringIO.new(":baron\n")]
|
22
|
-
instance = Pry.new(:input => StringIO.new(":alex\n"),
|
23
|
-
:output => @str_output,
|
24
|
-
:input_stack => stack)
|
25
|
-
|
26
|
-
instance.repl
|
27
|
-
@str_output.string.should =~ /:alex/
|
28
|
-
@str_output.string.should =~ /:baron/
|
29
|
-
@str_output.string.should =~ /:cloister/
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'input objects should be popped off stack as they are used up' do
|
33
|
-
stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
|
34
|
-
instance = Pry.new(:input => StringIO.new(":alex\n"),
|
35
|
-
:output => @str_output,
|
36
|
-
:input_stack => stack)
|
37
|
-
|
38
|
-
stack.size.should == 2
|
39
|
-
|
40
|
-
instance.rep
|
41
|
-
@str_output.string.should =~ /:alex/
|
42
|
-
instance.rep
|
43
|
-
@str_output.string.should =~ /:baron/
|
44
|
-
stack.size.should == 1
|
45
|
-
instance.rep
|
46
|
-
@str_output.string.should =~ /:cloister/
|
47
|
-
stack.size.should == 0
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should revert to Pry.config.input when it runs out of input objects in input_stack' do
|
51
|
-
redirect_pry_io(StringIO.new(":rimbaud\nexit\n"), StringIO.new) do
|
52
|
-
stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
|
53
|
-
instance = Pry.new(:input => StringIO.new(":alex\n"),
|
54
|
-
:output => @str_output,
|
55
|
-
:input_stack => stack)
|
56
|
-
|
57
|
-
instance.repl
|
58
|
-
@str_output.string.should =~ /:alex/
|
59
|
-
@str_output.string.should =~ /:baron/
|
60
|
-
@str_output.string.should =~ /:cloister/
|
61
|
-
@str_output.string.should =~ /:rimbaud/
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should display error and throw(:breakout) if at end of input after using up input_stack objects' do
|
66
|
-
catch(:breakout) do
|
67
|
-
redirect_pry_io(StringIO.new(":rimbaud\n"), @str_output) do
|
68
|
-
Pry.new(:input_stack => [StringIO.new(":a\n"), StringIO.new(":b\n")]).repl
|
69
|
-
end
|
70
|
-
end
|
71
|
-
@str_output.string.should =~ /Error: Pry ran out of things to read/
|
72
|
-
end
|
73
|
-
|
74
|
-
if "".respond_to?(:encoding)
|
75
|
-
it "should pass strings to Pry in the right encoding" do
|
76
|
-
input1 = "'f。。'.encoding.name" # utf-8, see coding declaration
|
77
|
-
input2 = input1.encode('Shift_JIS')
|
78
|
-
|
79
|
-
mock_pry(input1, input2).should == %{=> "UTF-8"\n=> "Shift_JIS"\n\n}
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should be able to use unicode regexes on a UTF-8 terminal" do
|
83
|
-
mock_pry('":-Þ" =~ /þ/i').should == %{=> 2\n\n}
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/test/test_method.rb
DELETED
@@ -1,401 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Pry::Method do
|
4
|
-
it "should use String names for compatibility" do
|
5
|
-
klass = Class.new { def hello; end }
|
6
|
-
Pry::Method.new(klass.instance_method(:hello)).name.should == "hello"
|
7
|
-
end
|
8
|
-
|
9
|
-
describe ".from_str" do
|
10
|
-
it 'should look up instance methods if no methods available and no options provided' do
|
11
|
-
klass = Class.new { def hello; end }
|
12
|
-
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass))
|
13
|
-
meth.should == klass.instance_method(:hello)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should look up methods if no instance methods available and no options provided' do
|
17
|
-
klass = Class.new { def self.hello; end }
|
18
|
-
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass))
|
19
|
-
meth.should == klass.method(:hello)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should look up instance methods first even if methods available and no options provided' do
|
23
|
-
klass = Class.new { def hello; end; def self.hello; end }
|
24
|
-
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass))
|
25
|
-
meth.should == klass.instance_method(:hello)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should look up instance methods if "instance-methods" option provided' do
|
29
|
-
klass = Class.new { def hello; end; def self.hello; end }
|
30
|
-
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {"instance-methods" => true})
|
31
|
-
meth.should == klass.instance_method(:hello)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should look up methods if :methods option provided' do
|
35
|
-
klass = Class.new { def hello; end; def self.hello; end }
|
36
|
-
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {:methods => true})
|
37
|
-
meth.should == klass.method(:hello)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should look up instance methods using the Class#method syntax' do
|
41
|
-
klass = Class.new { def hello; end; def self.hello; end }
|
42
|
-
meth = Pry::Method.from_str("klass#hello", Pry.binding_for(binding))
|
43
|
-
meth.should == klass.instance_method(:hello)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should look up methods using the object.method syntax' do
|
47
|
-
klass = Class.new { def hello; end; def self.hello; end }
|
48
|
-
meth = Pry::Method.from_str("klass.hello", Pry.binding_for(binding))
|
49
|
-
meth.should == klass.method(:hello)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should NOT look up instance methods using the Class#method syntax if no instance methods defined' do
|
53
|
-
klass = Class.new { def self.hello; end }
|
54
|
-
meth = Pry::Method.from_str("klass#hello", Pry.binding_for(binding))
|
55
|
-
meth.should == nil
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should NOT look up methods using the object.method syntax if no methods defined' do
|
59
|
-
klass = Class.new { def hello; end }
|
60
|
-
meth = Pry::Method.from_str("klass.hello", Pry.binding_for(binding))
|
61
|
-
meth.should == nil
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should look up methods using klass.new.method syntax' do
|
65
|
-
klass = Class.new { def hello; :hello; end }
|
66
|
-
meth = Pry::Method.from_str("klass.new.hello", Pry.binding_for(binding))
|
67
|
-
meth.name.should == "hello"
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should look up instance methods using klass.meth#method syntax' do
|
71
|
-
klass = Class.new { def self.meth; Class.new; end }
|
72
|
-
meth = Pry::Method.from_str("klass.meth#initialize", Pry.binding_for(binding))
|
73
|
-
meth.name.should == "initialize"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '.from_binding' do
|
78
|
-
it 'should be able to pick a method out of a binding' do
|
79
|
-
Pry::Method.from_binding(Class.new{ def self.foo; binding; end }.foo).name.should == "foo"
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should NOT find a method from the toplevel binding' do
|
83
|
-
Pry::Method.from_binding(TOPLEVEL_BINDING).should == nil
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should find methods that have been undef'd" do
|
87
|
-
m = Pry::Method.from_binding(Class.new do
|
88
|
-
def self.bar
|
89
|
-
class << self; undef bar; end
|
90
|
-
binding
|
91
|
-
end
|
92
|
-
end.bar)
|
93
|
-
m.name.should == "bar"
|
94
|
-
end
|
95
|
-
|
96
|
-
# Our source_location trick doesn't work, due to https://github.com/rubinius/rubinius/issues/953
|
97
|
-
unless Pry::Helpers::BaseHelpers.rbx?
|
98
|
-
it 'should find the super method correctly' do
|
99
|
-
a = Class.new{ def gag; binding; end; def self.line; __LINE__; end }
|
100
|
-
b = Class.new(a){ def gag; super; end }
|
101
|
-
|
102
|
-
g = b.new.gag
|
103
|
-
m = Pry::Method.from_binding(g)
|
104
|
-
|
105
|
-
m.owner.should == a
|
106
|
-
m.source_line.should == a.line
|
107
|
-
m.name.should == "gag"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'should find the right method if a super method exists' do
|
112
|
-
a = Class.new{ def gag; binding; end; }
|
113
|
-
b = Class.new(a){ def gag; super; binding; end; def self.line; __LINE__; end }
|
114
|
-
|
115
|
-
m = Pry::Method.from_binding(b.new.gag)
|
116
|
-
|
117
|
-
m.owner.should == b
|
118
|
-
m.source_line.should == b.line
|
119
|
-
m.name.should == "gag"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
describe 'super' do
|
124
|
-
it 'should be able to find the super method on a bound method' do
|
125
|
-
a = Class.new{ def rar; 4; end }
|
126
|
-
b = Class.new(a){ def rar; super; end }
|
127
|
-
|
128
|
-
obj = b.new
|
129
|
-
|
130
|
-
zuper = Pry::Method(obj.method(:rar)).super
|
131
|
-
zuper.owner.should == a
|
132
|
-
zuper.receiver.should == obj
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'should be able to find the super method of an unbound method' do
|
136
|
-
a = Class.new{ def rar; 4; end }
|
137
|
-
b = Class.new(a){ def rar; super; end }
|
138
|
-
|
139
|
-
zuper = Pry::Method(b.instance_method(:rar)).super
|
140
|
-
zuper.owner.should == a
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should return nil if no super method exists' do
|
144
|
-
a = Class.new{ def rar; super; end }
|
145
|
-
|
146
|
-
Pry::Method(a.instance_method(:rar)).super.should == nil
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should be able to find super methods defined on modules' do
|
150
|
-
m = Module.new{ def rar; 4; end }
|
151
|
-
a = Class.new{ def rar; super; end; include m }
|
152
|
-
|
153
|
-
zuper = Pry::Method(a.new.method(:rar)).super
|
154
|
-
zuper.owner.should == m
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should be able to find super methods defined on super-classes when there are modules in the way' do
|
158
|
-
a = Class.new{ def rar; 4; end }
|
159
|
-
m = Module.new{ def mooo; 4; end }
|
160
|
-
b = Class.new(a){ def rar; super; end; include m }
|
161
|
-
|
162
|
-
zuper = Pry::Method(b.new.method(:rar)).super
|
163
|
-
zuper.owner.should == a
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should be able to jump up multiple levels of bound method, even through modules' do
|
167
|
-
a = Class.new{ def rar; 4; end }
|
168
|
-
m = Module.new{ def rar; 4; end }
|
169
|
-
b = Class.new(a){ def rar; super; end; include m }
|
170
|
-
|
171
|
-
zuper = Pry::Method(b.new.method(:rar)).super
|
172
|
-
zuper.owner.should == m
|
173
|
-
zuper.super.owner.should == a
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe 'all_from_class' do
|
178
|
-
def should_find_method(name)
|
179
|
-
Pry::Method.all_from_class(@class).map(&:name).should.include(name)
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'should be able to find public instance methods defined in a class' do
|
183
|
-
@class = Class.new{ def meth; 1; end }
|
184
|
-
should_find_method('meth')
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'should be able to find private and protected instance methods defined in a class' do
|
188
|
-
@class = Class.new { protected; def prot; 1; end; private; def priv; 1; end }
|
189
|
-
should_find_method('priv')
|
190
|
-
should_find_method('prot')
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should find methods all the way up to Kernel' do
|
194
|
-
@class = Class.new
|
195
|
-
should_find_method('exit!')
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should be able to find instance methods defined in a super-class' do
|
199
|
-
@class = Class.new(Class.new{ def meth; 1; end }) {}
|
200
|
-
should_find_method('meth')
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'should be able to find instance methods defined in modules included into this class' do
|
204
|
-
@class = Class.new{ include Module.new{ def meth; 1; end; } }
|
205
|
-
should_find_method('meth')
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'should be able to find instance methods defined in modules included into super-classes' do
|
209
|
-
@class = Class.new(Class.new{ include Module.new{ def meth; 1; end; } })
|
210
|
-
should_find_method('meth')
|
211
|
-
end
|
212
|
-
|
213
|
-
it 'should attribute overridden methods to the sub-class' do
|
214
|
-
@class = Class.new(Class.new{ include Module.new{ def meth; 1; end; } }) { def meth; 2; end }
|
215
|
-
Pry::Method.all_from_class(@class).detect{ |x| x.name == 'meth' }.owner.should == @class
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'should be able to find methods defined on a singleton class' do
|
219
|
-
@class = (class << Object.new; def meth; 1; end; self; end)
|
220
|
-
should_find_method('meth')
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'should be able to find methods on super-classes when given a singleton class' do
|
224
|
-
@class = (class << Class.new{ def meth; 1; end}.new; self; end)
|
225
|
-
should_find_method('meth')
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe 'all_from_obj' do
|
230
|
-
describe 'on normal objects' do
|
231
|
-
def should_find_method(name)
|
232
|
-
Pry::Method.all_from_obj(@obj).map(&:name).should.include(name)
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should find methods defined in the object's class" do
|
236
|
-
@obj = Class.new{ def meth; 1; end }.new
|
237
|
-
should_find_method('meth')
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should find methods defined in modules included into the object's class" do
|
241
|
-
@obj = Class.new{ include Module.new{ def meth; 1; end } }.new
|
242
|
-
should_find_method('meth')
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should find methods defined in the object's singleton class" do
|
246
|
-
@obj = Object.new
|
247
|
-
class << @obj; def meth; 1; end; end
|
248
|
-
should_find_method('meth')
|
249
|
-
end
|
250
|
-
|
251
|
-
it "should find methods in modules included into the object's singleton class" do
|
252
|
-
@obj = Object.new
|
253
|
-
@obj.extend Module.new{ def meth; 1; end }
|
254
|
-
should_find_method('meth')
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should find methods all the way up to Kernel" do
|
258
|
-
@obj = Object.new
|
259
|
-
should_find_method('exit!')
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should not find methods defined on the classes singleton class" do
|
263
|
-
@obj = Class.new{ class << self; def meth; 1; end; end }.new
|
264
|
-
Pry::Method.all_from_obj(@obj).map(&:name).should.not.include('meth')
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should work in the face of an overridden send" do
|
268
|
-
@obj = Class.new{ def meth; 1; end; def send; raise EOFError; end }.new
|
269
|
-
should_find_method('meth')
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe 'on classes' do
|
274
|
-
def should_find_method(name)
|
275
|
-
Pry::Method.all_from_obj(@class).map(&:name).should.include(name)
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should find methods defined in the class' singleton class" do
|
279
|
-
@class = Class.new{ class << self; def meth; 1; end; end }
|
280
|
-
should_find_method('meth')
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should find methods defined on modules extended into the class" do
|
284
|
-
@class = Class.new{ extend Module.new{ def meth; 1; end; } }
|
285
|
-
should_find_method('meth')
|
286
|
-
end
|
287
|
-
|
288
|
-
it "should find methods defined on the singleton class of super-classes" do
|
289
|
-
@class = Class.new(Class.new{ class << self; def meth; 1; end; end })
|
290
|
-
should_find_method('meth')
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should not find methods defined within the class" do
|
294
|
-
@class = Class.new{ def meth; 1; end }
|
295
|
-
Pry::Method.all_from_obj(@obj).map(&:name).should.not.include('meth')
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should find methods defined on Class" do
|
299
|
-
@class = Class.new
|
300
|
-
should_find_method('allocate')
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should find methods defined on Kernel" do
|
304
|
-
@class = Class.new
|
305
|
-
should_find_method('exit!')
|
306
|
-
end
|
307
|
-
|
308
|
-
it "should attribute overridden methods to the sub-class' singleton class" do
|
309
|
-
@class = Class.new(Class.new{ class << self; def meth; 1; end; end }) { class << self; def meth; 1; end; end }
|
310
|
-
Pry::Method.all_from_obj(@class).detect{ |x| x.name == 'meth' }.owner.should == (class << @class; self; end)
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should attrbute overridden methods to the class not the module" do
|
314
|
-
@class = Class.new { class << self; def meth; 1; end; end; extend Module.new{ def meth; 1; end; } }
|
315
|
-
Pry::Method.all_from_obj(@class).detect{ |x| x.name == 'meth' }.owner.should == (class << @class; self; end)
|
316
|
-
end
|
317
|
-
|
318
|
-
it "should attribute overridden methods to the relevant singleton class in preference to Class" do
|
319
|
-
@class = Class.new { class << self; def allocate; 1; end; end }
|
320
|
-
Pry::Method.all_from_obj(@class).detect{ |x| x.name == 'allocate' }.owner.should == (class << @class; self; end)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
describe 'method resolution order' do
|
325
|
-
module LS
|
326
|
-
class Top; end
|
327
|
-
|
328
|
-
class Next < Top; end
|
329
|
-
|
330
|
-
module M; end
|
331
|
-
module N; include M; end
|
332
|
-
module O; include M; end
|
333
|
-
module P; end
|
334
|
-
|
335
|
-
class Low < Next; include N; include P; end
|
336
|
-
class Lower < Low; extend N; end
|
337
|
-
class Bottom < Lower; extend O; end
|
338
|
-
end
|
339
|
-
|
340
|
-
def singleton_class(obj); class << obj; self; end; end
|
341
|
-
|
342
|
-
it "should look at a class and then its superclass" do
|
343
|
-
Pry::Method.instance_resolution_order(LS::Next).should == [LS::Next] + Pry::Method.instance_resolution_order(LS::Top)
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should include the included modules between a class and its superclass" do
|
347
|
-
Pry::Method.instance_resolution_order(LS::Low).should == [LS::Low, LS::P, LS::N, LS::M] + Pry::Method.instance_resolution_order(LS::Next)
|
348
|
-
end
|
349
|
-
|
350
|
-
it "should not include modules extended into the class" do
|
351
|
-
Pry::Method.instance_resolution_order(LS::Bottom).should == [LS::Bottom] + Pry::Method.instance_resolution_order(LS::Lower)
|
352
|
-
end
|
353
|
-
|
354
|
-
it "should include included modules for Modules" do
|
355
|
-
Pry::Method.instance_resolution_order(LS::O).should == [LS::O, LS::M]
|
356
|
-
end
|
357
|
-
|
358
|
-
it "should include the singleton class of objects" do
|
359
|
-
obj = LS::Low.new
|
360
|
-
Pry::Method.resolution_order(obj).should == [singleton_class(obj)] + Pry::Method.instance_resolution_order(LS::Low)
|
361
|
-
end
|
362
|
-
|
363
|
-
it "should not include singleton classes of numbers" do
|
364
|
-
Pry::Method.resolution_order(4).should == Pry::Method.instance_resolution_order(Fixnum)
|
365
|
-
end
|
366
|
-
|
367
|
-
it "should include singleton classes for classes" do
|
368
|
-
Pry::Method.resolution_order(LS::Low).should == [singleton_class(LS::Low)] + Pry::Method.resolution_order(LS::Next)
|
369
|
-
end
|
370
|
-
|
371
|
-
it "should include modules included into singleton classes" do
|
372
|
-
Pry::Method.resolution_order(LS::Lower).should == [singleton_class(LS::Lower), LS::N, LS::M] + Pry::Method.resolution_order(LS::Low)
|
373
|
-
end
|
374
|
-
|
375
|
-
it "should include modules at most once" do
|
376
|
-
Pry::Method.resolution_order(LS::Bottom).count(LS::M).should == 1
|
377
|
-
end
|
378
|
-
|
379
|
-
it "should include modules at the point which they would be reached" do
|
380
|
-
Pry::Method.resolution_order(LS::Bottom).should == [singleton_class(LS::Bottom), LS::O] + (Pry::Method.resolution_order(LS::Lower))
|
381
|
-
end
|
382
|
-
|
383
|
-
it "should include the Pry::Method.instance_resolution_order of Class after the singleton classes" do
|
384
|
-
Pry::Method.resolution_order(LS::Top).should ==
|
385
|
-
[singleton_class(LS::Top), singleton_class(Object), (defined? BasicObject) && singleton_class(BasicObject)].compact +
|
386
|
-
Pry::Method.instance_resolution_order(Class)
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
describe 'method_name_from_first_line' do
|
392
|
-
it 'should work in all simple cases' do
|
393
|
-
meth = Pry::Method.new(nil)
|
394
|
-
meth.send(:method_name_from_first_line, "def x").should == "x"
|
395
|
-
meth.send(:method_name_from_first_line, "def self.x").should == "x"
|
396
|
-
meth.send(:method_name_from_first_line, "def ClassName.x").should == "x"
|
397
|
-
meth.send(:method_name_from_first_line, "def obj_name.x").should == "x"
|
398
|
-
end
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|