dietrb 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +0 -34
- data/Rakefile +17 -17
- data/TODO +5 -3
- data/bin/dietrb +15 -8
- data/dietrb.gemspec +4 -5
- data/lib/irb.rb +2 -5
- data/lib/irb/context.rb +23 -5
- data/lib/irb/driver.rb +8 -1
- data/lib/irb/driver/tty.rb +0 -2
- data/lib/irb/ext/completion.rb +29 -14
- data/lib/irb/ext/history.rb +1 -1
- data/lib/irb/source.rb +61 -1
- data/lib/irb/version.rb +1 -1
- data/spec/context_spec.rb +23 -15
- data/spec/ext/completion_spec.rb +18 -3
- data/spec/formatter_spec.rb +1 -1
- data/spec/source_spec.rb +66 -3
- data/spec/spec_helper.rb +10 -0
- metadata +18 -6
- data/lib/irb/ext/macruby.rb +0 -25
data/README.rdoc
CHANGED
@@ -49,16 +49,8 @@ The original IRB will still work when you uninstall the DietRB gem, though.
|
|
49
49
|
|
50
50
|
* Kernel#clear_history! will clear the history and the history file.
|
51
51
|
|
52
|
-
* irb/ext/macruby.rb, adds support for Cocoa development by starting an
|
53
|
-
NSRunloop. Loaded by default on MacRuby.
|
54
|
-
|
55
52
|
== Differences
|
56
53
|
|
57
|
-
* This IRB version specifically targets MacRuby, for now, and allows Cocoa
|
58
|
-
development to be done from the command-line. Dietrb will automatically
|
59
|
-
override the normal runloop to be ran in a thread and start a NSRunLoop on
|
60
|
-
the main thread.
|
61
|
-
|
62
54
|
* Dietrb will try to warn about syntax errors as soon as a line is entered and
|
63
55
|
only reset the buffer to the previous line. This means that you don't need to
|
64
56
|
loose any previous work:
|
@@ -112,29 +104,3 @@ Normal usage:
|
|
112
104
|
irb(#<#<Class:…>::A:…>):002:0> quit
|
113
105
|
=> nil
|
114
106
|
irb(main):007:0> quit
|
115
|
-
|
116
|
-
Or on MacRuby, try:
|
117
|
-
|
118
|
-
irb(main):001:0> win = NSWindow.alloc.initWithContentRect([200, 300, 250, 100],
|
119
|
-
irb(main):002:0> styleMask: NSTitledWindowMask|NSResizableWindowMask,
|
120
|
-
irb(main):003:0> backing: NSBackingStoreBuffered,
|
121
|
-
irb(main):004:0> defer: false)
|
122
|
-
=> #<NSWindow:0x20023eb00>
|
123
|
-
irb(main):005:0> win.orderFrontRegardless
|
124
|
-
=> #<NSWindow:0x20023eb00>
|
125
|
-
irb(main):006:0> win.title = 'Hello World'
|
126
|
-
=> "Hello World"
|
127
|
-
irb(main):007:0> bye = NSButton.alloc.initWithFrame([10, 10, 80, 80])
|
128
|
-
=> #<NSButton:0x20027f820>
|
129
|
-
irb(main):008:0> win.contentView.addSubview(bye)
|
130
|
-
=> #<NSView:0x200210320>
|
131
|
-
irb(main):009:0> bye.bezelStyle = NSThickerSquareBezelStyle
|
132
|
-
=> 4
|
133
|
-
irb(main):010:0> bye.title = 'Goodbye!'
|
134
|
-
=> "Goodbye!"
|
135
|
-
irb(main):011:0> bye.target = NSApp
|
136
|
-
=> #<NSApplication:0x200257fe0>
|
137
|
-
irb(main):012:0> bye.action = 'terminate:'
|
138
|
-
=> "terminate:"
|
139
|
-
irb(main):013:0> bye.sound = NSSound.soundNamed('Basso')
|
140
|
-
=> #<NSSound:0x200248b20>
|
data/Rakefile
CHANGED
@@ -53,20 +53,20 @@ namespace :macruby do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
begin
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
rescue LoadError
|
72
|
-
end
|
56
|
+
# begin
|
57
|
+
# require 'rubygems'
|
58
|
+
# require 'jeweler'
|
59
|
+
# require File.expand_path('../lib/irb/version', __FILE__)
|
60
|
+
# Jeweler::Tasks.new do |gemspec|
|
61
|
+
# gemspec.name = "dietrb"
|
62
|
+
# gemspec.version = IRB::VERSION::STRING
|
63
|
+
# gemspec.summary = gemspec.description = "IRB on a diet, for MacRuby / Ruby 1.9"
|
64
|
+
# gemspec.email = "eloy.de.enige@gmail.com"
|
65
|
+
# gemspec.homepage = "http://github.com/alloy/dietrb"
|
66
|
+
# gemspec.authors = ["Eloy Duran"]
|
67
|
+
#
|
68
|
+
# gemspec.required_ruby_version = ::Gem::Requirement.new("~> 1.9")
|
69
|
+
# gemspec.files.reject! { |file| file =~ /^(extensions|\.gitignore)/ }
|
70
|
+
# end
|
71
|
+
# rescue LoadError
|
72
|
+
# end
|
data/TODO
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
*
|
1
|
+
* Complete file paths in strings (for require etc).
|
2
|
+
* Write docs for using a as library. Probably right after creating a Cocoa client.
|
3
|
+
* Write a not useless README.
|
4
|
+
* Add specs for irb/driver/socket, and possibly for bin/dietrb.
|
2
5
|
* Configurable history file? (:HISTORY_FILE) Configurable number of saved history lines? (:SAVE_HISTORY)
|
3
|
-
* Make sure the following formatters work: hirb,
|
6
|
+
* Make sure the following formatters work: hirb, and looksee
|
4
7
|
* Make sure the majority of the utils in utility_belt work
|
5
8
|
* Possibly add copy-paste support as an ext
|
6
|
-
* Decide whether or not we need more control for colorizing which could be done with Ripper::SexpBuilder
|
data/bin/dietrb
CHANGED
@@ -39,18 +39,25 @@ module IRB
|
|
39
39
|
IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
|
40
40
|
|
41
41
|
if ARGV.empty?
|
42
|
-
driver
|
43
|
-
require
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
if driver == 'socket'
|
43
|
+
require "irb/driver/socket"
|
44
|
+
IRB::Driver.redirect_output! do
|
45
|
+
irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
driver ||= begin
|
49
|
+
require 'readline'
|
50
|
+
'readline'
|
51
|
+
rescue LoadError
|
52
|
+
'tty'
|
53
|
+
end
|
54
|
+
require "irb/driver/#{driver}"
|
55
|
+
irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
|
47
56
|
end
|
48
|
-
require "irb/driver/#{driver}"
|
49
|
-
irb(*IRB_CONTEXT_TOPLEVEL_ARGS)
|
50
57
|
else
|
51
58
|
path = ARGV.shift
|
52
59
|
context = IRB::Context.new(*IRB_CONTEXT_TOPLEVEL_ARGS)
|
53
60
|
File.open(path, 'r') { |f| f.each_line { |line| context.input_line(line) } }
|
54
61
|
end
|
55
62
|
end
|
56
|
-
end
|
63
|
+
end
|
data/dietrb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dietrb}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eloy Duran"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-28}
|
13
13
|
s.default_executable = %q{dietrb}
|
14
14
|
s.description = %q{IRB on a diet, for MacRuby / Ruby 1.9}
|
15
15
|
s.email = %q{eloy.de.enige@gmail.com}
|
@@ -37,7 +37,6 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/irb/ext/colorize.rb",
|
38
38
|
"lib/irb/ext/completion.rb",
|
39
39
|
"lib/irb/ext/history.rb",
|
40
|
-
"lib/irb/ext/macruby.rb",
|
41
40
|
"lib/irb/formatter.rb",
|
42
41
|
"lib/irb/source.rb",
|
43
42
|
"lib/irb/version.rb",
|
@@ -57,7 +56,7 @@ Gem::Specification.new do |s|
|
|
57
56
|
s.rdoc_options = ["--charset=UTF-8"]
|
58
57
|
s.require_paths = ["lib"]
|
59
58
|
s.required_ruby_version = Gem::Requirement.new("~> 1.9")
|
60
|
-
s.rubygems_version = %q{1.3.
|
59
|
+
s.rubygems_version = %q{1.3.7}
|
61
60
|
s.summary = %q{IRB on a diet, for MacRuby / Ruby 1.9}
|
62
61
|
s.test_files = [
|
63
62
|
"spec/context_spec.rb",
|
@@ -77,7 +76,7 @@ Gem::Specification.new do |s|
|
|
77
76
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
78
77
|
s.specification_version = 3
|
79
78
|
|
80
|
-
if Gem::Version.new(Gem::
|
79
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
81
80
|
else
|
82
81
|
end
|
83
82
|
else
|
data/lib/irb.rb
CHANGED
@@ -5,15 +5,12 @@
|
|
5
5
|
# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige@gmail.com>
|
6
6
|
|
7
7
|
require 'irb/context'
|
8
|
+
require 'irb/driver'
|
8
9
|
require 'irb/source'
|
9
10
|
require 'irb/version'
|
10
11
|
|
11
12
|
require 'irb/deprecated'
|
12
13
|
|
13
|
-
# if !ENV['SPECCING'] && defined?(RUBY_ENGINE) && RUBY_ENGINE == "macruby"
|
14
|
-
# require 'irb/ext/macruby'
|
15
|
-
# end
|
16
|
-
|
17
14
|
module IRB
|
18
15
|
class << self
|
19
16
|
# This is just here for so the ruby 1.9 IRB will seemingly work, but actually
|
@@ -26,4 +23,4 @@ module IRB
|
|
26
23
|
end
|
27
24
|
alias_method :setup, :start
|
28
25
|
end
|
29
|
-
end
|
26
|
+
end
|
data/lib/irb/context.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige@gmail.com>
|
6
6
|
|
7
7
|
require 'irb/formatter'
|
8
|
+
require 'irb/source'
|
8
9
|
|
9
10
|
module IRB
|
10
11
|
class Context
|
@@ -26,17 +27,24 @@ module IRB
|
|
26
27
|
def __evaluate__(source, file = __FILE__, line = __LINE__)
|
27
28
|
eval(source, @binding, file, line)
|
28
29
|
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
object_description = "`#{object.inspect}'"
|
33
|
+
object_description = "of class `#{object.class.name}'" if object_description.length > 32
|
34
|
+
"#<IRB::Context for object #{object_description}>"
|
35
|
+
end
|
36
|
+
alias_method :inspect, :to_s
|
29
37
|
|
30
38
|
def evaluate(source)
|
31
39
|
result = __evaluate__(source.to_s, '(irb)', @line - @source.buffer.size + 1)
|
32
40
|
unless result == IGNORE_RESULT
|
33
41
|
store_result(result)
|
34
|
-
|
42
|
+
output(formatter.result(result))
|
35
43
|
result
|
36
44
|
end
|
37
45
|
rescue Exception => e
|
38
46
|
store_exception(e)
|
39
|
-
|
47
|
+
output(formatter.exception(e))
|
40
48
|
end
|
41
49
|
|
42
50
|
# Returns whether or not the user wants to continue the current runloop.
|
@@ -56,7 +64,7 @@ module IRB
|
|
56
64
|
return false if @source.terminate?
|
57
65
|
|
58
66
|
if @source.syntax_error?
|
59
|
-
|
67
|
+
output(formatter.syntax_error(@line, @source.syntax_error))
|
60
68
|
@source.pop
|
61
69
|
elsif @source.code_block?
|
62
70
|
evaluate(@source)
|
@@ -67,12 +75,22 @@ module IRB
|
|
67
75
|
true
|
68
76
|
end
|
69
77
|
|
78
|
+
# Output is directed to the IRB::Driver.current driver’s output if a
|
79
|
+
# current driver is available. Otherwise it’s simply printed to $stdout.
|
80
|
+
def output(string)
|
81
|
+
if driver = IRB::Driver.current
|
82
|
+
driver.output.puts(string)
|
83
|
+
else
|
84
|
+
puts(string)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
70
88
|
def prompt
|
71
89
|
formatter.prompt(self)
|
72
90
|
end
|
73
91
|
|
74
92
|
def input_line(line)
|
75
|
-
|
93
|
+
output(formatter.prompt(self) + line)
|
76
94
|
process_line(line)
|
77
95
|
end
|
78
96
|
|
@@ -92,4 +110,4 @@ module IRB
|
|
92
110
|
@exception_assigner.call(exception)
|
93
111
|
end
|
94
112
|
end
|
95
|
-
end
|
113
|
+
end
|
data/lib/irb/driver.rb
CHANGED
@@ -18,6 +18,13 @@ module IRB
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
def redirect_output!(redirector = OutputRedirector.new)
|
23
|
+
before, $stdout = $stdout, redirector unless $stdout.is_a?(redirector.class)
|
24
|
+
yield
|
25
|
+
ensure
|
26
|
+
$stdout = before if before
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
class OutputRedirector
|
@@ -58,4 +65,4 @@ module IRB
|
|
58
65
|
end
|
59
66
|
end
|
60
67
|
end
|
61
|
-
end
|
68
|
+
end
|
data/lib/irb/driver/tty.rb
CHANGED
@@ -34,13 +34,11 @@ module IRB
|
|
34
34
|
# subclass thereof.
|
35
35
|
def run(context)
|
36
36
|
@context_stack << context
|
37
|
-
before, $stdout = $stdout, OutputRedirector.new unless $stdout.is_a?(OutputRedirector)
|
38
37
|
while line = consume
|
39
38
|
break unless context.process_line(line)
|
40
39
|
end
|
41
40
|
ensure
|
42
41
|
@context_stack.pop
|
43
|
-
$stdout = before if before
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
data/lib/irb/ext/completion.rb
CHANGED
@@ -59,6 +59,14 @@ module IRB
|
|
59
59
|
evaluate('local_variables').map(&:to_s)
|
60
60
|
end
|
61
61
|
|
62
|
+
def instance_variables
|
63
|
+
context.object.instance_variables.map(&:to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
def global_variables
|
67
|
+
super.map(&:to_s)
|
68
|
+
end
|
69
|
+
|
62
70
|
def instance_methods
|
63
71
|
context.object.methods.map(&:to_s)
|
64
72
|
end
|
@@ -81,11 +89,10 @@ module IRB
|
|
81
89
|
call = (source[-1,1] == '.')
|
82
90
|
receiver = source = source[0..-2] if call
|
83
91
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
92
|
+
# root node:
|
93
|
+
# [:program, [:stmts_add, [:stmts_new], [x, …]]]
|
94
|
+
# ^
|
95
|
+
if (sexp = Ripper::SexpBuilder.new(source).parse) && root = sexp[1][2]
|
89
96
|
# [:call, [:hash, nil], :".", [:@ident, x, …]]
|
90
97
|
if root[TYPE] == :call
|
91
98
|
call = true
|
@@ -105,11 +112,14 @@ module IRB
|
|
105
112
|
end
|
106
113
|
end
|
107
114
|
|
108
|
-
if call
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
115
|
+
result = if call
|
116
|
+
if m = (methods || methods_of_object(root))
|
117
|
+
format_methods(receiver, m, filter)
|
118
|
+
end
|
119
|
+
else
|
120
|
+
match_methods_vars_or_consts_in_scope(root)
|
121
|
+
end
|
122
|
+
result.sort.uniq if result
|
113
123
|
end
|
114
124
|
end
|
115
125
|
|
@@ -126,11 +136,13 @@ module IRB
|
|
126
136
|
def match_methods_vars_or_consts_in_scope(symbol)
|
127
137
|
var = symbol[VALUE]
|
128
138
|
filter = var[VALUE]
|
129
|
-
case var[TYPE]
|
139
|
+
result = case var[TYPE]
|
130
140
|
when :@ident
|
131
141
|
local_variables + instance_methods + RESERVED_DOWNCASE_WORDS
|
142
|
+
when :@ivar
|
143
|
+
instance_variables
|
132
144
|
when :@gvar
|
133
|
-
global_variables
|
145
|
+
global_variables
|
134
146
|
when :@const
|
135
147
|
if symbol[TYPE] == :top_const_ref
|
136
148
|
filter = "::#{filter}"
|
@@ -138,7 +150,8 @@ module IRB
|
|
138
150
|
else
|
139
151
|
constants + RESERVED_UPCASE_WORDS
|
140
152
|
end
|
141
|
-
end
|
153
|
+
end
|
154
|
+
(result && filter) ? result.grep(/^#{Regexp.quote(filter)}/) : result
|
142
155
|
end
|
143
156
|
|
144
157
|
def format_methods(receiver, methods, filter)
|
@@ -174,8 +187,10 @@ module IRB
|
|
174
187
|
case type
|
175
188
|
when :@ident
|
176
189
|
evaluate(name).methods if local_variables.include?(name)
|
190
|
+
when :@ivar
|
191
|
+
evaluate(name).methods if instance_variables.include?(name)
|
177
192
|
when :@gvar
|
178
|
-
eval(name).methods if global_variables.include?(name
|
193
|
+
eval(name).methods if global_variables.include?(name)
|
179
194
|
when :@const
|
180
195
|
evaluate(name).methods if constants.include?(name)
|
181
196
|
end
|
data/lib/irb/ext/history.rb
CHANGED
data/lib/irb/source.rb
CHANGED
@@ -72,7 +72,7 @@ module IRB
|
|
72
72
|
def initialize(source)
|
73
73
|
super
|
74
74
|
@level = 0
|
75
|
-
@code_block = !parse.nil?
|
75
|
+
@code_block = !parse.nil? && !@in_string && !@in_regexp && !@in_array
|
76
76
|
end
|
77
77
|
|
78
78
|
# Returns the code block indentation level.
|
@@ -183,6 +183,66 @@ module IRB
|
|
183
183
|
@level -= 1
|
184
184
|
super
|
185
185
|
end
|
186
|
+
|
187
|
+
def on_tstring_beg(token)
|
188
|
+
@in_string = token
|
189
|
+
@level += 1
|
190
|
+
super
|
191
|
+
end
|
192
|
+
|
193
|
+
def on_tstring_end(token)
|
194
|
+
if @in_string && tokens_match?(@in_string, token)
|
195
|
+
@in_string = nil
|
196
|
+
@level -= 1
|
197
|
+
end
|
198
|
+
super
|
199
|
+
end
|
200
|
+
|
201
|
+
def on_qwords_beg(token)
|
202
|
+
@in_array = token.strip
|
203
|
+
@level += 1
|
204
|
+
super
|
205
|
+
end
|
206
|
+
alias_method :on_words_beg, :on_qwords_beg
|
207
|
+
|
208
|
+
def on_words_sep(token)
|
209
|
+
if tokens_match?(@in_array, token)
|
210
|
+
@in_array = false
|
211
|
+
@level -= 1
|
212
|
+
end
|
213
|
+
super
|
214
|
+
end
|
215
|
+
|
216
|
+
def on_regexp_beg(token)
|
217
|
+
@in_regexp = token
|
218
|
+
@level += 1
|
219
|
+
super
|
220
|
+
end
|
221
|
+
|
222
|
+
def on_regexp_end(token)
|
223
|
+
token_without_regexp_options = token[0,1]
|
224
|
+
if tokens_match?(@in_regexp, token_without_regexp_options)
|
225
|
+
@in_regexp = false
|
226
|
+
@level -= 1
|
227
|
+
end
|
228
|
+
super
|
229
|
+
end
|
230
|
+
|
231
|
+
def tokens_match?(open_token, close_token)
|
232
|
+
last_char_open_token = open_token[-1, 1]
|
233
|
+
last_char_close_token = close_token[-1, 1]
|
234
|
+
if last_char_open_token == last_char_close_token
|
235
|
+
true
|
236
|
+
else
|
237
|
+
case last_char_open_token
|
238
|
+
when '{' then last_char_close_token == '}'
|
239
|
+
when '(' then last_char_close_token == ')'
|
240
|
+
when '[' then last_char_close_token == ']'
|
241
|
+
else
|
242
|
+
false
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
186
246
|
end
|
187
247
|
end
|
188
248
|
end
|
data/lib/irb/version.rb
CHANGED
data/spec/context_spec.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
require File.expand_path('../spec_helper', __FILE__)
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
|
-
class TestProcessor
|
5
|
-
def input(s)
|
6
|
-
s * 2
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
main = self
|
11
5
|
|
12
6
|
describe "IRB::Context" do
|
13
7
|
before do
|
8
|
+
@output = setup_current_driver.output
|
14
9
|
@context = IRB::Context.new(main)
|
15
10
|
@context.extend(OutputStubMixin)
|
16
11
|
end
|
@@ -38,12 +33,25 @@ describe "IRB::Context" do
|
|
38
33
|
it "does not use the same binding copy of the top level object" do
|
39
34
|
lambda { eval("x", @context.binding) }.should raise_error(NameError)
|
40
35
|
end
|
36
|
+
|
37
|
+
it "prints to the output object of the current driver" do
|
38
|
+
@context.output("croque monsieur")
|
39
|
+
@output.printed.should == "croque monsieur\n"
|
40
|
+
@context.printed.should == ""
|
41
|
+
end
|
42
|
+
|
43
|
+
it "prints as normal when no current driver is available" do
|
44
|
+
IRB::Driver.current = nil
|
45
|
+
@context.output("croque monsieur")
|
46
|
+
@output.printed.should == ""
|
47
|
+
@context.printed.should == "croque monsieur\n"
|
48
|
+
end
|
41
49
|
end
|
42
50
|
|
43
51
|
describe "IRB::Context, when evaluating source" do
|
44
52
|
before do
|
53
|
+
@output = setup_current_driver.output
|
45
54
|
@context = IRB::Context.new(main)
|
46
|
-
@context.extend(OutputStubMixin)
|
47
55
|
IRB.formatter = IRB::Formatter.new
|
48
56
|
end
|
49
57
|
|
@@ -53,7 +61,7 @@ describe "IRB::Context, when evaluating source" do
|
|
53
61
|
|
54
62
|
it "prints the result" do
|
55
63
|
@context.evaluate("Hash[:foo, :foo]")
|
56
|
-
@
|
64
|
+
@output.printed.should == "=> {:foo=>:foo}\n"
|
57
65
|
end
|
58
66
|
|
59
67
|
it "assigns the result to the local variable `_'" do
|
@@ -84,31 +92,31 @@ describe "IRB::Context, when evaluating source" do
|
|
84
92
|
|
85
93
|
it "prints the exception that occurs" do
|
86
94
|
@context.evaluate("DoesNotExist")
|
87
|
-
@
|
95
|
+
@output.printed.should =~ /^NameError:.+DoesNotExist/
|
88
96
|
end
|
89
97
|
|
90
98
|
it "uses the line number of the *first* line in the buffer, for the line parameter of eval" do
|
91
99
|
@context.process_line("DoesNotExist")
|
92
|
-
@
|
100
|
+
@output.printed.should =~ /\(irb\):1:in/
|
93
101
|
@context.process_line("class A")
|
94
102
|
@context.process_line("DoesNotExist")
|
95
103
|
@context.process_line("end")
|
96
|
-
@
|
104
|
+
@output.printed.should =~ /\(irb\):3:in.+\(irb\):2:in/m
|
97
105
|
end
|
98
106
|
|
99
107
|
it "ignores the result if it's IRB::Context::IGNORE_RESULT" do
|
100
108
|
@context.evaluate(":bananas")
|
101
109
|
@context.evaluate("IRB::Context::IGNORE_RESULT").should == nil
|
102
|
-
@
|
110
|
+
@output.printed.should == "=> :bananas\n"
|
103
111
|
@context.evaluate("_").should == :bananas
|
104
112
|
end
|
105
113
|
end
|
106
114
|
|
107
115
|
describe "IRB::Context, when receiving input" do
|
108
116
|
before do
|
117
|
+
@output = setup_current_driver.output
|
109
118
|
@context = IRB::Context.new(main)
|
110
119
|
@context.extend(InputStubMixin)
|
111
|
-
@context.extend(OutputStubMixin)
|
112
120
|
end
|
113
121
|
|
114
122
|
it "adds the received code to the source buffer" do
|
@@ -147,7 +155,7 @@ describe "IRB::Context, when receiving input" do
|
|
147
155
|
@context.process_line(" };")
|
148
156
|
|
149
157
|
@context.source.to_s.should == "def foo"
|
150
|
-
@
|
158
|
+
@output.printed.should == "SyntaxError: compile error\n(irb):2: syntax error, unexpected '}'\n"
|
151
159
|
end
|
152
160
|
|
153
161
|
it "returns whether or not the runloop should continue, but only if the level is 0" do
|
@@ -161,6 +169,6 @@ describe "IRB::Context, when receiving input" do
|
|
161
169
|
it "inputs a line to be processed" do
|
162
170
|
expected = "#{@context.formatter.prompt(@context)}2 * 21\n=> 42\n"
|
163
171
|
@context.input_line("2 * 21")
|
164
|
-
@
|
172
|
+
@output.printed.should == expected
|
165
173
|
end
|
166
174
|
end
|
data/spec/ext/completion_spec.rb
CHANGED
@@ -58,6 +58,11 @@ describe "IRB::Completion" do
|
|
58
58
|
complete('foo.').should include('foo.singleton_method')
|
59
59
|
end
|
60
60
|
|
61
|
+
it "matches as an instance variable" do
|
62
|
+
@context.__evaluate__('@an_instance_variable = ::CompletionStub.new')
|
63
|
+
complete('@an_instance_variable.').should == imethods(::CompletionStub, '@an_instance_variable')
|
64
|
+
end
|
65
|
+
|
61
66
|
it "matches as a global variable" do
|
62
67
|
complete('$a_completion_stub.').should == imethods(::CompletionStub, '$a_completion_stub')
|
63
68
|
end
|
@@ -193,9 +198,10 @@ describe "IRB::Completion" do
|
|
193
198
|
end
|
194
199
|
|
195
200
|
it "filters the methods, of the variable receiver, by the given method name" do
|
196
|
-
@context.__evaluate__('foo = ::CompletionStub.new')
|
201
|
+
@context.__evaluate__('foo = @an_instance_variable = ::CompletionStub.new')
|
197
202
|
complete('foo.an_im').should == %w{ foo.an_imethod }
|
198
203
|
complete('$a_completion_stub.an_im').should == %w{ $a_completion_stub.an_imethod }
|
204
|
+
complete('@an_instance_variable.an_im').should == %w{ @an_instance_variable.an_imethod }
|
199
205
|
# TODO: fix
|
200
206
|
# complete('CompletionStub.a_sing').should == %w{ CompletionStub.a_singleton_method }
|
201
207
|
end
|
@@ -204,7 +210,7 @@ describe "IRB::Completion" do
|
|
204
210
|
|
205
211
|
describe "when *not* doing a method call on an explicit receiver" do
|
206
212
|
before do
|
207
|
-
@context.__evaluate__("a_local_variable = :ok")
|
213
|
+
@context.__evaluate__("a_local_variable = @an_instance_variable = :ok")
|
208
214
|
end
|
209
215
|
|
210
216
|
it "matches local variables" do
|
@@ -219,6 +225,10 @@ describe "IRB::Completion" do
|
|
219
225
|
complete("a_loc").should == %w{ a_local_method a_local_variable }
|
220
226
|
end
|
221
227
|
|
228
|
+
it "matches instance variables" do
|
229
|
+
complete("@an_inst").should == %w{ @an_instance_variable }
|
230
|
+
end
|
231
|
+
|
222
232
|
it "matches global variables" do
|
223
233
|
complete("$a_completion_s").should == %w{ $a_completion_stub }
|
224
234
|
end
|
@@ -238,4 +248,9 @@ describe "IRB::Completion" do
|
|
238
248
|
complete(word[0..-2]).should include(word)
|
239
249
|
end
|
240
250
|
end
|
241
|
-
|
251
|
+
|
252
|
+
it "does not crash when trying to complete garbage" do
|
253
|
+
complete("/").should == nil
|
254
|
+
complete("./Rake").should == nil
|
255
|
+
end
|
256
|
+
end
|
data/spec/formatter_spec.rb
CHANGED
@@ -69,7 +69,7 @@ describe "IRB::Formatter" do
|
|
69
69
|
def object.inspect; @inspected = true; "Never called!"; end
|
70
70
|
def object.__id__; 2158110700; end
|
71
71
|
|
72
|
-
@formatter.result(object).should == "=>
|
72
|
+
@formatter.result(object).should == "=> #<#{object.class.name}:0x101444fd8>"
|
73
73
|
object.instance_variable_get(:@inspected).should_not == true
|
74
74
|
end
|
75
75
|
|
data/spec/source_spec.rb
CHANGED
@@ -140,11 +140,14 @@ describe "IRB::Source::Reflector" do
|
|
140
140
|
it "returns whether or not the source contains a syntax error, except a code block not ending" do
|
141
141
|
reflect("def;").syntax_error?.should == true
|
142
142
|
reflect("def;").syntax_error?.should == true
|
143
|
+
reflect("{ [ } ]").syntax_error?.should == true
|
143
144
|
reflect("def foo").syntax_error?.should == false
|
144
145
|
reflect("class A; }").syntax_error?.should == true
|
145
146
|
reflect("class A; {" ).syntax_error?.should == false
|
147
|
+
reflect("class A; def {").syntax_error?.should == true
|
146
148
|
reflect("class A def foo").syntax_error?.should == true
|
147
149
|
reflect("class A; def foo" ).syntax_error?.should == false
|
150
|
+
reflect("def foo; {; end; }").syntax_error?.should == true
|
148
151
|
end
|
149
152
|
|
150
153
|
it "returns the actual syntax error message if one occurs" do
|
@@ -185,12 +188,72 @@ describe "IRB::Source::Reflector" do
|
|
185
188
|
it "correctly increases and decreases the code block indentation level for literals" do
|
186
189
|
[
|
187
190
|
["lambda { |x|", "}"],
|
188
|
-
["{", "}"],
|
189
|
-
[
|
190
|
-
|
191
|
+
["{ :foo => ", " :bar }"],
|
192
|
+
["[ 1", ", 2 ]"],
|
193
|
+
|
194
|
+
["'", "'"],
|
195
|
+
["' ", " '"],
|
196
|
+
["'foo ", " bar'"],
|
197
|
+
["' foo ", " bar '"],
|
198
|
+
|
199
|
+
['"', '"'],
|
200
|
+
['" ', ' "'],
|
201
|
+
['"foo ', ' bar"'],
|
202
|
+
['" foo ', ' bar "'],
|
203
|
+
|
204
|
+
["%{", "}"],
|
205
|
+
["%{ ", " }"],
|
206
|
+
["%{foo ", " bar}"],
|
207
|
+
["%{ foo ", " bar }"],
|
208
|
+
["%(foo ", " bar)"],
|
209
|
+
["%( foo ", " bar )"],
|
210
|
+
["%[ foo ", " bar ]"],
|
211
|
+
["%[foo ", " bar]"],
|
212
|
+
|
213
|
+
#["%w{ ", " }"], fails on 1.9
|
214
|
+
["%w{foo ", " bar}"],
|
215
|
+
["%w{ foo ", " bar }"],
|
216
|
+
["%w(foo ", " bar)"],
|
217
|
+
["%w( foo ", " bar )"],
|
218
|
+
["%w[foo ", " bar]"],
|
219
|
+
["%w[ foo ", " bar ]"],
|
220
|
+
|
221
|
+
["%W{foo ", " bar}"],
|
222
|
+
["%W{ foo ", " bar }"],
|
223
|
+
["%W(foo ", " bar)"],
|
224
|
+
["%W( foo ", " bar )"],
|
225
|
+
["%W[foo ", " bar]"],
|
226
|
+
["%W[ foo ", " bar ]"],
|
227
|
+
|
228
|
+
["%r{foo ", " bar}"],
|
229
|
+
["%r{ foo ", " bar }"],
|
230
|
+
["%r{ foo ", " bar}i"],
|
231
|
+
["%r(foo ", " bar)"],
|
232
|
+
["%r( foo ", " bar )"],
|
233
|
+
["%r( foo ", " bar)i"],
|
234
|
+
["%r[foo ", " bar]"],
|
235
|
+
["%r[ foo ", " bar ]"],
|
236
|
+
["%r[ foo ", " bar]i"],
|
237
|
+
|
238
|
+
["/foo ", " bar/"],
|
239
|
+
["/ foo ", " bar /"],
|
240
|
+
["/ foo ", " bar/iu"], # macruby ticket 965
|
191
241
|
].each do |open, close|
|
192
242
|
reflect(open).level.should == 1
|
243
|
+
reflect(open).code_block?.should == false
|
193
244
|
reflect("#{open}\n#{close}").level.should == 0
|
245
|
+
reflect("#{open}\n#{close}").code_block?.should == true
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
it "handles cases that contain backspaces" do
|
250
|
+
[
|
251
|
+
["%{", "\b"],
|
252
|
+
["%w{", "\b"],
|
253
|
+
["%r{", "\b"],
|
254
|
+
].each do |open, close|
|
255
|
+
reflect("#{open}\n#{close}").level.should == 1
|
256
|
+
reflect("#{open}\n#{close}").code_block?.should == false
|
194
257
|
end
|
195
258
|
end
|
196
259
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dietrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Eloy Duran
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-10-28 00:00:00 +02:00
|
13
19
|
default_executable: dietrb
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -41,7 +47,6 @@ files:
|
|
41
47
|
- lib/irb/ext/colorize.rb
|
42
48
|
- lib/irb/ext/completion.rb
|
43
49
|
- lib/irb/ext/history.rb
|
44
|
-
- lib/irb/ext/macruby.rb
|
45
50
|
- lib/irb/formatter.rb
|
46
51
|
- lib/irb/source.rb
|
47
52
|
- lib/irb/version.rb
|
@@ -66,21 +71,28 @@ rdoc_options:
|
|
66
71
|
require_paths:
|
67
72
|
- lib
|
68
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
69
75
|
requirements:
|
70
76
|
- - ~>
|
71
77
|
- !ruby/object:Gem::Version
|
78
|
+
hash: 29
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 9
|
72
82
|
version: "1.9"
|
73
|
-
version:
|
74
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
75
85
|
requirements:
|
76
86
|
- - ">="
|
77
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
78
91
|
version: "0"
|
79
|
-
version:
|
80
92
|
requirements: []
|
81
93
|
|
82
94
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.7
|
84
96
|
signing_key:
|
85
97
|
specification_version: 3
|
86
98
|
summary: IRB on a diet, for MacRuby / Ruby 1.9
|
data/lib/irb/ext/macruby.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# MacRuby implementation of IRB.
|
2
|
-
#
|
3
|
-
# This file is covered by the Ruby license. See COPYING for more details.
|
4
|
-
#
|
5
|
-
# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige@gmail.com>
|
6
|
-
|
7
|
-
framework 'AppKit'
|
8
|
-
|
9
|
-
module IRB
|
10
|
-
class Context
|
11
|
-
alias_method :_run, :run
|
12
|
-
|
13
|
-
def run
|
14
|
-
if NSApplication.sharedApplication.running?
|
15
|
-
_run
|
16
|
-
else
|
17
|
-
Thread.new do
|
18
|
-
_run
|
19
|
-
NSApplication.sharedApplication.terminate(self)
|
20
|
-
end
|
21
|
-
NSApplication.sharedApplication.run
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|