Skip to content

Commit

Permalink
- pulled out FakeDocument for indenter specs
Browse files Browse the repository at this point in the history
- 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
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
19 changes: 1 addition & 18 deletions plugins/auto_indenter/spec/auto_indenter/analyzer_spec.rb
@@ -1,27 +1,10 @@

require File.join(File.dirname(__FILE__), "..", "spec_helper")
require File.join(File.dirname(__FILE__), "fake_document")

include Redcar

describe AutoIndenter::Analyzer do
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

describe "with indentation rules like Ruby's" do
def should_indent(src, options)
Expand Down
18 changes: 18 additions & 0 deletions plugins/auto_indenter/spec/auto_indenter/fake_document.rb
@@ -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
14 changes: 14 additions & 0 deletions plugins/auto_indenter/spec/auto_indenter/sample.scala
@@ -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.")
}
}
}
33 changes: 33 additions & 0 deletions plugins/auto_indenter/spec/auto_indenter/scala_spec.rb
@@ -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

0 comments on commit e7112a8

Please sign in to comment.