File tree Expand file tree Collapse file tree 2 files changed +80
-0
lines changed
Tests/SwiftFormatRulesTests Expand file tree Collapse file tree 2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -541,4 +541,82 @@ final class OrderedImportsTests: LintOrFormatRuleTestCase {
541
541
542
542
XCTAssertFormatting ( OrderedImports . self, input: input, expected: expected)
543
543
}
544
+
545
+ func testConditionalImports( ) {
546
+ let input =
547
+ """
548
+ import Zebras
549
+ import Apples
550
+ #if canImport(Darwin)
551
+ import Darwin
552
+ #elseif canImport(Glibc)
553
+ import Glibc
554
+ #endif
555
+ import Aardvarks
556
+
557
+ foo()
558
+ bar()
559
+ baz()
560
+ """
561
+
562
+ let expected =
563
+ """
564
+ import Aardvarks
565
+ import Apples
566
+ import Zebras
567
+
568
+ #if canImport(Darwin)
569
+ import Darwin
570
+ typealias SomeNativeTypeHandle = some_darwin_type_t
571
+ #elseif canImport(Glibc)
572
+ import Glibc
573
+ typealias SomeNativeTypeHandle = some_glibc_type_t
574
+ #endif
575
+
576
+ foo()
577
+ bar()
578
+ baz()
579
+ """
580
+
581
+ XCTAssertFormatting ( OrderedImports . self, input: input, expected: expected)
582
+ }
583
+
584
+ func testIgnoredConditionalImports( ) {
585
+ let input =
586
+ """
587
+ import Zebras
588
+ import Apples
589
+ #if canImport(Darwin)
590
+ import Darwin
591
+ #elseif canImport(Glibc)
592
+ import Glibc
593
+ #endif
594
+ // swift-format-ignore
595
+ import Aardvarks
596
+
597
+ foo()
598
+ bar()
599
+ baz()
600
+ """
601
+
602
+ let expected =
603
+ """
604
+ import Apples
605
+ import Zebras
606
+
607
+ #if canImport(Darwin)
608
+ import Darwin
609
+ #elseif canImport(Glibc)
610
+ import Glibc
611
+ #endif
612
+ // swift-format-ignore
613
+ import Aardvarks
614
+
615
+ foo()
616
+ bar()
617
+ baz()
618
+ """
619
+
620
+ XCTAssertFormatting ( OrderedImports . self, input: input, expected: expected)
621
+ }
544
622
}
Original file line number Diff line number Diff line change @@ -264,12 +264,14 @@ extension OrderedImportsTests {
264
264
// `swift test --generate-linuxmain`
265
265
// to regenerate.
266
266
static let __allTests__OrderedImportsTests = [
267
+ ( " testConditionalImports " , testConditionalImports) ,
267
268
( " testDisableOrderedImports " , testDisableOrderedImports) ,
268
269
( " testDisableOrderedImportsMovingComments " , testDisableOrderedImportsMovingComments) ,
269
270
( " testDuplicateAttributedImports " , testDuplicateAttributedImports) ,
270
271
( " testDuplicateCommentedImports " , testDuplicateCommentedImports) ,
271
272
( " testDuplicateIgnoredImports " , testDuplicateIgnoredImports) ,
272
273
( " testEmptyFile " , testEmptyFile) ,
274
+ ( " testIgnoredConditionalImports " , testIgnoredConditionalImports) ,
273
275
( " testImportsOrderWithDocComment " , testImportsOrderWithDocComment) ,
274
276
( " testImportsOrderWithoutModuleType " , testImportsOrderWithoutModuleType) ,
275
277
( " testInvalidImportsOrder " , testInvalidImportsOrder) ,
You can’t perform that action at this time.
0 commit comments