[macruby-changes] [4656] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:55:03 PDT 2010
Revision: 4656
http://trac.macosforge.org/projects/ruby/changeset/4656
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:55:01 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Use the context line ivar to give to eval as a more useful line number.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/spec/context_spec.rb
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 10:54:52 UTC (rev 4655)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 10:55:01 UTC (rev 4656)
@@ -23,12 +23,12 @@
clear_buffer
end
- def __evaluate__(source)
- eval(source, @binding)
+ def __evaluate__(source, file = __FILE__, line = __LINE__)
+ eval(source, @binding, file, line)
end
def evaluate(source)
- result = __evaluate__("_ = (#{source})")
+ result = __evaluate__("_ = (#{source})", '(irb)', @line - @source.buffer.size + 1)
puts formatter.result(result)
result
rescue Exception => e
Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb 2010-10-08 10:54:52 UTC (rev 4655)
+++ DietRB/trunk/spec/context_spec.rb 2010-10-08 10:55:01 UTC (rev 4656)
@@ -63,6 +63,7 @@
before do
@context = IRB::Context.new(main)
def @context.puts(string); @printed = string; end
+ def @context.printed; @printed; end
end
it "evaluates code with the object's binding" do
@@ -96,9 +97,17 @@
it "prints the exception that occurs" do
@context.evaluate("DoesNotExist")
- printed = @context.instance_variable_get(:@printed)
- printed.should.match /^NameError:.+DoesNotExist/
+ @context.printed.should.match /^NameError:.+DoesNotExist/
end
+
+ it "uses the line number of the *first* line in the buffer, for the line parameter of eval" do
+ @context.process_line("DoesNotExist")
+ @context.printed.should.match /\(irb\):1:in/
+ @context.process_line("class A")
+ @context.process_line("DoesNotExist")
+ @context.process_line("end")
+ @context.printed.should.match /\(irb\):3:in.+\(irb\):2:in/m
+ end
end
describe "IRB::Context, when receiving input" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/32dab1b7/attachment.html>
More information about the macruby-changes
mailing list