@@ -645,6 +645,103 @@ test "organize imports - edge cases" {
645
645
);
646
646
}
647
647
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
+
648
745
test "convert multiline string literal" {
649
746
try testConvertString (
650
747
\\const foo = \\Hell<cursor>o
0 commit comments