Skip to content

Commit b7551ec

Browse files
committed
feat(test): add new organize imports tests
1 parent c83b04f commit b7551ec

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

tests/lsp_features/code_actions.zig

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,103 @@ test "organize imports - edge cases" {
645645
);
646646
}
647647

648+
test "organize imports - duplicates" {
649+
try testOrganizeImports(
650+
\\const std = @import("std");
651+
\\const std = @import("std");
652+
\\
653+
\\fn foo() void { _ = std; }
654+
,
655+
\\const std = @import("std");
656+
\\
657+
\\fn foo() void { _ = std; }
658+
);
659+
try testOrganizeImports(
660+
\\const abc = @import("abc.zig");
661+
\\const xyz = @import("xyz.zig");
662+
\\const xyz = @import("xyz.zig");
663+
\\const abc = @import("abc.zig");
664+
\\const xyz = @import("xyz.zig");
665+
\\
666+
\\fn foo() void {
667+
\\ _ = xyz;
668+
\\ _ = abc;
669+
\\}
670+
,
671+
\\const abc = @import("abc.zig");
672+
\\const xyz = @import("xyz.zig");
673+
\\
674+
\\fn foo() void {
675+
\\ _ = xyz;
676+
\\ _ = abc;
677+
\\}
678+
);
679+
try testOrganizeImports(
680+
\\const abc = @import("abc.zig");
681+
\\const std = @import("std");
682+
\\const abc = @import("abc.zig");
683+
\\
684+
\\fn foo() void {
685+
\\ _ = std;
686+
\\ _ = abc;
687+
\\}
688+
,
689+
\\const std = @import("std");
690+
\\
691+
\\const abc = @import("abc.zig");
692+
\\
693+
\\fn foo() void {
694+
\\ _ = std;
695+
\\ _ = abc;
696+
\\}
697+
);
698+
}
699+
700+
test "organize imports - unused" {
701+
try testCleanImports(
702+
\\const std = @import("std");
703+
\\const mem = std.mem;
704+
\\const abc = @import("abc.zig");
705+
,
706+
\\const std = @import("std");
707+
\\
708+
\\
709+
);
710+
// pub decls are preserved
711+
try testCleanImports(
712+
\\const std = @import("std");
713+
\\pub const mem = std.mem;
714+
\\const abc = @import("abc.zig");
715+
,
716+
\\const std = @import("std");
717+
\\pub const mem = std.mem;
718+
\\
719+
\\
720+
);
721+
try testCleanImports(
722+
\\const abc = @import("abc.zig");
723+
\\pub const abc = @import("abc.zig");
724+
,
725+
\\pub const abc = @import("abc.zig");
726+
\\
727+
\\
728+
);
729+
try testCleanImports(
730+
\\const foo = @import("std").foo;
731+
\\const bar = @import("bar").bar;
732+
\\
733+
\\fn main() void {
734+
\\ foo();
735+
\\}
736+
,
737+
\\const foo = @import("std").foo;
738+
\\
739+
\\fn main() void {
740+
\\ foo();
741+
\\}
742+
);
743+
}
744+
648745
test "convert multiline string literal" {
649746
try testConvertString(
650747
\\const foo = \\Hell<cursor>o

0 commit comments

Comments
 (0)