[macruby-changes] [4649] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:54:01 PDT 2010


Revision: 4649
          http://trac.macosforge.org/projects/ruby/changeset/4649
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:54:00 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Reset the buffer when an Interrupt signal is received.

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/lib/irb/context.rb
    DietRB/trunk/lib/irb/source.rb
    DietRB/trunk/spec/context_spec.rb
    DietRB/trunk/spec/source_spec.rb

Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb	2010-10-08 10:53:50 UTC (rev 4648)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-08 10:54:00 UTC (rev 4649)
@@ -37,6 +37,9 @@
     
     def readline
       Readline.readline(formatter.prompt(self), true)
+    rescue Interrupt
+      clear_buffer
+      ""
     end
     
     def run

Modified: DietRB/trunk/lib/irb/source.rb
===================================================================
--- DietRB/trunk/lib/irb/source.rb	2010-10-08 10:53:50 UTC (rev 4648)
+++ DietRB/trunk/lib/irb/source.rb	2010-10-08 10:54:00 UTC (rev 4649)
@@ -10,8 +10,11 @@
     
     # Adds a source line to the buffer and flushes the cached reflection.
     def <<(source)
-      @reflection = nil
-      @buffer << source.chomp
+      source = source.strip
+      unless source.empty?
+        @reflection = nil
+        @buffer << source
+      end
     end
     
     # Removes the last line from the buffer and flushes the cached reflection.

Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb	2010-10-08 10:53:50 UTC (rev 4648)
+++ DietRB/trunk/spec/context_spec.rb	2010-10-08 10:54:00 UTC (rev 4649)
@@ -1,18 +1,21 @@
 require File.expand_path('../spec_helper', __FILE__)
 require 'tempfile'
 
-class << Readline
-  attr_reader :received
-  
-  def stub_input(*input)
-    @input = input
+def stub_Readline
+  class << Readline
+    attr_reader :received
+    
+    def stub_input(*input)
+      @input = input
+    end
+    
+    def readline(prompt, history)
+      @received = [prompt, history]
+      @input.shift
+    end
   end
-  
-  def readline(prompt, history)
-    @received = [prompt, history]
-    @input.shift
-  end
 end
+stub_Readline
 
 main = self
 
@@ -122,6 +125,24 @@
     @context.source.to_s.should == "def foo\np :ok"
   end
   
+  it "clears the source buffer when an Interrupt signal is received" do
+    begin
+      @context.process_line("def foo")
+      
+      def Readline.readline(*args)
+        def Readline.readline(*args)
+          nil
+        end
+        raise Interrupt
+      end
+      
+      lambda { @context.run }.should.not.raise Interrupt
+      @context.source.to_s.should == ""
+    ensure
+      stub_Readline
+    end
+  end
+  
   it "increases the current line number" do
     @context.line.should == 1
     @context.process_line("def foo")

Modified: DietRB/trunk/spec/source_spec.rb
===================================================================
--- DietRB/trunk/spec/source_spec.rb	2010-10-08 10:53:50 UTC (rev 4648)
+++ DietRB/trunk/spec/source_spec.rb	2010-10-08 10:54:00 UTC (rev 4649)
@@ -19,6 +19,12 @@
     @source.buffer.should == %w{ foo bar }
   end
   
+  it "ignores empty strings" do
+    @source << ""
+    @source << " \n"
+    @source.buffer.should == []
+  end
+  
   it "removes the last line from the buffer" do
     @source << "foo\n"
     @source << "bar\r\n"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/34c0812b/attachment-0001.html>


More information about the macruby-changes mailing list