forked from CodeEditApp/CodeEditSourceEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTTextViewControllerTests.swift
96 lines (80 loc) · 3.2 KB
/
STTextViewControllerTests.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import XCTest
@testable import CodeEditTextView
import SwiftTreeSitter
import AppKit
final class STTextViewControllerTests: XCTestCase {
var controller: STTextViewController!
var theme: EditorTheme!
override func setUpWithError() throws {
theme = EditorTheme(
text: .textColor,
insertionPoint: .textColor,
invisibles: .gray,
background: .textBackgroundColor,
lineHighlight: .highlightColor,
selection: .selectedTextColor,
keywords: .systemPink,
commands: .systemBlue,
types: .systemMint,
attributes: .systemTeal,
variables: .systemCyan,
values: .systemOrange,
numbers: .systemYellow,
strings: .systemRed,
characters: .systemRed,
comments: .systemGreen
)
controller = STTextViewController(
text: .constant(""),
language: .default,
font: .monospacedSystemFont(ofSize: 11, weight: .medium),
theme: theme,
tabWidth: 4,
wrapLines: true,
editorOverscroll: 0.5,
useThemeBackground: true
)
}
func test_captureNames() throws {
// test for "keyword"
let captureName1 = "keyword"
let color1 = controller.attributesFor(CaptureName(rawValue: captureName1))[.foregroundColor] as? NSColor
XCTAssertEqual(color1, NSColor.systemPink)
// test for "comment"
let captureName2 = "comment"
let color2 = controller.attributesFor(CaptureName(rawValue: captureName2))[.foregroundColor] as? NSColor
XCTAssertEqual(color2, NSColor.systemGreen)
/* ... additional tests here ... */
// test for empty case
let captureName3 = ""
let color3 = controller.attributesFor(CaptureName(rawValue: captureName3))[.foregroundColor] as? NSColor
XCTAssertEqual(color3, NSColor.textColor)
// test for random case
let captureName4 = "abc123"
let color4 = controller.attributesFor(CaptureName(rawValue: captureName4))[.foregroundColor] as? NSColor
XCTAssertEqual(color4, NSColor.textColor)
}
func test_editorOverScroll() throws {
let scrollView = try XCTUnwrap(controller.view as? NSScrollView)
scrollView.frame = .init(x: .zero,
y: .zero,
width: 100,
height: 100)
// editorOverscroll: 0
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0)
controller.editorOverscroll = 0.5
controller.reloadUI()
// editorOverscroll: 0.5
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 50.0)
controller.editorOverscroll = 1.0
controller.reloadUI()
// editorOverscroll: 1.0
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 87.0)
}
func test_editorOverScroll_ZeroCondition() throws {
let scrollView = try XCTUnwrap(controller.view as? NSScrollView)
scrollView.frame = .zero
// editorOverscroll: 0
XCTAssertEqual(scrollView.contentView.contentInsets.bottom, 0)
}
}