File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Sources/TecoCodeGeneratorTestHelpers Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1717 uses : actions/checkout@v3
1818 - name : Build
1919 run : swift build -c ${{ matrix.build-config }}
20+ - name : Test
21+ if : ${{ matrix.build-config == 'debug' }}
22+ run : swift test
Original file line number Diff line number Diff line change @@ -76,5 +76,10 @@ let package = Package(
7676 dependencies: [
7777 . byName( name: " TecoCodeGeneratorCommons " ) ,
7878 ] ) ,
79+ . target(
80+ name: " TecoCodeGeneratorTestHelpers " ,
81+ dependencies: [
82+ . byName( name: " TecoCodeGeneratorCommons " ) ,
83+ ] ) ,
7984 ]
8085)
Original file line number Diff line number Diff line change 1+ import SwiftSyntax
2+ @_implementationOnly import TecoCodeGeneratorCommons
3+ import XCTest
4+
5+ private func buildSyntax( _ buildable: some SyntaxProtocol ) -> [ String ] {
6+ // Format the code.
7+ let source = buildable. formatted ( using: CodeGenerationFormat ( ) )
8+
9+ // Work around styling issues regarding blank lines.
10+ let code = source. description. trimmingCharacters ( in: . whitespacesAndNewlines)
11+
12+ // Work around styling issues regarding trailing whitespaces.
13+ return code. split ( omittingEmptySubsequences: false , whereSeparator: \. isNewline) . map {
14+ var line = $0
15+ while line. last? . isWhitespace == true {
16+ line. removeLast ( )
17+ }
18+ return String ( line)
19+ }
20+ }
21+
22+ public func AssertBuilder( _ buildable: some SyntaxProtocol , _ result: String ) {
23+ // Format the code.
24+ let code = buildSyntax ( buildable) . joined ( separator: " \n " )
25+
26+ // Assert build result
27+ XCTAssertEqual ( code, result)
28+ }
29+
30+ public func AssertBuilder( _ buildable: some SyntaxProtocol , contains lines: [ String ] ) {
31+ // Format the code.
32+ let code = buildSyntax ( buildable)
33+
34+ // Assert build result
35+ for line in lines {
36+ XCTAssertTrue ( code. contains ( line) )
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments