@@ -32,4 +32,51 @@ class ImportDeclarationsTest {
3232 val expected = " import Foundation"
3333 assertEquals(expected, statements)
3434 }
35+
36+ @Test
37+ fun `it renders @testable declarations` () {
38+ val subject = ImportDeclarations ()
39+ subject.addImport(" MyPackage" , true )
40+ assertEquals(" @testable import MyPackage" , subject.toString())
41+ }
42+
43+ @Test
44+ fun `it preserves @testable declarations` () {
45+ val subject = ImportDeclarations ()
46+ subject.addImport(" MyPackage" , true )
47+ subject.addImport(" MyPackage" , false )
48+ assertEquals(" @testable import MyPackage" , subject.toString())
49+ }
50+
51+ @Test
52+ fun `it renders a single @_spi() declaration` () {
53+ val subject = ImportDeclarations ()
54+ subject.addImport(" MyPackage" , false , " MyInternalAPI" )
55+ assertEquals(" @_spi(MyInternalAPI) import MyPackage" , subject.toString())
56+ }
57+
58+ @Test
59+ fun `it renders a single @_spi() and @testable declaration` () {
60+ val subject = ImportDeclarations ()
61+ subject.addImport(" MyPackage" , true , " MyInternalAPI" )
62+ assertEquals(" @testable @_spi(MyInternalAPI) import MyPackage" , subject.toString())
63+ }
64+
65+ @Test
66+ fun `it renders multiple @_spi() declarations` () {
67+ val subject = ImportDeclarations ()
68+ subject.addImport(" MyPackage" , false , " MyInternalAPI1" )
69+ subject.addImport(" MyPackage" , false , " MyInternalAPI2" )
70+ assertEquals(" @_spi(MyInternalAPI1) @_spi(MyInternalAPI2) import MyPackage" , subject.toString())
71+ }
72+
73+ @Test
74+ fun `it deduplicates @_spi() declarations` () {
75+ val subject = ImportDeclarations ()
76+ subject.addImport(" MyPackage" , false , " MyInternalAPI1" )
77+ subject.addImport(" MyPackage" , false , " MyInternalAPI2" )
78+ subject.addImport(" MyPackage" , false , " MyInternalAPI1" )
79+ subject.addImport(" MyPackage" , false , " MyInternalAPI2" )
80+ assertEquals(" @_spi(MyInternalAPI1) @_spi(MyInternalAPI2) import MyPackage" , subject.toString())
81+ }
3582}
0 commit comments