This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace _functionBuilder with resultBuilder
- Loading branch information
1 parent
f3e29fb
commit 4baef88
Showing
9 changed files
with
396 additions
and
54 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,3 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Guille on 6/2/21. | ||
// | ||
|
||
import cmark | ||
import Foundation | ||
|
||
|
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,107 @@ | ||
import CommonMark | ||
import XCTest | ||
|
||
final class BlockBuilderTests: XCTestCase { | ||
func testBuildBlock() { | ||
// given | ||
@BlockBuilder func build() -> [Block] { | ||
"Hello" | ||
"world!" | ||
} | ||
|
||
// when | ||
let result = build() | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.paragraph([.text("Hello")]), | ||
.paragraph([.text("world!")]), | ||
], | ||
result | ||
) | ||
} | ||
|
||
func testBuildArray() { | ||
// given | ||
@BlockBuilder func build() -> [Block] { | ||
for i in 0 ... 3 { | ||
"\(i)" | ||
} | ||
} | ||
|
||
// when | ||
let result = build() | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.paragraph([.text("0")]), | ||
.paragraph([.text("1")]), | ||
.paragraph([.text("2")]), | ||
.paragraph([.text("3")]), | ||
], | ||
result | ||
) | ||
} | ||
|
||
func testBuildOptional() { | ||
@BlockBuilder func build() -> [Block] { | ||
"Something is:" | ||
if true { | ||
BlockQuote { | ||
"true" | ||
} | ||
} | ||
} | ||
|
||
// when | ||
let result = build() | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.paragraph([.text("Something is:")]), | ||
.blockQuote( | ||
[.paragraph([.text("true")])] | ||
), | ||
], | ||
result | ||
) | ||
} | ||
|
||
func testBuildEither() { | ||
@BlockBuilder func build(_ value: Bool) -> [Block] { | ||
"Something is:" | ||
if value { | ||
BlockQuote { | ||
"true" | ||
} | ||
} else { | ||
"false" | ||
} | ||
} | ||
|
||
// when | ||
let result1 = build(true) | ||
let result2 = build(false) | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.paragraph([.text("Something is:")]), | ||
.blockQuote( | ||
[.paragraph([.text("true")])] | ||
), | ||
], | ||
result1 | ||
) | ||
XCTAssertEqual( | ||
[ | ||
.paragraph([.text("Something is:")]), | ||
.paragraph([.text("false")]), | ||
], | ||
result2 | ||
) | ||
} | ||
} |
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,109 @@ | ||
import CommonMark | ||
import XCTest | ||
|
||
final class InlineBuilderTests: XCTestCase { | ||
func testBuildBlock() { | ||
// given | ||
@InlineBuilder func build() -> [Inline] { | ||
"Hello " | ||
Strong { "world!" } | ||
} | ||
|
||
// when | ||
let result = build() | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.text("Hello "), | ||
.strong( | ||
[.text("world!")] | ||
), | ||
], | ||
result | ||
) | ||
} | ||
|
||
func testBuildArray() { | ||
// given | ||
@InlineBuilder func build() -> [Inline] { | ||
for i in 0 ... 3 { | ||
"\(i) " | ||
} | ||
} | ||
|
||
// when | ||
let result = build() | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.text("0 "), | ||
.text("1 "), | ||
.text("2 "), | ||
.text("3 "), | ||
], | ||
result | ||
) | ||
} | ||
|
||
func testBuildOptional() { | ||
@InlineBuilder func build() -> [Inline] { | ||
"Something is " | ||
if true { | ||
Emphasis { | ||
"true" | ||
} | ||
} | ||
} | ||
|
||
// when | ||
let result = build() | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.text("Something is "), | ||
.emphasis( | ||
[.text("true")] | ||
), | ||
], | ||
result | ||
) | ||
} | ||
|
||
func testBuildEither() { | ||
@InlineBuilder func build(_ value: Bool) -> [Inline] { | ||
"Something is " | ||
if value { | ||
Emphasis { | ||
"true" | ||
} | ||
} else { | ||
"false" | ||
} | ||
} | ||
|
||
// when | ||
let result1 = build(true) | ||
let result2 = build(false) | ||
|
||
// then | ||
XCTAssertEqual( | ||
[ | ||
.text("Something is "), | ||
.emphasis( | ||
[.text("true")] | ||
), | ||
], | ||
result1 | ||
) | ||
XCTAssertEqual( | ||
[ | ||
.text("Something is "), | ||
.text("false"), | ||
], | ||
result2 | ||
) | ||
} | ||
} |
Oops, something went wrong.