forked from objcio/attributed-string-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.swift
71 lines (57 loc) · 1.84 KB
/
Tests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import XCTest
import SwiftUI
import AttributedStringBuilder
@AttributedStringBuilder
var example: some AttributedStringConvertible {
"Hello, World!"
.bold()
.modify { $0.backgroundColor = .yellow }
Array(repeating:
"""
This is some markdown with **strong** `code` text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tempus, tortor eu maximus gravida, ante diam fermentum magna, in gravida ex tellus ac purus.
- One
- Two
- Three
```
some code
```
And a number list:
1. One
1. Two
1. Three
Checklist:
- [ ] Unchecked item
- [x] Checked item
Another *paragraph*.
> A blockquote.
""".markdown() as any AttributedStringConvertible, count: 2)
Table(rows: [
.init(cells: [
.init(borderColor: .green, borderWidth: .init(right: 2), contents: "Table Testing"),
.init(contents: Embed {
Circle().fill(LinearGradient(colors: [.blue, .red], startPoint: .top, endPoint: .bottom))
.frame(width: 100, height: 100)
} )
])
])
.modify { $0.size = 10 }
// NSImage(systemSymbolName: "hand.wave", accessibilityDescription: nil)!
Embed {
HStack {
Image(systemName: "hand.wave")
.font(.largeTitle)
Text("Hello from SwiftUI")
Color.red.frame(width: 100, height: 50)
}
}
}
let sampleAttributes = Attributes(family: "Georgia", size: 16, textColor: .black, paragraphSpacing: 10)
class Tests: XCTestCase {
func testPDF() async {
let data = await example
.joined(separator: "\n")
.run(environment: .init(attributes: sampleAttributes))
.pdf()
try! data.write(to: .desktopDirectory.appending(component: "out.pdf"))
}
}