[macruby-changes] [4598] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 03:46:23 PDT 2010
Revision: 4598
http://trac.macosforge.org/projects/ruby/changeset/4598
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 03:46:22 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Increase and decrease indentation level for most, if not all, keywords and literals as IRB does it.
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/lib/irb/source.rb
DietRB/trunk/spec/source_spec.rb
Modified: DietRB/trunk/lib/irb/source.rb
===================================================================
--- DietRB/trunk/lib/irb/source.rb 2010-10-08 10:46:13 UTC (rev 4597)
+++ DietRB/trunk/lib/irb/source.rb 2010-10-08 10:46:22 UTC (rev 4598)
@@ -65,15 +65,37 @@
@valid
end
+ INCREASE_LEVEL_KEYWORDS = %w{ class module def begin if unless case while for do }
+
def on_kw(token) #:nodoc:
case token
- when "class", "def"
+ when *INCREASE_LEVEL_KEYWORDS
@level += 1
when "end"
@level -= 1
end
super
end
+
+ def on_lbracket(token) #:nodoc:
+ @level += 1
+ super
+ end
+
+ def on_rbracket(token) #:nodoc:
+ @level -= 1
+ super
+ end
+
+ def on_lbrace(token) #:nodoc:
+ @level += 1
+ super
+ end
+
+ def on_rbrace(token) #:nodoc:
+ @level -= 1
+ super
+ end
end
end
end
\ No newline at end of file
Modified: DietRB/trunk/spec/source_spec.rb
===================================================================
--- DietRB/trunk/spec/source_spec.rb 2010-10-08 10:46:13 UTC (rev 4597)
+++ DietRB/trunk/spec/source_spec.rb 2010-10-08 10:46:22 UTC (rev 4598)
@@ -21,7 +21,7 @@
@source.buffer.should == %w{ foo bar }
end
- it "returns the full buffered source, joined by a newline" do
+ it "returns the full buffered source, joined by newlines" do
@source.source.should == ""
@source << "foo\n"
@source.source.should == "foo"
@@ -105,4 +105,33 @@
reflect("class A; class B; def bar; p :ok; end").level.should == 2
reflect("class A; class B; def bar; p :ok; end; end; end").level.should == 0
end
+
+ it "correctly increases and decreases the code block indentation level for keywords" do
+ [
+ "class A",
+ "module A",
+ "def foo",
+ "begin",
+ "if x == :ok",
+ "unless x == :ko",
+ "case x",
+ "while x",
+ "for x in xs",
+ "x.each do"
+ ].each do |open|
+ reflect(open).level.should == 1
+ reflect("#{open}\nend").level.should == 0
+ end
+ end
+
+ it "correctly increases and decreases the code block indentation level for literals" do
+ [
+ ["lambda { |x|", "}"],
+ ["{", "}"],
+ ["[", "]"]
+ ].each do |open, close|
+ reflect(open).level.should == 1
+ reflect("#{open}\n#{close}").level.should == 0
+ end
+ 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/1eae6a4b/attachment.html>
More information about the macruby-changes
mailing list