Skip to content

Commit d461e6e

Browse files
author
Leonard Ehrenfried
committed
Add specs
1 parent 051cc2a commit d461e6e

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source 'https://rubygems.org'
2+
gem 'vimrunner', '0.3.0'
3+
gem 'rake', '10.0.4'
4+
gem 'rspec', '~> 2.13.0'
5+

Gemfile.lock

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.1.3)
5+
rake (0.9.2.2)
6+
rspec (2.9.0)
7+
rspec-core (~> 2.9.0)
8+
rspec-expectations (~> 2.9.0)
9+
rspec-mocks (~> 2.9.0)
10+
rspec-core (2.9.0)
11+
rspec-expectations (2.9.1)
12+
diff-lcs (~> 1.1.3)
13+
rspec-mocks (2.9.0)
14+
15+
PLATFORMS
16+
ruby
17+
18+
DEPENDENCIES
19+
rake
20+
rspec

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rspec/core/rake_task'
2+
3+
RSpec::Core::RakeTask.new
4+
5+
task :test => :spec
6+
task :default => :spec

spec/fixtures/vanilla.expected.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.foo
2+
3+
import java.bla
4+
import scala.horst
5+
6+
import AgentTypes._
7+
import akka.actor.{Actor, ActorLogging, ActorRef, ActorRefFactory, ActorSystem, Props, Stash, Terminated}
8+
9+
class Bar

spec/fixtures/vanilla.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.foo
2+
3+
import java.bla
4+
import AgentTypes._
5+
import scala.horst
6+
7+
import akka.actor.{Actor, ActorLogging, ActorRef, ActorRefFactory, ActorSystem, Props, Stash, Terminated}
8+
9+
class Bar

spec/import_sorting_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require "spec_helper"
2+
3+
describe ":SortScalaImports" do
4+
5+
describe "Sorting across groups" do
6+
["vanilla"].each do |name|
7+
it "should sort vanilla file" do
8+
actual = sort_fixture_across_groups name
9+
expected = expected(name)
10+
actual.should eq(expected)
11+
end
12+
end
13+
end
14+
15+
end

spec/spec_helper.rb

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'vimrunner'
2+
require 'tempfile'
3+
4+
PWD = File.expand_path File.dirname(__FILE__)
5+
6+
RSpec.configure do |config|
7+
8+
config.before(:suite) do
9+
VIM = Vimrunner.start
10+
VIM.add_plugin(File.expand_path('../..', __FILE__), 'plugin/scala.vim')
11+
end
12+
13+
config.after(:suite) do
14+
VIM.kill
15+
end
16+
end
17+
18+
def sort_fixture_across_groups(name)
19+
fixture_path = "#{PWD}/fixtures/#{name}.scala"
20+
21+
temp_file = Tempfile.new('vim-scala-')
22+
temp_file.write File.read(fixture_path)
23+
temp_file.rewind
24+
25+
VIM.edit temp_file.path
26+
27+
VIM.command "let g:scala_sort_across_groups=1"
28+
VIM.command "SortScalaImports"
29+
VIM.write
30+
31+
temp_file.rewind
32+
output = temp_file.read
33+
34+
temp_file.close
35+
temp_file.unlink
36+
37+
output
38+
end
39+
40+
def expected(name)
41+
path = "#{PWD}/fixtures/#{name}.expected.scala"
42+
File.read(path)
43+
end
44+

0 commit comments

Comments
 (0)