mirror of
https://github.com/nvim-lua/plenary.nvim
synced 2024-09-16 13:24:05 +02:00
chore: format with stylua 0.12.0 (#316)
This commit is contained in:
parent
3e0e3af520
commit
e86dc9b112
2 changed files with 206 additions and 193 deletions
|
@ -3,4 +3,4 @@ line_endings = "Unix"
|
|||
indent_type = "Spaces"
|
||||
indent_width = 2
|
||||
quote_style = "AutoPreferDouble"
|
||||
no_call_parentheses = true
|
||||
call_parentheses = "None"
|
|
@ -3,14 +3,16 @@ local eq = assert.are.same
|
|||
|
||||
describe("strings", function()
|
||||
describe("strdisplaywidth", function()
|
||||
for _, case in ipairs {
|
||||
{ str = "abcde", expected = { single = 5, double = 5 } },
|
||||
-- This space below is a tab (U+0009)
|
||||
{ str = "abc de", expected = { single = 10, double = 10 } },
|
||||
{ str = "アイウエオ", expected = { single = 10, double = 10 } },
|
||||
{ str = "├─┤", expected = { single = 3, double = 6 } },
|
||||
{ str = 123, expected = { single = 3, double = 3 } },
|
||||
} do
|
||||
for _, case in
|
||||
ipairs {
|
||||
{ str = "abcde", expected = { single = 5, double = 5 } },
|
||||
-- This space below is a tab (U+0009)
|
||||
{ str = "abc de", expected = { single = 10, double = 10 } },
|
||||
{ str = "アイウエオ", expected = { single = 10, double = 10 } },
|
||||
{ str = "├─┤", expected = { single = 3, double = 6 } },
|
||||
{ str = 123, expected = { single = 3, double = 3 } },
|
||||
}
|
||||
do
|
||||
for _, ambiwidth in ipairs { "single", "double" } do
|
||||
local item = type(case.str) == "string" and '"%s"' or "%s"
|
||||
local msg = ("ambiwidth = %s, " .. item .. " -> %d"):format(ambiwidth, case.str, case.expected[ambiwidth])
|
||||
|
@ -28,12 +30,14 @@ describe("strings", function()
|
|||
end)
|
||||
|
||||
describe("strcharpart", function()
|
||||
for _, case in ipairs {
|
||||
{ args = { "abcde", 2 }, expected = "cde" },
|
||||
{ args = { "abcde", 2, 2 }, expected = "cd" },
|
||||
{ args = { "アイウエオ", 2, 2 }, expected = "ウエ" },
|
||||
{ args = { "├───┤", 2, 2 }, expected = "──" },
|
||||
} do
|
||||
for _, case in
|
||||
ipairs {
|
||||
{ args = { "abcde", 2 }, expected = "cde" },
|
||||
{ args = { "abcde", 2, 2 }, expected = "cd" },
|
||||
{ args = { "アイウエオ", 2, 2 }, expected = "ウエ" },
|
||||
{ args = { "├───┤", 2, 2 }, expected = "──" },
|
||||
}
|
||||
do
|
||||
local msg = ('("%s", %d, %s) -> "%s"'):format(case.args[1], case.args[2], tostring(case.args[3]), case.expected)
|
||||
it("lua: " .. msg, function()
|
||||
eq(case.expected, strings.strcharpart(unpack(case.args)))
|
||||
|
@ -45,74 +49,79 @@ describe("strings", function()
|
|||
end)
|
||||
|
||||
describe("truncate", function()
|
||||
for _, case in ipairs {
|
||||
-- truncations from the right
|
||||
{ args = { "abcde", 6, nil, 1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5, nil, 1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4, nil, 1 }, expected = { single = "abc…", double = "ab…" } },
|
||||
{
|
||||
args = { "アイウエオ", 11, nil, 1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 10, nil, 1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{ args = { "アイウエオ", 9, nil, 1 }, expected = { single = "アイウエ…", double = "アイウ…" } },
|
||||
{ args = { "アイウエオ", 8, nil, 1 }, expected = { single = "アイウ…", double = "アイウ…" } },
|
||||
{ args = { "├─┤", 7, nil, 1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6, nil, 1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5, nil, 1 }, expected = { single = "├─┤", double = "├…" } },
|
||||
{ args = { "├─┤", 4, nil, 1 }, expected = { single = "├─┤", double = "├…" } },
|
||||
{ args = { "├─┤", 3, nil, 1 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2, nil, 1 }, expected = { single = "├…", double = "…" } },
|
||||
-- truncations from the left
|
||||
{ args = { "abcde", 6, nil, -1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5, nil, -1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4, nil, -1 }, expected = { single = "…cde", double = "…de" } },
|
||||
{
|
||||
args = { "アイウエオ", 11, nil, -1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 10, nil, -1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 9, nil, -1 },
|
||||
expected = { single = "…イウエオ", double = "…ウエオ" },
|
||||
},
|
||||
{ args = { "アイウエオ", 8, nil, -1 }, expected = { single = "…ウエオ", double = "…ウエオ" } },
|
||||
{ args = { "├─┤", 7, nil, -1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6, nil, -1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5, nil, -1 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 4, nil, -1 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 3, nil, -1 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2, nil, -1 }, expected = { single = "…┤", double = "…" } },
|
||||
-- truncations from the middle
|
||||
{ args = { "abcde", 6, nil, 0 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5, nil, 0 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4, nil, 0 }, expected = { single = "a…de", double = "a…e" } },
|
||||
{
|
||||
args = { "アイウエオ", 11, nil, 0 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 10, nil, 0 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 9, nil, 0 },
|
||||
expected = { single = "アイ…エオ", double = "ア…エオ" },
|
||||
},
|
||||
{ args = { "アイウエオ", 8, nil, 0 }, expected = { single = "ア…エオ", double = "ア…エオ" } },
|
||||
{ args = { "├─┤", 7, nil, 0 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6, nil, 0 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5, nil, 0 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 4, nil, 0 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 3, nil, 0 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2, nil, 0 }, expected = { single = "…┤", double = "…" } },
|
||||
} do
|
||||
for _, case in
|
||||
ipairs {
|
||||
-- truncations from the right
|
||||
{ args = { "abcde", 6, nil, 1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5, nil, 1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4, nil, 1 }, expected = { single = "abc…", double = "ab…" } },
|
||||
{
|
||||
args = { "アイウエオ", 11, nil, 1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 10, nil, 1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 9, nil, 1 },
|
||||
expected = { single = "アイウエ…", double = "アイウ…" },
|
||||
},
|
||||
{ args = { "アイウエオ", 8, nil, 1 }, expected = { single = "アイウ…", double = "アイウ…" } },
|
||||
{ args = { "├─┤", 7, nil, 1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6, nil, 1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5, nil, 1 }, expected = { single = "├─┤", double = "├…" } },
|
||||
{ args = { "├─┤", 4, nil, 1 }, expected = { single = "├─┤", double = "├…" } },
|
||||
{ args = { "├─┤", 3, nil, 1 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2, nil, 1 }, expected = { single = "├…", double = "…" } },
|
||||
-- truncations from the left
|
||||
{ args = { "abcde", 6, nil, -1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5, nil, -1 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4, nil, -1 }, expected = { single = "…cde", double = "…de" } },
|
||||
{
|
||||
args = { "アイウエオ", 11, nil, -1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 10, nil, -1 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 9, nil, -1 },
|
||||
expected = { single = "…イウエオ", double = "…ウエオ" },
|
||||
},
|
||||
{ args = { "アイウエオ", 8, nil, -1 }, expected = { single = "…ウエオ", double = "…ウエオ" } },
|
||||
{ args = { "├─┤", 7, nil, -1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6, nil, -1 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5, nil, -1 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 4, nil, -1 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 3, nil, -1 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2, nil, -1 }, expected = { single = "…┤", double = "…" } },
|
||||
-- truncations from the middle
|
||||
{ args = { "abcde", 6, nil, 0 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 5, nil, 0 }, expected = { single = "abcde", double = "abcde" } },
|
||||
{ args = { "abcde", 4, nil, 0 }, expected = { single = "a…de", double = "a…e" } },
|
||||
{
|
||||
args = { "アイウエオ", 11, nil, 0 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 10, nil, 0 },
|
||||
expected = { single = "アイウエオ", double = "アイウエオ" },
|
||||
},
|
||||
{
|
||||
args = { "アイウエオ", 9, nil, 0 },
|
||||
expected = { single = "アイ…エオ", double = "ア…エオ" },
|
||||
},
|
||||
{ args = { "アイウエオ", 8, nil, 0 }, expected = { single = "ア…エオ", double = "ア…エオ" } },
|
||||
{ args = { "├─┤", 7, nil, 0 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 6, nil, 0 }, expected = { single = "├─┤", double = "├─┤" } },
|
||||
{ args = { "├─┤", 5, nil, 0 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 4, nil, 0 }, expected = { single = "├─┤", double = "…┤" } },
|
||||
{ args = { "├─┤", 3, nil, 0 }, expected = { single = "├─┤", double = "…" } },
|
||||
{ args = { "├─┤", 2, nil, 0 }, expected = { single = "…┤", double = "…" } },
|
||||
}
|
||||
do
|
||||
for _, ambiwidth in ipairs { "single", "double" } do
|
||||
local msg = ("ambiwidth = %s, direction = %s, [%s, %d] -> %s"):format(
|
||||
ambiwidth,
|
||||
|
@ -132,14 +141,16 @@ describe("strings", function()
|
|||
end)
|
||||
|
||||
describe("align_str", function()
|
||||
for _, case in ipairs {
|
||||
{ args = { "abcde", 8 }, expected = { single = "abcde ", double = "abcde " } },
|
||||
{ args = { "アイウ", 8 }, expected = { single = "アイウ ", double = "アイウ " } },
|
||||
{ args = { "├─┤", 8 }, expected = { single = "├─┤ ", double = "├─┤ " } },
|
||||
{ args = { "abcde", 8, true }, expected = { single = " abcde", double = " abcde" } },
|
||||
{ args = { "アイウ", 8, true }, expected = { single = " アイウ", double = " アイウ" } },
|
||||
{ args = { "├─┤", 8, true }, expected = { single = " ├─┤", double = " ├─┤" } },
|
||||
} do
|
||||
for _, case in
|
||||
ipairs {
|
||||
{ args = { "abcde", 8 }, expected = { single = "abcde ", double = "abcde " } },
|
||||
{ args = { "アイウ", 8 }, expected = { single = "アイウ ", double = "アイウ " } },
|
||||
{ args = { "├─┤", 8 }, expected = { single = "├─┤ ", double = "├─┤ " } },
|
||||
{ args = { "abcde", 8, true }, expected = { single = " abcde", double = " abcde" } },
|
||||
{ args = { "アイウ", 8, true }, expected = { single = " アイウ", double = " アイウ" } },
|
||||
{ args = { "├─┤", 8, true }, expected = { single = " ├─┤", double = " ├─┤" } },
|
||||
}
|
||||
do
|
||||
for _, ambiwidth in ipairs { "single", "double" } do
|
||||
local msg = ('ambiwidth = %s, [%s, %d, %s] -> "%s"'):format(
|
||||
ambiwidth,
|
||||
|
@ -162,134 +173,136 @@ describe("strings", function()
|
|||
local function lines(t)
|
||||
return table.concat(t, "\n")
|
||||
end
|
||||
for _, case in ipairs {
|
||||
{
|
||||
msg = "empty string",
|
||||
tabstop = 8,
|
||||
args = { "" },
|
||||
expected = "",
|
||||
},
|
||||
{
|
||||
msg = "in case tabs are longer than spaces",
|
||||
tabstop = 8,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab><Tab> -> 13 spaces",
|
||||
" 5 spaces -> 0 space",
|
||||
for _, case in
|
||||
ipairs {
|
||||
{
|
||||
msg = "empty string",
|
||||
tabstop = 8,
|
||||
args = { "" },
|
||||
expected = "",
|
||||
},
|
||||
{
|
||||
msg = "in case tabs are longer than spaces",
|
||||
tabstop = 8,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab><Tab> -> 13 spaces",
|
||||
" 5 spaces -> 0 space",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
" <Tab><Tab> -> 13 spaces",
|
||||
"5 spaces -> 0 space",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
" <Tab><Tab> -> 13 spaces",
|
||||
"5 spaces -> 0 space",
|
||||
},
|
||||
},
|
||||
{
|
||||
msg = "in case tabs are shorter than spaces",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab><Tab> -> 0 space",
|
||||
" 5spaces -> 1 space",
|
||||
{
|
||||
msg = "in case tabs are shorter than spaces",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab><Tab> -> 0 space",
|
||||
" 5spaces -> 1 space",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
"<Tab><Tab> -> 0 space",
|
||||
" 5spaces -> 1 space",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
"<Tab><Tab> -> 0 space",
|
||||
" 5spaces -> 1 space",
|
||||
},
|
||||
},
|
||||
{
|
||||
msg = "ignores empty lines",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
{
|
||||
msg = "ignores empty lines",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" 8 spaces -> 3 spaces",
|
||||
"",
|
||||
"",
|
||||
" 5 spaces -> 0 space",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" 8 spaces -> 3 spaces",
|
||||
" 8 spaces -> 3 spaces",
|
||||
"",
|
||||
"",
|
||||
" 5 spaces -> 0 space",
|
||||
"5 spaces -> 0 space",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" 8 spaces -> 3 spaces",
|
||||
"",
|
||||
"",
|
||||
"5 spaces -> 0 space",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
},
|
||||
},
|
||||
{
|
||||
msg = "no indent",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab> -> 2 spaces",
|
||||
{
|
||||
msg = "no indent",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab> -> 2 spaces",
|
||||
"Here is no indent.",
|
||||
" 4 spaces will remain",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
" <Tab> -> 2 spaces",
|
||||
"Here is no indent.",
|
||||
" 4 spaces will remain",
|
||||
},
|
||||
},
|
||||
expected = lines {
|
||||
" <Tab> -> 2 spaces",
|
||||
"Here is no indent.",
|
||||
" 4 spaces will remain",
|
||||
},
|
||||
},
|
||||
{
|
||||
msg = "leave_indent = 4",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab> -> 6 spaces",
|
||||
"0 indent -> 4 spaces",
|
||||
" 4 spaces -> 8 spaces",
|
||||
{
|
||||
msg = "leave_indent = 4",
|
||||
tabstop = 2,
|
||||
args = {
|
||||
lines {
|
||||
" <Tab> -> 6 spaces",
|
||||
"0 indent -> 4 spaces",
|
||||
" 4 spaces -> 8 spaces",
|
||||
},
|
||||
4,
|
||||
},
|
||||
expected = lines {
|
||||
" <Tab> -> 6 spaces",
|
||||
" 0 indent -> 4 spaces",
|
||||
" 4 spaces -> 8 spaces",
|
||||
},
|
||||
4,
|
||||
},
|
||||
expected = lines {
|
||||
" <Tab> -> 6 spaces",
|
||||
" 0 indent -> 4 spaces",
|
||||
" 4 spaces -> 8 spaces",
|
||||
},
|
||||
},
|
||||
{
|
||||
msg = "typical usecase: <Tab> to 5 spaces",
|
||||
tabstop = 4,
|
||||
args = {
|
||||
lines {
|
||||
{
|
||||
msg = "typical usecase: <Tab> to 5 spaces",
|
||||
tabstop = 4,
|
||||
args = {
|
||||
lines {
|
||||
"",
|
||||
" Chapter 1",
|
||||
"",
|
||||
" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed",
|
||||
" do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
"",
|
||||
" Ut enim ad minim veniam, quis nostrud exercitation ullamco",
|
||||
" laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
"",
|
||||
},
|
||||
5,
|
||||
},
|
||||
expected = lines {
|
||||
"",
|
||||
" Chapter 1",
|
||||
" Chapter 1",
|
||||
"",
|
||||
" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed",
|
||||
" do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed",
|
||||
" do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
"",
|
||||
" Ut enim ad minim veniam, quis nostrud exercitation ullamco",
|
||||
" laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
" Ut enim ad minim veniam, quis nostrud exercitation ullamco",
|
||||
" laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
"",
|
||||
},
|
||||
5,
|
||||
},
|
||||
expected = lines {
|
||||
"",
|
||||
" Chapter 1",
|
||||
"",
|
||||
" Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed",
|
||||
" do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
||||
"",
|
||||
" Ut enim ad minim veniam, quis nostrud exercitation ullamco",
|
||||
" laboris nisi ut aliquip ex ea commodo consequat.",
|
||||
"",
|
||||
},
|
||||
},
|
||||
} do
|
||||
}
|
||||
do
|
||||
local msg = ("tabstop = %d, %s"):format(case.tabstop, case.msg)
|
||||
it(msg, function()
|
||||
local original = vim.bo.tabstop
|
||||
|
|
Loading…
Reference in a new issue