Skip to content

Commit db444c7

Browse files
kimdvCippoX
authored andcommitted
Add test cases for spacing between attributes
1 parent 6d81de5 commit db444c7

File tree

3 files changed

+88
-5
lines changed

3 files changed

+88
-5
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
import SwiftSyntax
15+
import SwiftSyntaxBuilder
16+
17+
final class AttributeListSyntaxTests: XCTestCase {
18+
func testAttributeListSyntaxSpacing() {
19+
let buildable = AttributeListSyntax {
20+
AttributeSyntax("@inlinable")
21+
AttributeSyntax("@discardableResult")
22+
}
23+
assertBuildResult(
24+
buildable,
25+
"""
26+
@inlinable @discardableResult
27+
"""
28+
)
29+
}
30+
}

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,47 @@ final class FunctionTests: XCTestCase {
163163
}
164164
"""
165165
),
166+
#line: (
167+
DeclSyntax(
168+
"""
169+
@discardableResult
170+
public func foo() -> String {
171+
return "foo"
172+
}
173+
"""
174+
),
175+
"""
176+
@discardableResult
177+
public func foo() -> String {
178+
return "foo"
179+
}
180+
"""
181+
),
182+
#line: (
183+
DeclSyntax(
184+
FunctionDeclSyntax(
185+
attributes: [.attribute(AttributeSyntax("@inline(__always)")), .attribute(AttributeSyntax("@discardableResult"))],
186+
modifiers: [DeclModifierSyntax(name: .keyword(.public))],
187+
identifier: TokenSyntax.identifier("foo"),
188+
signature: FunctionSignatureSyntax(
189+
input: ParameterClauseSyntax(
190+
parameterList: FunctionParameterListSyntax {}
191+
),
192+
output: ReturnClauseSyntax(
193+
returnType: SimpleTypeIdentifierSyntax(name: .identifier("String"))
194+
)
195+
),
196+
bodyBuilder: {
197+
StmtSyntax(#"return "foo""#)
198+
}
199+
)
200+
),
201+
"""
202+
@inline(__always) @discardableResult public func foo() -> String {
203+
return "foo"
204+
}
205+
"""
206+
),
166207
#line: (
167208
DeclSyntax(
168209
FunctionDeclSyntax(

Tests/SwiftSyntaxBuilderTest/ImportTests.swift renamed to Tests/SwiftSyntaxBuilderTest/ImportDeclSyntaxTests.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,28 @@ import XCTest
1414
import SwiftSyntax
1515
import SwiftSyntaxBuilder
1616

17-
final class ImportTests: XCTestCase {
18-
func testImport() {
19-
let leadingTrivia = Trivia.unexpectedText("")
17+
final class ImportDeclSyntaxTests: XCTestCase {
18+
func testImportDeclSyntax() {
2019
let identifier = TokenSyntax.identifier("SwiftSyntax")
2120

2221
let importDecl = ImportDeclSyntax(
23-
leadingTrivia: leadingTrivia,
2422
path: AccessPathSyntax([AccessPathComponentSyntax(name: identifier)])
2523
)
2624

27-
assertBuildResult(importDecl, "␣import SwiftSyntax")
25+
assertBuildResult(importDecl, "import SwiftSyntax")
26+
}
27+
28+
func testImportWithAttribute() {
29+
let buildable = ImportDeclSyntax(
30+
attributes: [.attribute("@_exported")],
31+
path: [AccessPathComponentSyntax(name: "SwiftSyntax")]
32+
)
33+
34+
assertBuildResult(
35+
buildable,
36+
"""
37+
@_exported import SwiftSyntax
38+
"""
39+
)
2840
}
2941
}

0 commit comments

Comments
 (0)