[macruby-changes] [4693] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 04:00:39 PDT 2010
Revision: 4693
http://trac.macosforge.org/projects/ruby/changeset/4693
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 04:00:39 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Fix syntax error messages so that it never shows the underscore variable.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/TODO
DietRB/trunk/lib/irb/context.rb
Added Paths:
-----------
DietRB/trunk/spec/regression/
DietRB/trunk/spec/regression/context_spec.rb
Modified: DietRB/trunk/TODO
===================================================================
--- DietRB/trunk/TODO 2010-10-08 11:00:27 UTC (rev 4692)
+++ DietRB/trunk/TODO 2010-10-08 11:00:39 UTC (rev 4693)
@@ -1,5 +1,3 @@
-* Make stdin work
-* Fix error message resulting of syntax like: require 'date;
* Make sure the following formatters work: hirb, awesome_print, and looksee
* Make sure the majority of the utils in utility_belt work
* Possibly add copy-paste support as an ext
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 11:00:27 UTC (rev 4692)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 11:00:39 UTC (rev 4693)
@@ -34,6 +34,7 @@
@line = 1
clear_buffer
+ @underscore_assigner = __evaluate__("_ = nil; proc { |val| _ = val }")
@processors = self.class.processors.map { |processor| processor.new(self) }
end
@@ -42,7 +43,8 @@
end
def evaluate(source)
- result = __evaluate__("_ = (#{source})", '(irb)', @line - @source.buffer.size + 1)
+ result = __evaluate__(source.to_s, '(irb)', @line - @source.buffer.size + 1)
+ store_result(result)
puts formatter.result(result)
result
rescue Exception => e
@@ -108,6 +110,10 @@
def clear_buffer
@source = Source.new
end
+
+ def store_result(result)
+ @underscore_assigner.call(result)
+ end
end
end
Added: DietRB/trunk/spec/regression/context_spec.rb
===================================================================
--- DietRB/trunk/spec/regression/context_spec.rb (rev 0)
+++ DietRB/trunk/spec/regression/context_spec.rb 2010-10-08 11:00:39 UTC (rev 4693)
@@ -0,0 +1,16 @@
+require File.expand_path('../../spec_helper', __FILE__)
+
+main = self
+
+describe "IRB::Context, when evaluating source" do
+ before do
+ @context = IRB::Context.new(main)
+ def @context.printed; @printed ||= '' end
+ def @context.puts(string); printed << "#{string}\n" end
+ end
+
+ it "does not assign the result to the `_' variable in one go, so it doesn't show up in a syntax error" do
+ @context.evaluate("'banana;")
+ @context.printed.should.not.include "_ = ('banana;)"
+ end
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/6772265f/attachment.html>
More information about the macruby-changes
mailing list