spacevim/bundle/splitjoin.vim/spec/plugin/yaml_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

710 lines
13 KiB
Ruby

require 'spec_helper'
describe "yaml" do
let(:filename) { 'test.yml' }
before :each do
vim.set 'expandtab'
vim.set 'shiftwidth', 2
end
after :each do
vim.command('silent! unlet g:splitjoin_curly_brace_padding')
end
describe "arrays" do
specify "basic" do
set_file_contents <<~EOF
root:
one: [1, 2]
two: ['three', 'four']
EOF
vim.search 'one'
split
vim.search 'two'
split
assert_file_contents <<~EOF
root:
one:
- 1
- 2
two:
- 'three'
- 'four'
EOF
vim.search 'one'
join
vim.search 'two'
join
assert_file_contents <<~EOF
root:
one: [1, 2]
two: ['three', 'four']
EOF
end
specify "with empty spaces" do
set_file_contents <<~EOF
root:
- 'one'
- 'two'
EOF
vim.search 'root'
join
assert_file_contents <<~EOF
root: ['one', 'two']
EOF
end
specify "with strings containing a colon" do
set_file_contents <<~EOF
root:
- 'one: foo'
- 'two: bar'
EOF
vim.search 'root'
join
assert_file_contents <<~EOF
root: ['one: foo', 'two: bar']
EOF
vim.search 'root'
split
assert_file_contents <<~EOF
root:
- 'one: foo'
- 'two: bar'
EOF
end
specify "with strings containing a comma" do
set_file_contents <<~EOF
root:
- 'one, foo'
- 'two, bar'
EOF
vim.search 'root'
join
assert_file_contents <<~EOF
root: ['one, foo', 'two, bar']
EOF
vim.search 'root'
split
assert_file_contents <<~EOF
root:
- 'one, foo'
- 'two, bar'
EOF
end
specify "splitting nested maps inside an array" do
set_file_contents <<~EOF
root: [{ one: { foo: bar } }]
EOF
vim.search 'root'
split
assert_file_contents <<~EOF
root:
- one: { foo: bar }
EOF
end
specify "nested objects inside an array" do
set_file_contents <<~EOF
root:
- one: { foo: bar }
EOF
vim.search 'one'
split
assert_file_contents <<~EOF
root:
- one:
foo: bar
EOF
end
specify "list of simple objects" do
set_file_contents <<~EOF
list: [{ aprop: 1 }, { aProp: 2 }, { 'a:prop': 3 }, { a prop: 4 }, { a#prop: 5 }]
EOF
vim.search 'list'
split
assert_file_contents <<~EOF
list:
- aprop: 1
- aProp: 2
- 'a:prop': 3
- a prop: 4
- a#prop: 5
EOF
vim.search 'list'
join
assert_file_contents <<~EOF
list: [{ aprop: 1 }, { aProp: 2 }, { 'a:prop': 3 }, { a prop: 4 }, { a#prop: 5 }]
EOF
end
specify "containing mixed elements" do
set_file_contents <<~EOF
list: [{ prop: 1 }, { a: 1, b: 2 }, "a: b", { a value: 1, 'a:value': 2, aValue: 3 }]
EOF
vim.search 'list'
split
assert_file_contents <<~EOF
list:
- prop: 1
- { a: 1, b: 2 }
- "a: b"
- { a value: 1, 'a:value': 2, aValue: 3 }
EOF
vim.search 'list'
join
assert_file_contents <<~EOF
list: [{ prop: 1 }, { a: 1, b: 2 }, "a: b", { a value: 1, 'a:value': 2, aValue: 3 }]
EOF
end
specify "preserve empty lines" do
set_file_contents <<~EOF
list:
- 1
end: true
EOF
vim.search 'list'
join
assert_file_contents <<~EOF
list: [1]
end: true
EOF
vim.search 'list'
split
assert_file_contents <<~EOF
list:
- 1
end: true
EOF
end
specify "Not handled: containing mulitline maps (recursive)" do
set_file_contents <<~EOF
list:
- one: 1
two: 2
EOF
vim.search 'list'
# Call command instead of mapping to avoid default mapping
vim.command 'SplitjoinJoin'
# Does nothing, needs to be joined from the inside first
assert_file_contents <<~EOF
list:
- one: 1
two: 2
EOF
end
specify "Not handled: containing arrays (recursive)" do
set_file_contents <<~EOF
list:
- - 1
- 2
EOF
vim.search 'list'
# Call command instead of mapping to avoid default mapping
vim.command 'SplitjoinJoin'
assert_file_contents <<~EOF
list:
- - 1
- 2
EOF
end
specify "inside an array" do
set_file_contents <<~EOF
list:
- - 1
- 2
EOF
vim.search '1'
join
assert_file_contents <<~EOF
list:
- [1, 2]
EOF
end
specify "split nested arrays" do
set_file_contents <<~EOF
list: [[[1, 2]]]
EOF
vim.search 'list'
split
assert_file_contents <<~EOF
list:
- [[1, 2]]
EOF
vim.search '1'
split
assert_file_contents <<~EOF
list:
- - [1, 2]
EOF
vim.search '1'
split
assert_file_contents <<~EOF
list:
- - - 1
- 2
EOF
end
specify "join nested arrays" do
set_file_contents <<~EOF
list:
- - - 1
- 2
- - - 3
end: true
EOF
vim.search '1'
join
assert_file_contents <<~EOF
list:
- - [1, 2]
- - - 3
end: true
EOF
vim.search '1'
join
assert_file_contents <<~EOF
list:
- [[1, 2]]
- - - 3
end: true
EOF
vim.search '3'
join
assert_file_contents <<~EOF
list:
- [[1, 2]]
- - [3]
end: true
EOF
vim.search '3'
join
assert_file_contents <<~EOF
list:
- [[1, 2]]
- [[3]]
end: true
EOF
vim.search 'list'
join
assert_file_contents <<~EOF
list: [[[1, 2]], [[3]]]
end: true
EOF
end
specify "stripping comments" do
set_file_contents <<~EOF
root#list: # root object
- 'one'
- 'two' # second record
EOF
vim.search 'root'
join
assert_file_contents <<~EOF
root#list: ['one', 'two']
EOF
end
specify "joining inside an array and map with other properties" do
set_file_contents <<~EOF
list:
- foo:
- 1
- 2
bar:
one: 1
two: 2
end: true
EOF
vim.search 'foo:'
join
assert_file_contents <<~EOF
list:
- foo: [1, 2]
bar:
one: 1
two: 2
end: true
EOF
end
end
describe "maps" do
specify "basic" do
set_file_contents <<~EOF
root:
one: { foo: bar }
two: { three: ['four', 'five'], six: seven }
EOF
vim.search 'one'
split
vim.search 'two'
split
assert_file_contents <<~EOF
root:
one:
foo: bar
two:
three: ['four', 'five']
six: seven
EOF
vim.search 'one'
join
vim.search 'two'
join
assert_file_contents <<~EOF
root:
one: { foo: bar }
two: { three: ['four', 'five'], six: seven }
EOF
end
specify "with multiple spaces after key" do
set_file_contents <<~EOF
root: { one: 1 }
EOF
vim.search 'root:'
split
assert_file_contents <<~EOF
root:
one: 1
EOF
end
specify "without padding" do
vim.command 'let g:splitjoin_curly_brace_padding = 0'
set_file_contents <<~EOF
root:
one: 1
EOF
vim.search 'root:'
join
assert_file_contents 'root: {one: 1}'
end
specify "complex keys" do
set_file_contents <<~EOF
root:
one value: 1
'my:key': 2
EOF
vim.search 'root'
join
assert_file_contents <<~EOF
root: { one value: 1, 'my:key': 2 }
EOF
end
specify "preserve empty lines" do
set_file_contents <<~EOF
map:
one: 1
end: true
EOF
vim.search ''
join
assert_file_contents <<~EOF
map: { one: 1 }
end: true
EOF
vim.search 'map'
split
assert_file_contents <<~EOF
map:
one: 1
end: true
EOF
end
specify "joining inside an array" do
set_file_contents <<~EOF
list:
- one: 1
two: 2
end: true
EOF
vim.search 'one:'
join
assert_file_contents <<~EOF
list:
- { one: 1, two: 2 }
end: true
EOF
end
specify "splitting inside an array" do
set_file_contents <<~EOF
list:
- { one: 1, two: 2 }
end: true
EOF
vim.search 'one:'
split
assert_file_contents <<~EOF
list:
- one: 1
two: 2
end: true
EOF
end
specify "splitting inside an array, with complex properties" do
set_file_contents <<~EOF
list:
- { one: 1, two: [ 'foo', 'bar' ], three: { foo: 'item-1', bar: 'item-2' } }
end: true
EOF
vim.search 'one:'
split
assert_file_contents <<~EOF
list:
- one: 1
two: [ 'foo', 'bar' ]
three: { foo: 'item-1', bar: 'item-2' }
end: true
EOF
end
specify "joining inside an array and map" do
set_file_contents <<~EOF
list:
- foo:
one: 1
two: 2
end: true
EOF
vim.search 'foo:'
join
assert_file_contents <<~EOF
list:
- foo: { one: 1, two: 2 }
end: true
EOF
end
specify "joining inside an array and map with other properties" do
set_file_contents <<~EOF
list:
- foo:
one: 1
two: 2
bar:
one: 1
two: 2
end: true
EOF
vim.search 'foo:'
join
assert_file_contents <<~EOF
list:
- foo: { one: 1, two: 2 }
bar:
one: 1
two: 2
end: true
EOF
end
specify "splitting inside an array and map" do
set_file_contents <<~EOF
list:
- foo: { one: 1, two: 2 }
end: true
EOF
vim.search 'foo:'
split
assert_file_contents <<~EOF
list:
- foo:
one: 1
two: 2
end: true
EOF
end
specify "Not handled: containing nested maps (recursive)" do
set_file_contents <<~EOF
map:
foo:
bar: 2
EOF
vim.search 'map'
# Call command instead of mapping to avoid default mapping
vim.command 'SplitjoinJoin'
assert_file_contents <<~EOF
map:
foo:
bar: 2
EOF
end
specify "Not handled: containing nested maps within lists (recursive)" do
set_file_contents <<~EOF
list1:
- one: 1
- two: 2
four:
five: 6
EOF
vim.search 'two'
# Call command instead of mapping to avoid default mapping
vim.command 'SplitjoinJoin'
assert_file_contents <<~EOF
list1:
- one: 1
- two: 2
four:
five: 6
EOF
end
specify "stripping comments" do
set_file_contents <<~EOF
root_a#list: # root object
a: 'one'
b: 'two' # one more
root_b#list:
- prop: # nested object
a: 'one' # another
b: 'two'
EOF
vim.search 'root_a'
join
vim.search 'prop'
join
assert_file_contents <<~EOF
root_a#list: { a: 'one', b: 'two' }
root_b#list:
- prop: { a: 'one', b: 'two' }
EOF
end
specify "splitting paths in maps" do
set_file_contents <<~EOF
- copy: { dest: /etc/default/locale, content: "LANG=en_US.UTF-8" }
EOF
vim.search 'dest'
split
assert_file_contents <<~EOF
- copy:
dest: /etc/default/locale
content: "LANG=en_US.UTF-8"
EOF
end
end
end