forked from CodeEditApp/CodeEditTextView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmphasisManagerTests.swift
More file actions
37 lines (31 loc) · 1.38 KB
/
EmphasisManagerTests.swift
File metadata and controls
37 lines (31 loc) · 1.38 KB
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
import Testing
import Foundation
@testable import CodeEditTextView
@Suite()
struct EmphasisManagerTests {
@Test()
@MainActor
func testFlashEmphasisLayersNotLeaked() {
// Ensure layers are not leaked when switching from flash emphasis to any other emphasis type.
let textView = TextView(string: "Lorem Ipsum")
textView.frame = NSRect(x: 0, y: 0, width: 1000, height: 100)
textView.layoutManager.layoutLines(in: CGRect(origin: .zero, size: CGSize(width: 1000, height: 100)))
textView.emphasisManager?.addEmphasis(
Emphasis(range: NSRange(location: 0, length: 5), style: .standard, flash: true),
for: "e"
)
// Text layer and emphasis layer
#expect(textView.layer?.sublayers?.count == 2)
#expect(textView.emphasisManager?.getEmphases(for: "e").count == 1)
textView.emphasisManager?.addEmphases(
[Emphasis(range: NSRange(location: 0, length: 5), style: .underline(color: .red), flash: true)],
for: "e"
)
#expect(textView.layer?.sublayers?.count == 4)
#expect(textView.emphasisManager?.getEmphases(for: "e").count == 2)
textView.emphasisManager?.removeAllEmphases()
// No emphasis layers remain
#expect(textView.layer?.sublayers?.count == nil)
#expect(textView.emphasisManager?.getEmphases(for: "e").count == 0)
}
}