-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from squareup/skorulis/getter-named
Add parameter to name-getters to allow customisation
- Loading branch information
Showing
10 changed files
with
204 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Created by Alexander skorulis on 28/7/2023. | ||
|
||
@testable import KnitCodeGen | ||
import SwiftSyntax | ||
import XCTest | ||
|
||
final class KnitDirectivesTests: XCTestCase { | ||
|
||
func testAccessLevel() throws { | ||
XCTAssertEqual( | ||
try parse(" @knit public"), | ||
.init(accessLevel: .public, getterConfig: []) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("@knit internal"), | ||
.init(accessLevel: .internal, getterConfig: []) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("@knit hidden"), | ||
.init(accessLevel: .hidden, getterConfig: []) | ||
) | ||
} | ||
|
||
func testKnitPrefix() { | ||
XCTAssertEqual( | ||
try parse("// @knit public"), | ||
.init(accessLevel: .public, getterConfig: []) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("knit public"), | ||
.empty | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("public @knit"), | ||
.empty | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("informational comment"), | ||
.empty | ||
) | ||
} | ||
|
||
func testGetterConfig() { | ||
XCTAssertEqual( | ||
try parse("// @knit getter-named"), | ||
.init(accessLevel: nil, getterConfig: [.identifiedGetter(nil)]) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("// @knit getter-named(\"customName\")"), | ||
.init(accessLevel: nil, getterConfig: [.identifiedGetter("customName")]) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("// @knit getter-callAsFunction"), | ||
.init(accessLevel: nil, getterConfig: [.callAsFunction]) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("// @knit getter-callAsFunction getter-named"), | ||
.init(accessLevel: nil, getterConfig: [.identifiedGetter(nil), .callAsFunction]) | ||
) | ||
|
||
XCTAssertEqual( | ||
try parse("// @knit getter-callAsFunction getter-named"), | ||
.init(accessLevel: nil, getterConfig: [.identifiedGetter(nil), .callAsFunction]) | ||
) | ||
} | ||
|
||
private func parse(_ comment: String) throws -> KnitDirectives { | ||
let trivia = Trivia(pieces: [.lineComment(comment)]) | ||
return try KnitDirectives.parse(leadingTrivia: trivia) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.