feat: rewrite indent module

This commit is contained in:
Munif Tanjim 2022-01-18 21:17:26 +06:00 committed by Christian Clason
parent baf94219aa
commit c0110e34aa
13 changed files with 136 additions and 182 deletions

View file

@ -13,15 +13,9 @@ describe("indent C:", function()
runner:whole_file(".", {
expected_failures = {
"./ternary.c",
"./string.c",
"./preproc_func.c",
"./preproc_cond.c",
"./no_braces.c",
"./label.c",
"./func.c",
"./expr.c",
"./comment.c",
"./array.c",
},
})
end)
@ -36,14 +30,14 @@ describe("indent C:", function()
runner:new_line("label.c", { on_line = 3, text = "normal:", indent = 0 }, "expected failure", XFAIL)
runner:new_line("loop.c", { on_line = 3, text = "x++;", indent = 8 })
runner:new_line("preproc_cond.c", { on_line = 5, text = "x++;", indent = 4 })
runner:new_line("preproc_func.c", { on_line = 3, text = "x++; \\", indent = 8 })
runner:new_line("string.c", { on_line = 1, text = "brave new \\", indent = 0 }, "expected failure", XFAIL)
runner:new_line("preproc_func.c", { on_line = 3, text = "x++; \\", indent = 8 }, "expected failure", XFAIL)
runner:new_line("string.c", { on_line = 1, text = "brave new \\", indent = 0 })
runner:new_line("string.c", { on_line = 4, text = '"brave new "', indent = 4 })
runner:new_line("struct.c", { on_line = 4, text = "int y;", indent = 8 })
runner:new_line("switch.c", { on_line = 3, text = "x++;", indent = 12 })
runner:new_line("ternary.c", { on_line = 4, text = ": (x == 0) : 0", indent = 8 })
runner:new_line("ternary.c", { on_line = 4, text = ": (x == 0) : 0", indent = 8 }, "expected failure", XFAIL)
-- the line after inserted one will be left with wrong indent but we only care about the inserted one
runner:new_line("no_braces.c", { on_line = 4, text = "x++;", indent = 8 }, "expected failure", XFAIL)
runner:new_line("no_braces.c", { on_line = 4, text = "x++;", indent = 8 })
runner:new_line("no_braces.c", { on_line = 7, text = "x++;", indent = 8 })
runner:new_line("no_braces.c", { on_line = 10, text = "x++;", indent = 8 })
end)

View file

@ -16,18 +16,9 @@ describe("indent C++:", function()
expected_failures = {
-- C
"c/ternary.c",
"c/string.c",
"c/preproc_func.c",
"c/preproc_cond.c",
"c/no_braces.c",
"c/label.c",
"c/func.c",
"c/expr.c",
"c/comment.c",
"c/array.c",
-- C++
"cpp/access.cpp",
"cpp/stream.cpp",
},
})
end)
@ -46,14 +37,14 @@ describe("indent C++:", function()
run:new_line("c/label.c", { on_line = 3, text = "normal:", indent = 0 }, "expected failure", XFAIL)
run:new_line("c/loop.c", { on_line = 3, text = "x++;", indent = 8 })
run:new_line("c/preproc_cond.c", { on_line = 5, text = "x++;", indent = 4 })
run:new_line("c/preproc_func.c", { on_line = 3, text = "x++; \\", indent = 8 })
run:new_line("c/string.c", { on_line = 1, text = "brave new \\", indent = 0 }, "expected failure", XFAIL)
run:new_line("c/preproc_func.c", { on_line = 3, text = "x++; \\", indent = 8 }, "expected failure", XFAIL)
run:new_line("c/string.c", { on_line = 1, text = "brave new \\", indent = 0 })
run:new_line("c/string.c", { on_line = 4, text = '"brave new "', indent = 4 })
run:new_line("c/struct.c", { on_line = 4, text = "int y;", indent = 8 })
run:new_line("c/switch.c", { on_line = 3, text = "x++;", indent = 12 })
run:new_line("c/ternary.c", { on_line = 4, text = ": (x == 0) : 0", indent = 8 })
run:new_line("c/ternary.c", { on_line = 4, text = ": (x == 0) : 0", indent = 8 }, "expected failure", XFAIL)
-- the line after inserted one will be left with wrong indent but we only care about the inserted one
run:new_line("c/no_braces.c", { on_line = 4, text = "x++;", indent = 8 }, "expected failure", XFAIL)
run:new_line("c/no_braces.c", { on_line = 4, text = "x++;", indent = 8 })
run:new_line("c/no_braces.c", { on_line = 7, text = "x++;", indent = 8 })
run:new_line("c/no_braces.c", { on_line = 10, text = "x++;", indent = 8 })
end)

View file

@ -10,21 +10,23 @@ local run = Runner:new(it, "tests/indent/lua", {
describe("indent Lua:", function()
describe("whole file:", function()
run:whole_file(".", { expected_failures = {
"./comment.lua",
} })
run:whole_file(".", {
expected_failures = {
"./comment.lua",
},
})
end)
describe("new line:", function()
run:new_line("comment.lua", { on_line = 1, text = "line", indent = "-- " })
run:new_line("comment.lua", { on_line = 5, text = "multiline", indent = " " })
run:new_line("comment.lua", { on_line = 5, text = "multiline", indent = " " }, "expected failure", XFAIL)
run:new_line("func.lua", { on_line = 1, text = "x = x + 1", indent = 2 })
run:new_line("func.lua", { on_line = 2, text = "y = y + 1", indent = 4 })
run:new_line("func.lua", { on_line = 5, text = "3,", indent = 4 })
run:new_line("string.lua", { on_line = 1, text = "x", indent = 0 }, "expected failure", XFAIL)
run:new_line("string.lua", { on_line = 2, text = "x", indent = 0 }, "expected failure", XFAIL)
run:new_line("string.lua", { on_line = 1, text = "x", indent = 0 })
run:new_line("string.lua", { on_line = 2, text = "x", indent = 0 })
run:new_line("string.lua", { on_line = 3, text = "x", indent = 2 })
run:new_line("string.lua", { on_line = 4, text = "x", indent = 4 }, "expected failure", XFAIL)
run:new_line("string.lua", { on_line = 4, text = "x", indent = 4 })
run:new_line("table.lua", { on_line = 1, text = "b = 0,", indent = 2 })
run:new_line("table.lua", { on_line = 5, text = "4,", indent = 4 })
run:new_line("table.lua", { on_line = 7, text = "4,", indent = 4 })

View file

@ -15,7 +15,6 @@ describe("indent Python:", function()
"./aligned_indent.py",
"./branches.py",
"./hanging_indent.py",
"./join_lines.py",
"./nested_collections.py",
},
})
@ -26,8 +25,8 @@ describe("indent Python:", function()
run:new_line("basic_blocks.py", { on_line = 1, text = "wait,", indent = 4 })
run:new_line("basic_blocks.py", { on_line = 6, text = "x += 1", indent = 4 })
run:new_line("basic_blocks.py", { on_line = 10, text = "x += 1", indent = 8 })
run:new_line("basic_blocks.py", { on_line = 7, text = "x += 1", indent = 0 })
run:new_line("basic_blocks.py", { on_line = 11, text = "x += 1", indent = 4 })
run:new_line("basic_blocks.py", { on_line = 7, text = "x += 1", indent = 4 })
run:new_line("basic_blocks.py", { on_line = 11, text = "x += 1", indent = 8 })
run:new_line("basic_collections.py", { on_line = 3, text = "4,", indent = 4 })
run:new_line("comprehensions.py", { on_line = 8, text = "if x != 2", indent = 4 })
run:new_line("control_flow.py", { on_line = 23, text = "x = 4", indent = 4 }, "expected failure", XFAIL)
@ -39,9 +38,9 @@ describe("indent Python:", function()
run:new_line("nested_collections.py", { on_line = 5, text = "0,", indent = 12 })
run:new_line("nested_collections.py", { on_line = 6, text = ",0", indent = 12 })
run:new_line("nested_collections.py", { on_line = 29, text = "[1, 2],", indent = 12 })
run:new_line("nested_collections.py", { on_line = 39, text = "0,", indent = 5 })
run:new_line("nested_collections.py", { on_line = 39, text = "0,", indent = 5 }, "expected failure", XFAIL)
run:new_line("strings.py", { on_line = 14, text = "x", indent = 4 })
run:new_line("strings.py", { on_line = 15, text = "x", indent = 0 }, nil, XFAIL)
run:new_line("strings.py", { on_line = 16, text = "x", indent = 8 }, nil, XFAIL)
run:new_line("strings.py", { on_line = 15, text = "x", indent = 0 })
run:new_line("strings.py", { on_line = 16, text = "x", indent = 8 })
end)
end)

View file

@ -1,10 +1,10 @@
macro_rules! foo {
($a:ident, $b:ident, $c:ident) => {
struct $a;
struct $b;
struct a { value: $a };
struct b { value: $b };
};
($a:ident) => {
struct $a;
struct a { value: $a };
};
}

View file

@ -1,5 +1,4 @@
local Runner = require("tests.indent.common").Runner
local XFAIL = require("tests.indent.common").XFAIL
local run = Runner:new(it, "tests/indent/rust", {
tabstop = 4,
@ -10,17 +9,7 @@ local run = Runner:new(it, "tests/indent/rust", {
describe("indent Rust:", function()
describe("whole file:", function()
run:whole_file(".", {
expected_failures = {
"./enum.rs",
"./func.rs",
"./array.rs",
"./where.rs",
"./trait.rs",
"./string.rs",
"./macro.rs",
},
})
run:whole_file "."
end)
describe("new line:", function()
@ -29,8 +18,8 @@ describe("indent Rust:", function()
run:new_line("comment.rs", { on_line = 3, text = "a", indent = "/// " })
run:new_line("cond.rs", { on_line = 11, text = "x += 1;", indent = 12 })
run:new_line("cond.rs", { on_line = 2, text = "x += 1;", indent = 8 })
run:new_line("cond.rs", { on_line = 4, text = "x += 1;", indent = 8 }, "expected_failures", XFAIL)
run:new_line("cond.rs", { on_line = 6, text = "x += 1;", indent = 8 }, "expected_failures", XFAIL)
run:new_line("cond.rs", { on_line = 4, text = "x += 1;", indent = 8 })
run:new_line("cond.rs", { on_line = 6, text = "x += 1;", indent = 8 })
run:new_line("enum.rs", { on_line = 2, text = "Q,", indent = 4 })
run:new_line("enum.rs", { on_line = 4, text = "i32,", indent = 8 })
run:new_line("enum.rs", { on_line = 8, text = "z: u32,", indent = 8 })
@ -49,7 +38,7 @@ describe("indent Rust:", function()
run:new_line("mod.rs", { on_line = 1, text = "const Z: i32 = 1;", indent = 4 })
run:new_line("mod.rs", { on_line = 2, text = "const Z: i32 = 1;", indent = 4 })
run:new_line("mod.rs", { on_line = 6, text = "const Z: i32 = 1;", indent = 8 })
run:new_line("string.rs", { on_line = 2, text = "brave new", indent = 0 }, "expected_failures", XFAIL)
run:new_line("string.rs", { on_line = 2, text = "brave new", indent = 0 })
run:new_line("string.rs", { on_line = 5, text = "brave new \\", indent = 8 })
run:new_line("string.rs", { on_line = 9, text = "brave new \\", indent = 8 })
run:new_line("struct.rs", { on_line = 1, text = "z: i32,", indent = 4 })