require "spec_helper"
shared_examples_for "vim" do
-
before(:each) {
# clear buffer
vim.normal 'gg"_dG'
it "puts the closing parenthesis at the same level" do
vim.feedkeys ')'
- indent.should == 0
+ indent.should == (hang_closing ? shiftwidth : 0)
end
end
it "lines up the closing parenthesis" do
vim.feedkeys '}'
- indent.should == 0
+ indent.should == (hang_closing ? shiftwidth : 0)
end
end
end
end
-describe "vim when using width of 4" do
- before {
- vim.command("set sw=4 ts=4 sts=4 et")
- }
- it_behaves_like "vim"
-end
+SUITE_SHIFTWIDTHS = [4, 3]
+SUITE_HANG_CLOSINGS = [false, true]
-describe "vim when using width of 3" do
- before {
- vim.command("set sw=3 ts=3 sts=3 et")
- }
- it_behaves_like "vim"
+SUITE_SHIFTWIDTHS.each do |sw|
+ describe "vim when using width of #{sw}" do
+ before {
+ vim.command("set sw=#{sw} ts=#{sw} sts=#{sw} et")
+ }
+ it "sets shiftwidth to #{sw}" do
+ shiftwidth.should == sw
+ end
+
+ SUITE_HANG_CLOSINGS.each do |hc|
+ describe "vim when hang_closing is set to #{hc}" do
+ before {
+ set_hang_closing hc
+ }
+ it "sets hang_closing to #{hc}" do
+ hang_closing.should == !!hc
+ end
+
+ it_behaves_like "vim"
+ end
+ end
+ end
end
describe "vim when not using python_pep8_indent_multiline_string" do
it_behaves_like "multiline strings"
end
-describe "vim for cython" do
- before {
- vim.command "enew"
- vim.command "set ft=cython"
- vim.command "runtime indent/python.vim"
-
- # Insert two blank lines.
- # The first line is a corner case in this plugin that would shadow the
- # correct behaviour of other tests. Thus we explicitly jump to the first
- # line when we require so.
- vim.feedkeys 'i\<CR>\<CR>\<ESC>'
- }
-
- describe "when using a cdef function definition" do
- it "indents shiftwidth spaces" do
- vim.feedkeys 'icdef long_function_name(\<CR>arg'
- indent.should == shiftwidth * 2
- end
- end
-
- describe "when using a cpdef function definition" do
- it "indents shiftwidth spaces" do
- vim.feedkeys 'icpdef long_function_name(\<CR>arg'
- indent.should == shiftwidth * 2
- end
- end
-end
-
describe "Handles far away opening parens" do
before { vim.feedkeys '\<ESC>ggdGifrom foo import (' }
indent.should == shiftwidth
end
end
+
+describe "Compact multiline dict" do
+ before { vim.feedkeys '\<ESC>ggdGid = {"one": 1,' }
+
+ it "gets indented correctly" do
+ vim.feedkeys '\<CR>'
+ proposed_indent.should == 5
+
+ vim.feedkeys '"two": 2}'
+ proposed_indent.should == 5
+
+ vim.feedkeys '\<CR>'
+ proposed_indent.should == 0
+ end
+end