spacevim/bundle/splitjoin.vim/spec/plugin/python_spec.rb
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

275 lines
5.3 KiB
Ruby

require 'spec_helper'
describe "python" do
let(:filename) { 'test.py' }
before :each do
vim.set(:expandtab)
vim.set(:shiftwidth, 4)
end
specify "dictionaries" do
set_file_contents "spam = {'spam': [1, 2, 3], 'spam, spam': 'eggs'}"
vim.search '{'
split
assert_file_contents <<~EOF
spam = {
'spam': [1, 2, 3],
'spam, spam': 'eggs'
}
EOF
join
assert_file_contents "spam = {'spam': [1, 2, 3], 'spam, spam': 'eggs'}"
end
specify "dictionaries with non-string keys" do
set_file_contents "spam = {spam: [1, 2, 3], 'spam, spam': 'eggs'}"
vim.search '{'
split
assert_file_contents <<~EOF
spam = {
spam: [1, 2, 3],
'spam, spam': 'eggs'
}
EOF
join
assert_file_contents "spam = {spam: [1, 2, 3], 'spam, spam': 'eggs'}"
end
specify "lists" do
set_file_contents 'spam = [1, [2, 3], 4]'
vim.search '[1'
split
assert_file_contents <<~EOF
spam = [1,
[2, 3],
4]
EOF
join
assert_file_contents 'spam = [1, [2, 3], 4]'
end
specify "imports" do
set_file_contents 'from foo import bar, baz'
split
assert_file_contents <<~EOF
from foo import bar,\\
baz
EOF
join
assert_file_contents 'from foo import bar, baz'
end
specify "statements" do
set_file_contents 'while True: loop()'
split
assert_file_contents <<~EOF
while True:
loop()
EOF
join
assert_file_contents 'while True: loop()'
end
specify "ternary clauses" do
set_file_contents <<~EOF
with indent as _:
max_x = x1 if x1 > x2 else x2
EOF
vim.search('max_x')
split
assert_file_contents <<~EOF
with indent as _:
if x1 > x2:
max_x = x1
else:
max_x = x2
EOF
join
assert_file_contents <<~EOF
with indent as _:
max_x = x1 if x1 > x2 else x2
EOF
end
specify "splitting within a string" do
pending "Old version on CI" if ENV['CI']
set_file_contents <<~EOF
run("one", "two", "three {}".format(four))
EOF
vim.search('one')
split
assert_file_contents <<~EOF
run("one",
"two",
"three {}".format(four))
EOF
end
specify "chained method calls" do
pending "Old version on CI" if ENV['CI']
set_file_contents <<~EOF
SomeModel.objects.filter(asdf=1, qwer=2).exclude(zxcv=2, tyui=3)
EOF
vim.search('zxcv')
split
assert_file_contents <<~EOF
SomeModel.objects.filter(asdf=1, qwer=2).exclude(zxcv=2,
tyui=3)
EOF
end
specify "variable assignment" do
set_file_contents <<~EOF
def example(self):
one, self.two, three = foo("bar"), ["one", "two"], {foo: "bar"}
EOF
vim.search('two')
split
assert_file_contents <<~EOF
def example(self):
one = foo("bar")
self.two = ["one", "two"]
three = {foo: "bar"}
EOF
vim.search('two')
join
assert_file_contents <<~EOF
def example(self):
one = foo("bar")
self.two, three = ["one", "two"], {foo: "bar"}
EOF
end
specify "variable assignment of an array" do
set_file_contents <<~EOF
def example():
one, two, three = Some.expression("that returns an array")
EOF
vim.search('two')
split
assert_file_contents <<~EOF
def example():
one = Some.expression("that returns an array")[0]
two = Some.expression("that returns an array")[1]
three = Some.expression("that returns an array")[2]
EOF
vim.search('one')
join
assert_file_contents <<~EOF
def example():
one, two, three = Some.expression("that returns an array")
EOF
end
specify "dictionary within tuple" do
pending "Old version on CI" if ENV['CI']
set_file_contents <<~EOF
out = ("one", {"two": "three"}, "four")
EOF
vim.search('one')
split
assert_file_contents <<~EOF
out = ("one",
{"two": "three"},
"four")
EOF
vim.search('one')
join
assert_file_contents <<~EOF
out = ("one", {"two": "three"}, "four")
EOF
end
specify "tuple within dictionary" do
set_file_contents <<~EOF
out = {"one": "two", "key": ("three", "four")}
EOF
vim.search('one')
split
assert_file_contents <<~EOF
out = {
"one": "two",
"key": ("three", "four")
}
EOF
vim.search('out')
join
assert_file_contents <<~EOF
out = {"one": "two", "key": ("three", "four")}
EOF
end
specify "list comprehensions" do
pending "Old version on CI" if ENV['CI']
set_file_contents <<~EOF
result = [x * y for x in range(1, 10) for y in range(10, 20) if x != y]
EOF
vim.search('x')
split
assert_file_contents <<~EOF
result = [x * y
for x in range(1, 10)
for y in range(10, 20)
if x != y]
EOF
vim.search('[')
join
assert_file_contents <<~EOF
result = [x * y for x in range(1, 10) for y in range(10, 20) if x != y]
EOF
end
end