fix(dart_indent): Fix dart case/default indent

add tests

add tests for fallthrough case

add more tests

keep functional tests
This commit is contained in:
Pham Huy Hoang 2023-04-13 01:42:53 +09:00 committed by Stephan Seitz
parent ba6c55b203
commit 36d4deb294
3 changed files with 49 additions and 2 deletions

View file

@ -13,6 +13,13 @@
(try_statement)
] @indent.begin
(switch_block
(_) @indent.begin
(#set! indent.immediate 1)
(#set! indent.start_at_same_line 1))
(switch_label) @indent.branch
[
"("
")"
@ -26,6 +33,9 @@
"}"
] @indent.end
(return_statement ";" @indent.end)
(break_statement ";" @indent.end)
; this one is for dedenting the else block
(if_statement (block) @indent.branch)

View file

@ -0,0 +1,30 @@
void test() {
switch(a) {
case 1:
}
}
void test() {
switch(a) {
default:
}
}
void test_break_dedent() {
switch(x) {
case 1:
break;
}
switch(y) {
case 2:
return;
}
}
void test_multi_case() {
switch(x) {
case 1:
case 2:
}
}

View file

@ -2,9 +2,9 @@ local Runner = require("tests.indent.common").Runner
local XFAIL = require("tests.indent.common").XFAIL
local run = Runner:new(it, "tests/indent/dart", {
tabstop = 4,
tabstop = 2,
shiftwidth = 2,
softtabstop = 0,
softtabstop = 2,
expandtab = true,
})
@ -25,6 +25,13 @@ describe("new line:", function()
run:new_line("class.dart", { on_line = 6, text = "'100'", indent = 8 }, "expected failure", XFAIL)
run:new_line("class.dart", { on_line = 7, text = "int five = 5", indent = 2 }, "expected failure", XFAIL)
run:new_line("try.dart", { on_line = 2, text = "var x;", indent = 4 })
run:new_line("switch.dart", { on_line = 3, text = "x = 1;", indent = 6 })
run:new_line("switch.dart", { on_line = 9, text = "x = 1;", indent = 6 })
run:new_line("switch.dart", { on_line = 3, text = "case 2:", indent = 4 })
run:new_line("switch.dart", { on_line = 16, text = "abc;", indent = 4 })
run:new_line("switch.dart", { on_line = 20, text = "abc;", indent = 4 })
run:new_line("switch.dart", { on_line = 28, text = "y++;", indent = 6 })
run:new_line("multiple_arguments.dart", { on_line = 10, text = "var x;", indent = 4 })
run:new_line(
"multiple_arguments.dart",