[macruby-changes] [4856] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 31 15:51:45 PDT 2010
Revision: 4856
http://trac.macosforge.org/projects/ruby/changeset/4856
Author: eloy.de.enige at gmail.com
Date: 2010-10-31 15:51:43 -0700 (Sun, 31 Oct 2010)
Log Message:
-----------
Move auto_indent option to IRB::Formatter
Modified Paths:
--------------
DietRB/trunk/TODO
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/lib/irb/driver/readline.rb
DietRB/trunk/lib/irb/driver/tty.rb
DietRB/trunk/lib/irb/ext/colorize.rb
DietRB/trunk/spec/context_spec.rb
DietRB/trunk/spec/driver/readline_spec.rb
DietRB/trunk/spec/driver/tty_spec.rb
Modified: DietRB/trunk/TODO
===================================================================
--- DietRB/trunk/TODO 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/TODO 2010-10-31 22:51:43 UTC (rev 4856)
@@ -1,4 +1,4 @@
-* Move auto_indent option to formatter
+* Add auto_indent option to bin
* Complete file paths in strings (for require etc).
* Write docs for using a as library. Probably right after creating a Cocoa client.
* Write a not useless README.
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -98,8 +98,8 @@
end
end
- def prompt(indent = false)
- formatter.prompt(self, indent)
+ def prompt(ignore_auto_indent = false)
+ formatter.prompt(self, ignore_auto_indent)
end
def input_line(line)
Modified: DietRB/trunk/lib/irb/driver/readline.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/readline.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/lib/irb/driver/readline.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -15,7 +15,7 @@
end
def readline
- source = ::Readline.readline(prompt, true)
+ source = ::Readline.readline(context.prompt, true)
IRB::History.input(source)
source
end
Modified: DietRB/trunk/lib/irb/driver/tty.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/tty.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/lib/irb/driver/tty.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -4,7 +4,6 @@
module Driver
class TTY
attr_reader :input, :output, :context_stack
- attr_accessor :auto_indent # TODO: this should probably go to a more global config, which means we shouldn't completely deprecate the CONF
def initialize(input = $stdin, output = $stdout)
@input = input
@@ -16,12 +15,8 @@
@context_stack.last
end
- def prompt
- context.prompt(@auto_indent)
- end
-
def readline
- @output.print(prompt)
+ @output.print(context.prompt)
@input.gets
end
Modified: DietRB/trunk/lib/irb/ext/colorize.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/colorize.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/lib/irb/ext/colorize.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -169,7 +169,7 @@
Ripper.lex(str).map { |_, type, token| colorize_token(type, token) }.join
end
- def prompt(context, indent = false)
+ def prompt(context, ignore_auto_indent = false)
colorize_token(:prompt, super)
end
Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -117,7 +117,12 @@
@output = setup_current_driver.output
@context = IRB::Context.new(main)
@context.extend(InputStubMixin)
+ @context.formatter.auto_indent = true
end
+
+ after do
+ @context.formatter.auto_indent = false
+ end
it "adds the received code to the source buffer" do
@context.process_line("def foo")
@@ -125,20 +130,14 @@
@context.source.to_s.should == "def foo\n p :ok"
end
- it "yields the line if it changed after reindenting" do
+ it "yields the line if it changed, *after* reindenting" do
line = nil
@context.process_line("def foo") { |x| line = x }
line.should == nil
@context.process_line("p :ok") { |x| line = x }
line.should == " p :ok"
end
-
- it "clears the source buffer" do
- @context.process_line("def foo")
- @context.clear_buffer
- @context.source.to_s.should == ""
- end
-
+
it "increases the current line number, *after* yielding the new re-indented line" do
@context.line.should == 1
@context.process_line("def foo")
Modified: DietRB/trunk/spec/driver/readline_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/readline_spec.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/spec/driver/readline_spec.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -44,6 +44,10 @@
Readline.clear_printed!
end
+ after do
+ @context.formatter.auto_indent = false
+ end
+
it "is a subclass of IRB::Driver::TTY" do
IRB::Driver::Readline.superclass.should == IRB::Driver::TTY
end
@@ -58,23 +62,23 @@
end
it "reads a line through the Readline module" do
- Readline.stub_input "nom nom nom"
+ Readline.stub_input("nom nom nom")
@driver.readline.should == "nom nom nom"
end
it "prints a prompt" do
- @context.source << "def foo"
- Readline.stub_input "nom nom nom"
+ @context.process_line("def foo")
+ Readline.stub_input("nom nom nom")
@driver.readline
Readline.printed.should == @context.prompt
end
it "prints a prompt with indentation if it's configured" do
- @driver.auto_indent = true
- @context.source << "def foo"
- Readline.stub_input "nom nom nom"
+ @context.formatter.auto_indent = true
+ @context.process_line("def foo")
+ Readline.stub_input("nom nom nom")
@driver.readline
- Readline.printed.should == @context.prompt(true)
+ Readline.printed[-2,2].should == " "
end
it "tells the Readline module to use the history" do
Modified: DietRB/trunk/spec/driver/tty_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/tty_spec.rb 2010-10-31 22:51:32 UTC (rev 4855)
+++ DietRB/trunk/spec/driver/tty_spec.rb 2010-10-31 22:51:43 UTC (rev 4856)
@@ -7,24 +7,28 @@
@context = IRB::Context.new(Object.new)
@driver.context_stack << @context
end
-
+
+ after do
+ @context.formatter.auto_indent = false
+ end
+
it "prints the prompt and reads a line of input" do
- @context.source << "def foo"
- @driver.input.stub_input "calzone"
+ @context.process_line("def foo")
+ @driver.input.stub_input("calzone")
@driver.readline.should == "calzone"
@driver.output.printed.should == @context.prompt
end
it "prints a prompt with indentation if it's configured" do
- @driver.auto_indent = true
- @context.source << "def foo"
- @driver.input.stub_input "calzone"
+ @context.formatter.auto_indent = true
+ @context.process_line("def foo")
+ @driver.input.stub_input("calzone")
@driver.readline
- @driver.output.printed.should == @context.prompt(true)
+ @driver.output.printed[-2,2].should == " "
end
it "consumes input" do
- @driver.input.stub_input "calzone"
+ @driver.input.stub_input("calzone")
@driver.consume.should == "calzone"
end
@@ -45,7 +49,7 @@
it "makes the given context the current one, for this driver, for the duration of the runloop" do
$from_context = nil
- @driver.input.stub_input "$from_context = IRB::Driver.current.context"
+ @driver.input.stub_input("$from_context = IRB::Driver.current.context")
@driver.run(@context)
$from_context.should == @context
IRB::Driver.current.context.should == nil
@@ -53,7 +57,7 @@
it "feeds input into a given context" do
$from_context = false
- @driver.input.stub_input "$from_context = true", "exit"
+ @driver.input.stub_input("$from_context = true", "exit")
@driver.run(@context)
$from_context.should == true
end
@@ -61,7 +65,7 @@
it "makes sure there's a global output redirector while running a context" do
before = $stdout
$from_context = nil
- @driver.input.stub_input "$from_context = $stdout", "exit"
+ @driver.input.stub_input("$from_context = $stdout", "exit")
@driver.run(@context)
$from_context.class == IRB::Driver::OutputRedirector
$stdout.should == before
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101031/46ec5b04/attachment.html>
More information about the macruby-changes
mailing list