forked from danlucraft/redcar
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- pulled out FakeDocument for indenter specs
- added sample of a scala file. - added a failing spec for the scala indenter.
- Loading branch information
Silvio Heuberger
committed
Jun 29, 2010
1 parent
2752f1f
commit e7112a8
Showing
4 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class FakeDocument | ||
def initialize(string, tab_width, soft_tabs) | ||
@string = string | ||
@tab_width, @soft_tab = tab_width, soft_tabs | ||
end | ||
|
||
def get_line(ix) | ||
lines[ix] + "\n" | ||
end | ||
|
||
def lines | ||
@string.split("\n") | ||
end | ||
|
||
def indentation | ||
Document::Indentation.new(self, @tab_width, @soft_tabs) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ch.mollusca.stomp.frame | ||
|
||
import org.scalatest.Spec | ||
|
||
class FrameProcessorSpec extends Spec { | ||
|
||
val frameProcessor = new FrameProcessor | ||
|
||
describe("The frame processor") { | ||
it("should handle a complete CONNECT frame") { | ||
assert(frame.content === "message body.") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require File.join(File.dirname(__FILE__), "..", "spec_helper") | ||
require File.join(File.dirname(__FILE__), "fake_document") | ||
|
||
include Redcar | ||
|
||
describe AutoIndenter::Analyzer do | ||
|
||
scala = File.open(File.join(File.dirname(__FILE__), "sample.scala"), "r").read | ||
|
||
def should_indent(src, options) | ||
simple_rules = AutoIndenter::Rules.new( | ||
/^.*\{[^}"']*$|^\s*(def|class|object|trait|val|var|private|protected):\s*$/, | ||
/^(.*\*\/)?\s*\}([^}{"']*\{)?[;\s]*(\/\/.*|\/\*.*\*\/\s*)?$|^\s*(def|class|object|trait|val|var|private|protected):\s*$/, | ||
/^(?!(.*[};:])?\s*(\/\/|\/\*.*\*\/\s*$)).*[^\s;:{}]\s*$/ | ||
) | ||
|
||
analyzer = AutoIndenter::Analyzer.new(simple_rules, FakeDocument.new(src, 2, false), 2, false) | ||
analyzer.calculate_for_line(options[:line]).should == options[:indent] | ||
end | ||
|
||
describe "with Scala's real indentation rules loaded" do | ||
it "should indent correctly after curly braces" do | ||
should_indent(scala, :line => 0, :indent => 0) | ||
should_indent(scala, :line => 1, :indent => 0) | ||
should_indent(scala, :line => 7, :indent => 2) | ||
should_indent(scala, :line => 9, :indent => 2) | ||
should_indent(scala, :line => 10, :indent => 3) | ||
|
||
# ticket: http://redcar.lighthouseapp.com/projects/25090/tickets/244-indenter-has-trouble-with-scala | ||
should_indent(scala, :line => 11, :indent => 2) | ||
end | ||
end | ||
end |