pry 0.9.0pre2-i386-mingw32 → 0.9.0pre3-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/bin/pry +19 -9
- data/lib/pry.rb +5 -2
- data/lib/pry/command_processor.rb +21 -16
- data/lib/pry/config.rb +3 -0
- data/lib/pry/default_commands/gems.rb +5 -5
- data/lib/pry/default_commands/input.rb +3 -3
- data/lib/pry/default_commands/introspection.rb +4 -4
- data/lib/pry/default_commands/ls.rb +2 -2
- data/lib/pry/default_commands/shell.rb +1 -1
- data/lib/pry/history_array.rb +105 -0
- data/lib/pry/pry_class.rb +7 -5
- data/lib/pry/pry_instance.rb +34 -5
- data/lib/pry/version.rb +1 -1
- data/test/helper.rb +1 -0
- data/test/test_command_processor.rb +44 -10
- data/test/test_default_commands/test_gems.rb +14 -0
- data/test/test_history_array.rb +65 -0
- data/test/test_pry.rb +93 -1
- metadata +20 -4
data/Rakefile
CHANGED
data/bin/pry
CHANGED
@@ -20,9 +20,25 @@ See: `https://github.com/banister` for more information.
|
|
20
20
|
}
|
21
21
|
|
22
22
|
on :e, :exec, "A line of code to execute in context before the session starts", true
|
23
|
-
|
24
|
-
on "no-
|
25
|
-
|
23
|
+
|
24
|
+
on "no-pager", "Disable pager for long output" do
|
25
|
+
Pry.pager = false
|
26
|
+
end
|
27
|
+
|
28
|
+
on "no-color", "Disable syntax highlighting for session" do
|
29
|
+
Pry.color = false
|
30
|
+
end
|
31
|
+
|
32
|
+
on :f, "Suppress loading of ~/.pryrc" do
|
33
|
+
# load ~/.pryrc, if not suppressed with -f option
|
34
|
+
Pry.config.should_load_rc = false
|
35
|
+
end
|
36
|
+
|
37
|
+
on "no-plugins", "Suppress loading of plugins." do
|
38
|
+
# suppress plugins if given --no-plugins optino
|
39
|
+
Pry.config.plugins.enabled = false
|
40
|
+
end
|
41
|
+
|
26
42
|
on "simple-prompt", "Enable simple prompt mode" do
|
27
43
|
Pry.prompt = Pry::SIMPLE_PROMPT
|
28
44
|
end
|
@@ -50,12 +66,6 @@ end
|
|
50
66
|
# invoked via cli
|
51
67
|
Pry.cli = true
|
52
68
|
|
53
|
-
# load ~/.pryrc, if not suppressed with -f option
|
54
|
-
Pry.config.should_load_rc = !opts.f?
|
55
|
-
|
56
|
-
# suppress plugins if given --no-plugins optino
|
57
|
-
Pry.config.plugins.enabled = false if opts["no-plugins"]
|
58
|
-
|
59
69
|
# create the actual context
|
60
70
|
context = Pry.binding_for(eval(opts[:context]))
|
61
71
|
|
data/lib/pry.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# (C) John Mair (banisterfiend) 2011
|
2
2
|
# MIT License
|
3
3
|
|
4
|
+
require 'pp'
|
5
|
+
|
4
6
|
class Pry
|
5
7
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
6
8
|
DEFAULT_HOOKS = {
|
@@ -19,7 +21,7 @@ class Pry
|
|
19
21
|
# The default prints
|
20
22
|
DEFAULT_PRINT = proc do |output, value|
|
21
23
|
if Pry.color
|
22
|
-
output.puts "=> #{CodeRay.scan(
|
24
|
+
output.puts "=> #{CodeRay.scan(value.pretty_inspect, :ruby).term}"
|
23
25
|
else
|
24
26
|
output.puts "=> #{Pry.view(value)}"
|
25
27
|
end
|
@@ -79,6 +81,7 @@ if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
|
79
81
|
end
|
80
82
|
|
81
83
|
require "pry/version"
|
84
|
+
require "pry/history_array"
|
82
85
|
require "pry/helpers"
|
83
86
|
require "pry/command_set"
|
84
87
|
require "pry/commands"
|
@@ -88,4 +91,4 @@ require "pry/completion"
|
|
88
91
|
require "pry/plugins"
|
89
92
|
require "pry/core_extensions"
|
90
93
|
require "pry/pry_class"
|
91
|
-
require "pry/pry_instance"
|
94
|
+
require "pry/pry_instance"
|
@@ -12,13 +12,16 @@ class Pry
|
|
12
12
|
|
13
13
|
def_delegators :@pry_instance, :commands, :nesting, :output
|
14
14
|
|
15
|
-
# Is the string a command
|
15
|
+
# Is the string a valid command?
|
16
16
|
# @param [String] val The string passed in from the Pry prompt.
|
17
17
|
# @return [Boolean] Whether the string is a valid command.
|
18
18
|
def valid_command?(val)
|
19
|
-
!!(command_matched(val)[0])
|
19
|
+
!!(command_matched(val, binding)[0])
|
20
20
|
end
|
21
21
|
|
22
|
+
# Convert the object to a form that can be interpolated into a
|
23
|
+
# Regexp cleanly.
|
24
|
+
# @return [String] The string to interpolate into a Regexp
|
22
25
|
def convert_to_regex(obj)
|
23
26
|
case obj
|
24
27
|
when String
|
@@ -44,10 +47,20 @@ class Pry
|
|
44
47
|
# and argument string.
|
45
48
|
# This method should not need to be invoked directly.
|
46
49
|
# @param [String] val The line of input.
|
50
|
+
# @param [Binding] target The binding to perform string
|
51
|
+
# interpolation against.
|
47
52
|
# @return [Array] The command data and arg string pair
|
48
|
-
def command_matched(val)
|
49
|
-
_, cmd_data = commands.commands.find do |name,
|
50
|
-
|
53
|
+
def command_matched(val, target)
|
54
|
+
_, cmd_data = commands.commands.find do |name, data|
|
55
|
+
|
56
|
+
interp_val = interpolate_string(val, target)
|
57
|
+
command_regex = /^#{convert_to_regex(name)}(?!\S)/
|
58
|
+
|
59
|
+
if data.options[:interpolate] && (command_regex =~ interp_val)
|
60
|
+
val.replace interp_val
|
61
|
+
else
|
62
|
+
command_regex =~ val
|
63
|
+
end
|
51
64
|
end
|
52
65
|
|
53
66
|
[cmd_data, (Regexp.last_match ? Regexp.last_match.captures : nil), (Regexp.last_match ? Regexp.last_match.end(0) : nil)]
|
@@ -65,18 +78,10 @@ class Pry
|
|
65
78
|
def process_commands(val, eval_string, target)
|
66
79
|
|
67
80
|
# no command was matched, so return to caller
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# perform ruby interpolation for commands
|
73
|
-
if command.options[:interpolate]
|
74
|
-
val.replace interpolate_string(val, target)
|
75
|
-
# command, captures, pos = command_matched(val)
|
76
|
-
# captures = captures.map { |v| interpolate_string(v, target) if v }
|
77
|
-
end
|
78
|
-
|
81
|
+
command, captures, pos = command_matched(val, target)
|
82
|
+
return if !command
|
79
83
|
arg_string = val[pos..-1].strip
|
84
|
+
|
80
85
|
args = arg_string ? Shellwords.shellwords(arg_string) : []
|
81
86
|
|
82
87
|
options = {
|
data/lib/pry/config.rb
CHANGED
@@ -88,6 +88,9 @@ class Pry
|
|
88
88
|
# `plugins.strict_loading` (Boolean) which toggles whether referring to a non-existent plugin should raise an exception (defaults to `false`)
|
89
89
|
# @return [OpenStruct]
|
90
90
|
attr_accessor :plugins
|
91
|
+
|
92
|
+
# @return [Integer] Amount of results that will be stored into _out_
|
93
|
+
attr_accessor :memory_size
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
@@ -33,12 +33,12 @@ class Pry
|
|
33
33
|
end
|
34
34
|
|
35
35
|
gems.each do |gem, specs|
|
36
|
-
specs.sort! do |a,b|
|
37
|
-
Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
|
36
|
+
specs.sort! do |a,b|
|
37
|
+
Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
|
38
38
|
end
|
39
|
-
|
40
|
-
versions = specs.map
|
41
|
-
index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
|
39
|
+
|
40
|
+
versions = specs.each_with_index.map do |spec, index|
|
41
|
+
index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
|
42
42
|
end
|
43
43
|
|
44
44
|
output.puts "#{text.white gem} (#{versions.join ', '})"
|
@@ -12,8 +12,8 @@ class Pry
|
|
12
12
|
render_output(false, 0, Pry.color ? CodeRay.scan(eval_string, :ruby).term : eval_string)
|
13
13
|
end
|
14
14
|
|
15
|
-
command
|
16
|
-
:interpolate => false, :listing => "amend-line-N" do |line_number, replacement_line|
|
15
|
+
command(/amend-line-?(\d+)?/, "Experimental amend-line, where the N in amend-line-N represents line to replace. Aliases: %N",
|
16
|
+
:interpolate => false, :listing => "amend-line-N") do |line_number, replacement_line|
|
17
17
|
replacement_line = "" if !replacement_line
|
18
18
|
input_array = eval_string.each_line.to_a
|
19
19
|
line_num = line_number ? line_number.to_i : input_array.size - 1
|
@@ -21,7 +21,7 @@ class Pry
|
|
21
21
|
eval_string.replace input_array.join
|
22
22
|
end
|
23
23
|
|
24
|
-
alias_command
|
24
|
+
alias_command(/%(\d+)?/, /amend-line-?(\d+)?/, "")
|
25
25
|
|
26
26
|
command "hist", "Show and replay Readline history. Type `hist --help` for more info." do |*args|
|
27
27
|
Slop.parse(args) do |opt|
|
@@ -109,8 +109,8 @@ class Pry
|
|
109
109
|
|
110
110
|
opt.on :M, "instance-methods", "Operate on instance methods."
|
111
111
|
opt.on :m, :methods, "Operate on methods."
|
112
|
-
opt.on "no-reload", "Do not automatically reload the method's file after editting."
|
113
|
-
opt.on
|
112
|
+
opt.on :n, "no-reload", "Do not automatically reload the method's file after editting."
|
113
|
+
opt.on "no-jump", "Do not fast forward editor to first line of method."
|
114
114
|
opt.on :c, :context, "Select object context to run under.", true do |context|
|
115
115
|
target = Pry.binding_for(target.eval(context))
|
116
116
|
end
|
@@ -143,13 +143,13 @@ class Pry
|
|
143
143
|
editor_invocation = Pry.editor.call(file, line)
|
144
144
|
else
|
145
145
|
# only use start line if -n option is not used
|
146
|
-
start_line_syntax = opts
|
146
|
+
start_line_syntax = opts["no-jump"] ? "" : start_line_for_editor(line)
|
147
147
|
editor_invocation = "#{Pry.editor} #{start_line_syntax} #{file}"
|
148
148
|
end
|
149
149
|
|
150
150
|
run ".#{editor_invocation}"
|
151
151
|
silence_warnings do
|
152
|
-
load file if !opts
|
152
|
+
load file if !opts.n?
|
153
153
|
end
|
154
154
|
end
|
155
155
|
end
|
@@ -180,9 +180,9 @@ Shows local and instance variables by default.
|
|
180
180
|
list = list.grep(options[:grep]) if list
|
181
181
|
list.uniq! if list
|
182
182
|
if Pry.color
|
183
|
-
text << CodeRay.scan(
|
183
|
+
text << CodeRay.scan(list.inspect, :ruby).term + "\n"
|
184
184
|
else
|
185
|
-
text <<
|
185
|
+
text << list.inspect + "\n"
|
186
186
|
end
|
187
187
|
if !options[:f]
|
188
188
|
stagger_output(text)
|
@@ -3,7 +3,7 @@ class Pry
|
|
3
3
|
|
4
4
|
Shell = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
command
|
6
|
+
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
|
7
7
|
if cmd =~ /^cd\s+(.+)/i
|
8
8
|
dest = $1
|
9
9
|
begin
|
@@ -0,0 +1,105 @@
|
|
1
|
+
class Pry
|
2
|
+
# A history array is an array to which you can only add elements. Older
|
3
|
+
# entries are removed progressively, so that the aray never contains more than
|
4
|
+
# N elements.
|
5
|
+
#
|
6
|
+
# History arrays are used by Pry to store the output of the last commands.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# ary = Pry::HistoryArray.new 10
|
10
|
+
# ary << 1 << 2 << 3
|
11
|
+
# ary[0] # => 1
|
12
|
+
# ary[1] # => 2
|
13
|
+
# 10.times { |n| ary << n }
|
14
|
+
# ary[0] # => nil
|
15
|
+
# ary[-1] # => 9
|
16
|
+
class HistoryArray
|
17
|
+
include Enumerable
|
18
|
+
|
19
|
+
# @param [Integer] size Maximum amount of objects in the array
|
20
|
+
def initialize(size)
|
21
|
+
@max_size = size
|
22
|
+
|
23
|
+
@hash = {}
|
24
|
+
@count = 0
|
25
|
+
end
|
26
|
+
|
27
|
+
# Pushes an object at the end of the array
|
28
|
+
# @param [Object] value Object to be added
|
29
|
+
def <<(value)
|
30
|
+
@hash[@count] = value
|
31
|
+
|
32
|
+
if @hash.size > max_size
|
33
|
+
@hash.delete(@count - max_size)
|
34
|
+
end
|
35
|
+
|
36
|
+
@count += 1
|
37
|
+
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# @overload [](index)
|
42
|
+
# @param [Integer] index Index of the item to access.
|
43
|
+
# @return [Object, nil] Item at that index or nil if it has been removed.
|
44
|
+
# @overload [](index, size)
|
45
|
+
# @param [Integer] index Index of the first item to access.
|
46
|
+
# @param [Integer] size Amount of items to access
|
47
|
+
# @return [Array, nil] The selected items. Nil if index is greater than
|
48
|
+
# the size of the array.
|
49
|
+
# @overload [](range)
|
50
|
+
# @param [Range<Integer>] range Range of indices to access.
|
51
|
+
# @return [Array, nil] The selected items. Nil if index is greater than
|
52
|
+
# the size of the array.
|
53
|
+
def [](index_or_range, size = nil)
|
54
|
+
if index_or_range.is_a? Integer
|
55
|
+
index = convert_index(index_or_range)
|
56
|
+
|
57
|
+
if size
|
58
|
+
end_index = index + size
|
59
|
+
index > @count ? nil : (index...[end_index, @count].min).map do |n|
|
60
|
+
@hash[n]
|
61
|
+
end
|
62
|
+
else
|
63
|
+
@hash[index]
|
64
|
+
end
|
65
|
+
else
|
66
|
+
range = convert_range(index_or_range)
|
67
|
+
range.begin > @count ? nil : range.map { |n| @hash[n] }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Integer] Amount of objects in the array
|
72
|
+
def size
|
73
|
+
@count
|
74
|
+
end
|
75
|
+
|
76
|
+
def each
|
77
|
+
((@count - size)...@count).each do |n|
|
78
|
+
yield @hash[n]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_a
|
83
|
+
((@count - size)...@count).map { |n| @hash[n] }
|
84
|
+
end
|
85
|
+
|
86
|
+
def inspect
|
87
|
+
"#<#{self.class} size=#{size} first=#{@count - size} max_size=#{max_size}>"
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [Integer] Maximum amount of objects in the array
|
91
|
+
attr_reader :max_size
|
92
|
+
|
93
|
+
private
|
94
|
+
def convert_index(n)
|
95
|
+
n >= 0 ? n : @count + n
|
96
|
+
end
|
97
|
+
|
98
|
+
def convert_range(range)
|
99
|
+
end_index = convert_index(range.end)
|
100
|
+
end_index += 1 unless range.exclude_end?
|
101
|
+
|
102
|
+
Range.new(convert_index(range.begin), [end_index, @count].min, true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/pry/pry_class.rb
CHANGED
@@ -69,7 +69,7 @@ class Pry
|
|
69
69
|
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
70
70
|
|
71
71
|
delegate_accessors :@config, :input, :output, :commands, :prompt, :print, :exception_handler,
|
72
|
-
:hooks, :color, :pager, :editor
|
72
|
+
:hooks, :color, :pager, :editor, :memory_size
|
73
73
|
end
|
74
74
|
|
75
75
|
# Load the rc files given in the `Pry::RC_FILES` array.
|
@@ -105,12 +105,12 @@ class Pry
|
|
105
105
|
new(options).repl(target)
|
106
106
|
end
|
107
107
|
|
108
|
-
# A custom version of `Kernel#
|
108
|
+
# A custom version of `Kernel#pretty_inspect`.
|
109
109
|
# This method should not need to be accessed directly.
|
110
110
|
# @param obj The object to view.
|
111
111
|
# @return [String] The string representation of `obj`.
|
112
112
|
def self.view(obj)
|
113
|
-
obj.
|
113
|
+
obj.pretty_inspect
|
114
114
|
|
115
115
|
rescue NoMethodError
|
116
116
|
"unknown"
|
@@ -122,8 +122,8 @@ class Pry
|
|
122
122
|
# @param max_size The maximum number of chars before clipping occurs.
|
123
123
|
# @return [String] The string representation of `obj`.
|
124
124
|
def self.view_clip(obj, max_size=60)
|
125
|
-
if
|
126
|
-
|
125
|
+
if obj.inspect.size < max_size
|
126
|
+
obj.inspect
|
127
127
|
else
|
128
128
|
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
|
129
129
|
end
|
@@ -199,6 +199,8 @@ class Pry
|
|
199
199
|
config.history.save = true
|
200
200
|
config.history.load = true
|
201
201
|
config.history.file = File.expand_path("~/.pry_history")
|
202
|
+
|
203
|
+
config.memory_size = 100
|
202
204
|
end
|
203
205
|
|
204
206
|
# Set all the configurable options back to their default values
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -26,6 +26,7 @@ class Pry
|
|
26
26
|
# component of the REPL. (see print.rb)
|
27
27
|
def initialize(options={})
|
28
28
|
refresh(options)
|
29
|
+
|
29
30
|
@command_processor = CommandProcessor.new(self)
|
30
31
|
end
|
31
32
|
|
@@ -38,7 +39,7 @@ class Pry
|
|
38
39
|
attributes = [
|
39
40
|
:input, :output, :commands, :print,
|
40
41
|
:exception_handler, :hooks, :custom_completions,
|
41
|
-
:prompt
|
42
|
+
:prompt, :memory_size
|
42
43
|
]
|
43
44
|
|
44
45
|
attributes.each do |attribute|
|
@@ -48,6 +49,7 @@ class Pry
|
|
48
49
|
defaults.merge!(options).each do |key, value|
|
49
50
|
send "#{key}=", value
|
50
51
|
end
|
52
|
+
|
51
53
|
true
|
52
54
|
end
|
53
55
|
|
@@ -71,6 +73,17 @@ class Pry
|
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
76
|
+
# @return [Integer] The maximum amount of objects remembered by the inp and
|
77
|
+
# out arrays. Defaults to 100.
|
78
|
+
def memory_size
|
79
|
+
@output_array.max_size
|
80
|
+
end
|
81
|
+
|
82
|
+
def memory_size=(size)
|
83
|
+
@input_array = Pry::HistoryArray.new(size)
|
84
|
+
@output_array = Pry::HistoryArray.new(size)
|
85
|
+
end
|
86
|
+
|
74
87
|
# Get nesting data.
|
75
88
|
# This method should not need to be accessed directly.
|
76
89
|
# @return [Array] The unparsed nesting information.
|
@@ -111,8 +124,13 @@ class Pry
|
|
111
124
|
Pry.active_instance = self
|
112
125
|
|
113
126
|
# Make sure special locals exist
|
127
|
+
target.eval("inp = ::Pry.active_instance.instance_eval { @input_array }")
|
128
|
+
target.eval("out = ::Pry.active_instance.instance_eval { @output_array }")
|
129
|
+
|
114
130
|
set_active_instance(target)
|
131
|
+
@input_array << nil # add empty input so inp and out match
|
115
132
|
set_last_result(Pry.last_result, target)
|
133
|
+
|
116
134
|
self.session_target = target
|
117
135
|
end
|
118
136
|
|
@@ -193,19 +211,29 @@ class Pry
|
|
193
211
|
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target, instance_eval(&custom_completions)
|
194
212
|
end
|
195
213
|
|
214
|
+
# save the pry instance to active_instance
|
215
|
+
Pry.active_instance = self
|
216
|
+
|
217
|
+
target.eval("inp = ::Pry.active_instance.instance_eval { @input_array }")
|
218
|
+
target.eval("out = ::Pry.active_instance.instance_eval { @output_array }")
|
219
|
+
|
196
220
|
@last_result_is_exception = false
|
197
221
|
set_active_instance(target)
|
198
|
-
expr = r(target)
|
199
222
|
|
200
|
-
|
201
|
-
|
223
|
+
code = r(target)
|
224
|
+
|
225
|
+
Pry.line_buffer.push(*code.each_line)
|
226
|
+
res = set_last_result(target.eval(code, Pry.eval_path, Pry.current_line), target)
|
227
|
+
res
|
202
228
|
rescue SystemExit => e
|
203
229
|
exit
|
204
230
|
rescue Exception => e
|
205
231
|
@last_result_is_exception = true
|
232
|
+
@output_array << e
|
206
233
|
set_last_exception(e, target)
|
207
234
|
ensure
|
208
|
-
|
235
|
+
@input_array << code
|
236
|
+
Pry.current_line += code.each_line.count if code
|
209
237
|
end
|
210
238
|
|
211
239
|
# Perform a read.
|
@@ -292,6 +320,7 @@ class Pry
|
|
292
320
|
# @param [Binding] target The binding to set `_` on.
|
293
321
|
def set_last_result(result, target)
|
294
322
|
Pry.last_result = result
|
323
|
+
@output_array << result
|
295
324
|
target.eval("_ = ::Pry.last_result")
|
296
325
|
end
|
297
326
|
|
data/lib/pry/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe "Pry::CommandProcessor" do
|
4
|
-
|
5
4
|
before do
|
6
5
|
@pry = Pry.new
|
7
6
|
@pry.commands = Pry::CommandSet.new
|
@@ -12,9 +11,21 @@ describe "Pry::CommandProcessor" do
|
|
12
11
|
@pry.commands = Pry::CommandSet.new
|
13
12
|
end
|
14
13
|
|
14
|
+
it 'should accurately determine if a command is valid' do
|
15
|
+
@pry.commands.command("test-command") {}
|
16
|
+
valid = @command_processor.valid_command? "test-command"
|
17
|
+
valid.should == true
|
18
|
+
|
19
|
+
valid = @command_processor.valid_command? "blah"
|
20
|
+
valid.should == false
|
21
|
+
|
22
|
+
a = "test-command"
|
23
|
+
lambda { @command_processor.valid_command? '#{a}' }.should.raise NameError
|
24
|
+
end
|
25
|
+
|
15
26
|
it 'should correctly match a simple string command' do
|
16
27
|
@pry.commands.command("test-command") {}
|
17
|
-
command, captures, pos = @command_processor.command_matched "test-command"
|
28
|
+
command, captures, pos = @command_processor.command_matched "test-command", binding
|
18
29
|
|
19
30
|
command.name.should == "test-command"
|
20
31
|
captures.should == []
|
@@ -23,7 +34,7 @@ describe "Pry::CommandProcessor" do
|
|
23
34
|
|
24
35
|
it 'should correctly match a simple string command with parameters' do
|
25
36
|
@pry.commands.command("test-command") { |arg|}
|
26
|
-
command, captures, pos = @command_processor.command_matched "test-command hello"
|
37
|
+
command, captures, pos = @command_processor.command_matched "test-command hello", binding
|
27
38
|
|
28
39
|
command.name.should == "test-command"
|
29
40
|
captures.should == []
|
@@ -31,7 +42,7 @@ describe "Pry::CommandProcessor" do
|
|
31
42
|
end
|
32
43
|
|
33
44
|
it 'should not match when the relevant command does not exist' do
|
34
|
-
command, captures, pos = @command_processor.command_matched "test-command"
|
45
|
+
command, captures, pos = @command_processor.command_matched "test-command", binding
|
35
46
|
|
36
47
|
command.should == nil
|
37
48
|
captures.should == nil
|
@@ -39,7 +50,7 @@ describe "Pry::CommandProcessor" do
|
|
39
50
|
|
40
51
|
it 'should correctly match a regex command' do
|
41
52
|
@pry.commands.command(/rue(.?)/) { }
|
42
|
-
command, captures, pos = @command_processor.command_matched "rue hello"
|
53
|
+
command, captures, pos = @command_processor.command_matched "rue hello", binding
|
43
54
|
|
44
55
|
command.name.should == /rue(.?)/
|
45
56
|
captures.should == [""]
|
@@ -48,7 +59,7 @@ describe "Pry::CommandProcessor" do
|
|
48
59
|
|
49
60
|
it 'should correctly match a regex command and extract the capture groups' do
|
50
61
|
@pry.commands.command(/rue(.?)/) { }
|
51
|
-
command, captures, pos = @command_processor.command_matched "rue5 hello"
|
62
|
+
command, captures, pos = @command_processor.command_matched "rue5 hello", binding
|
52
63
|
|
53
64
|
command.name.should == /rue(.?)/
|
54
65
|
captures.should == ["5"]
|
@@ -57,7 +68,7 @@ describe "Pry::CommandProcessor" do
|
|
57
68
|
|
58
69
|
it 'should correctly match a string command with spaces in its name' do
|
59
70
|
@pry.commands.command("test command") {}
|
60
|
-
command, captures, pos = @command_processor.command_matched "test command"
|
71
|
+
command, captures, pos = @command_processor.command_matched "test command", binding
|
61
72
|
|
62
73
|
command.name.should == "test command"
|
63
74
|
captures.should == []
|
@@ -66,7 +77,7 @@ describe "Pry::CommandProcessor" do
|
|
66
77
|
|
67
78
|
it 'should correctly match a string command with spaces in its name with parameters' do
|
68
79
|
@pry.commands.command("test command") {}
|
69
|
-
command, captures, pos = @command_processor.command_matched "test command param1 param2"
|
80
|
+
command, captures, pos = @command_processor.command_matched "test command param1 param2", binding
|
70
81
|
|
71
82
|
command.name.should == "test command"
|
72
83
|
captures.should == []
|
@@ -78,7 +89,7 @@ describe "Pry::CommandProcessor" do
|
|
78
89
|
@pry.commands.command(regex_command_name) {}
|
79
90
|
|
80
91
|
sample_text = "test friendship command"
|
81
|
-
command, captures, pos = @command_processor.command_matched sample_text
|
92
|
+
command, captures, pos = @command_processor.command_matched sample_text, binding
|
82
93
|
|
83
94
|
command.name.should == regex_command_name
|
84
95
|
captures.should == ["friendship"]
|
@@ -90,10 +101,33 @@ describe "Pry::CommandProcessor" do
|
|
90
101
|
@pry.commands.command(regex_command_name) {}
|
91
102
|
|
92
103
|
sample_text = ".cd ~/pry"
|
93
|
-
command, captures, pos = @command_processor.command_matched sample_text
|
104
|
+
command, captures, pos = @command_processor.command_matched sample_text, binding
|
94
105
|
|
95
106
|
command.name.should == regex_command_name
|
96
107
|
captures.should == ["cd ~/pry"]
|
97
108
|
pos.should == sample_text.size
|
98
109
|
end
|
110
|
+
|
111
|
+
it 'should correctly match a command whose name is interpolated' do
|
112
|
+
@pry.commands.command("blah") {}
|
113
|
+
a = "bl"
|
114
|
+
b = "ah"
|
115
|
+
command, captures, pos = @command_processor.command_matched '#{a}#{b}', binding
|
116
|
+
|
117
|
+
command.name.should == "blah"
|
118
|
+
captures.should == []
|
119
|
+
pos.should == command.name.length
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should NOT match a command whose name is interpolated when :interpolate => false' do
|
123
|
+
@pry.commands.command("boast", "", :interpolate => false) {}
|
124
|
+
a = "boa"
|
125
|
+
b = "st"
|
126
|
+
|
127
|
+
# remember to use '' instead of "" when testing interpolation or
|
128
|
+
# you'll cause yourself incredible confusion
|
129
|
+
command, captures, pos = @command_processor.command_matched '#{a}#{b}', binding
|
130
|
+
|
131
|
+
command.should == nil
|
132
|
+
end
|
99
133
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Pry::DefaultCommands::Gems" do
|
4
|
+
describe "gem-list" do
|
5
|
+
|
6
|
+
# fixing bug for 1.8 compat
|
7
|
+
it 'should not raise when invoked' do
|
8
|
+
str_output = StringIO.new
|
9
|
+
Pry.start self, :input => InputTester.new("gem-list", "exit-all"), :output => str_output
|
10
|
+
str_output.string.should.not =~ /NoMethodError/
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Pry::HistoryArray do
|
4
|
+
before do
|
5
|
+
@array = Pry::HistoryArray.new 10
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should have a maximum size specifed at creation time' do
|
9
|
+
@array.max_size.should == 10
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be able to be added objects to' do
|
13
|
+
@array << 1 << 2 << 3
|
14
|
+
@array.size.should == 3
|
15
|
+
@array.to_a.should == [1, 2, 3]
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should be able to access single elements' do
|
19
|
+
@array << 1 << 2 << 3
|
20
|
+
@array[2].should == 3
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be able to access negative indices' do
|
24
|
+
@array << 1 << 2 << 3
|
25
|
+
@array[-1].should == 3
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should be able to access ranges' do
|
29
|
+
@array << 1 << 2 << 3 << 4
|
30
|
+
@array[1..2].should == [2, 3]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should be able to access ranges starting from a negative index' do
|
34
|
+
@array << 1 << 2 << 3 << 4
|
35
|
+
@array[-2..3].should == [3, 4]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should be able to access ranges ending at a negative index' do
|
39
|
+
@array << 1 << 2 << 3 << 4
|
40
|
+
@array[2..-1].should == [3, 4]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should be able to access ranges using only negative indices' do
|
44
|
+
@array << 1 << 2 << 3 << 4
|
45
|
+
@array[-2..-1].should == [3, 4]
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should be able to use range where end is excluded' do
|
49
|
+
@array << 1 << 2 << 3 << 4
|
50
|
+
@array[-2...-1].should == [3]
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should be able to access slices using a size' do
|
54
|
+
@array << 1 << 2 << 3 << 4
|
55
|
+
@array[-3, 2].should == [2, 3]
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should remove older entries' do
|
59
|
+
11.times { |n| @array << n }
|
60
|
+
|
61
|
+
@array[0].should == nil
|
62
|
+
@array[1].should == 1
|
63
|
+
@array[10].should == 10
|
64
|
+
end
|
65
|
+
end
|
data/test/test_pry.rb
CHANGED
@@ -6,6 +6,15 @@ puts "With method_source version #{MethodSource::VERSION}"
|
|
6
6
|
puts "--"
|
7
7
|
|
8
8
|
describe Pry do
|
9
|
+
|
10
|
+
describe 'warning emissions' do
|
11
|
+
it 'should emit no warnings' do
|
12
|
+
Open4.popen4 'ruby -I lib -rubygems -r"pry" -W -e "exit"' do |pid, stdin, stdout, stderr|
|
13
|
+
stderr.read.empty?.should == true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
9
18
|
describe "open a Pry session on an object" do
|
10
19
|
describe "rep" do
|
11
20
|
before do
|
@@ -134,6 +143,67 @@ describe Pry do
|
|
134
143
|
end
|
135
144
|
end
|
136
145
|
|
146
|
+
describe "history arrays" do
|
147
|
+
it 'sets _ to the last result' do
|
148
|
+
res = []
|
149
|
+
input = InputTester.new *[":foo", "self << _", "42", "self << _"]
|
150
|
+
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
151
|
+
pry.repl(res)
|
152
|
+
|
153
|
+
res.should == [:foo, 42]
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'sets out to an array with the result' do
|
157
|
+
res = {}
|
158
|
+
input = InputTester.new *[":foo", "42", "self[:res] = out"]
|
159
|
+
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
160
|
+
pry.repl(res)
|
161
|
+
|
162
|
+
res[:res].should.be.kind_of Pry::HistoryArray
|
163
|
+
res[:res][1..2].should == [:foo, 42]
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'sets inp to an array with the entered lines' do
|
167
|
+
res = {}
|
168
|
+
input = InputTester.new *[":foo", "42", "self[:res] = inp"]
|
169
|
+
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
170
|
+
pry.repl(res)
|
171
|
+
|
172
|
+
res[:res].should.be.kind_of Pry::HistoryArray
|
173
|
+
res[:res][1..2].should == [":foo\n", "42\n"]
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'uses 100 as the size of inp and out' do
|
177
|
+
res = []
|
178
|
+
input = InputTester.new *["self << out.max_size << inp.max_size"]
|
179
|
+
pry = Pry.new(:input => input, :output => Pry::NullOutput)
|
180
|
+
pry.repl(res)
|
181
|
+
|
182
|
+
res.should == [100, 100]
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'can change the size of the history arrays' do
|
186
|
+
res = []
|
187
|
+
input = InputTester.new *["self << out.max_size << inp.max_size"]
|
188
|
+
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
189
|
+
:memory_size => 1000)
|
190
|
+
pry.repl(res)
|
191
|
+
|
192
|
+
res.should == [1000, 1000]
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'store exceptions' do
|
196
|
+
res = []
|
197
|
+
input = InputTester.new *["foo!","self << inp[-1] << out[-1]"]
|
198
|
+
pry = Pry.new(:input => input, :output => Pry::NullOutput,
|
199
|
+
:memory_size => 1000)
|
200
|
+
pry.repl(res)
|
201
|
+
|
202
|
+
res.first.should == "foo!\n"
|
203
|
+
res.last.should.be.kind_of NoMethodError
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
137
207
|
describe "test loading rc files" do
|
138
208
|
|
139
209
|
before do
|
@@ -492,11 +562,33 @@ describe Pry do
|
|
492
562
|
Pry.new(:commands => set).rep
|
493
563
|
end
|
494
564
|
|
495
|
-
# binding.pry
|
496
565
|
str_output.string.should =~ /hello bing/
|
497
566
|
$obj = nil
|
498
567
|
end
|
499
568
|
|
569
|
+
it 'should create a regex command and arg_string should be interpolated' do
|
570
|
+
set = Pry::CommandSet.new do
|
571
|
+
command /hello(\w+)/, "" do |c1, a1, a2, a3|
|
572
|
+
output.puts "hello #{c1} #{a1} #{a2} #{a3}"
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
str_output = StringIO.new
|
577
|
+
$a1 = "bing"
|
578
|
+
$a2 = "bong"
|
579
|
+
$a3 = "bang"
|
580
|
+
redirect_pry_io(InputTester.new('hellojohn #{$a1} #{$a2} #{$a3}'), str_output) do
|
581
|
+
Pry.new(:commands => set).rep
|
582
|
+
end
|
583
|
+
|
584
|
+
str_output.string.should =~ /hello john bing bong bang/
|
585
|
+
|
586
|
+
$a1 = nil
|
587
|
+
$a2 = nil
|
588
|
+
$a3 = nil
|
589
|
+
end
|
590
|
+
|
591
|
+
|
500
592
|
it 'if a regex capture is missing it should be nil' do
|
501
593
|
set = Pry::CommandSet.new do
|
502
594
|
command /hello(.)?/, "" do |c1, a1|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 5
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.0pre3
|
6
6
|
platform: i386-mingw32
|
7
7
|
authors:
|
8
8
|
- John Mair (banisterfiend)
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-09 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_parser
|
@@ -68,16 +68,27 @@ dependencies:
|
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: open4
|
72
72
|
prerelease: false
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.0.1
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: win32console
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
74
85
|
none: false
|
75
86
|
requirements:
|
76
87
|
- - ">="
|
77
88
|
- !ruby/object:Gem::Version
|
78
89
|
version: 1.3.0
|
79
90
|
type: :runtime
|
80
|
-
version_requirements: *
|
91
|
+
version_requirements: *id007
|
81
92
|
description: an IRB alternative and runtime developer console
|
82
93
|
email: jrmair@gmail.com
|
83
94
|
executables:
|
@@ -132,6 +143,7 @@ files:
|
|
132
143
|
- lib/pry/helpers/base_helpers.rb
|
133
144
|
- lib/pry/helpers/command_helpers.rb
|
134
145
|
- lib/pry/helpers/text.rb
|
146
|
+
- lib/pry/history_array.rb
|
135
147
|
- lib/pry/plugins.rb
|
136
148
|
- lib/pry/pry_class.rb
|
137
149
|
- lib/pry/pry_instance.rb
|
@@ -143,8 +155,10 @@ files:
|
|
143
155
|
- test/test_default_commands.rb
|
144
156
|
- test/test_default_commands/test_context.rb
|
145
157
|
- test/test_default_commands/test_documentation.rb
|
158
|
+
- test/test_default_commands/test_gems.rb
|
146
159
|
- test/test_default_commands/test_input.rb
|
147
160
|
- test/test_default_commands/test_introspection.rb
|
161
|
+
- test/test_history_array.rb
|
148
162
|
- test/test_pry.rb
|
149
163
|
- test/testrc
|
150
164
|
- wiki/Customizing-pry.md
|
@@ -184,7 +198,9 @@ test_files:
|
|
184
198
|
- test/test_default_commands.rb
|
185
199
|
- test/test_default_commands/test_context.rb
|
186
200
|
- test/test_default_commands/test_documentation.rb
|
201
|
+
- test/test_default_commands/test_gems.rb
|
187
202
|
- test/test_default_commands/test_input.rb
|
188
203
|
- test/test_default_commands/test_introspection.rb
|
204
|
+
- test/test_history_array.rb
|
189
205
|
- test/test_pry.rb
|
190
206
|
- test/testrc
|