forked from CodeEditApp/CodeEditSourceEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextViewController+MoveLinesTests.swift
More file actions
107 lines (91 loc) · 3.83 KB
/
TextViewController+MoveLinesTests.swift
File metadata and controls
107 lines (91 loc) · 3.83 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
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
97
98
99
100
101
102
103
104
105
106
107
//
// TextViewController+MoveLinesTests.swift
// CodeEditSourceEditor
//
// Created by Bogdan Belogurov on 01/06/2025.
//
import XCTest
@testable import CodeEditSourceEditor
@testable import CodeEditTextView
import CustomDump
final class TextViewControllerMoveLinesTests: XCTestCase {
var controller: TextViewController!
override func setUpWithError() throws {
controller = Mock.textViewController(theme: Mock.theme())
controller.loadView()
}
func testHandleMoveLinesUpForSingleLine() {
let strings: [(NSString, Int)] = [
("This is a test string\n", 0),
("With multiple lines\n", 22)
]
for (insertedString, location) in strings {
controller.textView.replaceCharacters(
in: [NSRange(location: location, length: 0)],
with: insertedString as String
)
}
let cursorRange = NSRange(location: 40, length: 0)
controller.textView.selectionManager.textSelections = [.init(range: cursorRange)]
controller.cursorPositions = [CursorPosition(range: cursorRange)]
controller.moveLinesUp()
let expectedString = "With multiple lines\nThis is a test string\n"
expectNoDifference(controller.string, expectedString)
}
func testHandleMoveLinesDownForSingleLine() {
let strings: [(NSString, Int)] = [
("This is a test string\n", 0),
("With multiple lines\n", 22)
]
for (insertedString, location) in strings {
controller.textView.replaceCharacters(
in: [NSRange(location: location, length: 0)],
with: insertedString as String
)
}
let cursorRange = NSRange(location: 0, length: 0)
controller.textView.selectionManager.textSelections = [.init(range: cursorRange)]
controller.cursorPositions = [CursorPosition(range: cursorRange)]
controller.moveLinesDown()
let expectedString = "With multiple lines\nThis is a test string\n"
expectNoDifference(controller.string, expectedString)
}
func testHandleMoveLinesUpForMultiLine() {
let strings: [(NSString, Int)] = [
("This is a test string\n", 0),
("With multiple lines\n", 22),
("And additional info\n", 42)
]
for (insertedString, location) in strings {
controller.textView.replaceCharacters(
in: [NSRange(location: location, length: 0)],
with: insertedString as String
)
}
let cursorRange = NSRange(location: 40, length: 15)
controller.textView.selectionManager.textSelections = [.init(range: cursorRange)]
controller.cursorPositions = [CursorPosition(range: cursorRange)]
controller.moveLinesUp()
let expectedString = "With multiple lines\nAnd additional info\nThis is a test string\n"
expectNoDifference(controller.string, expectedString)
}
func testHandleMoveLinesDownForMultiLine() {
let strings: [(NSString, Int)] = [
("This is a test string\n", 0),
("With multiple lines\n", 22),
("And additional info\n", 42)
]
for (insertedString, location) in strings {
controller.textView.replaceCharacters(
in: [NSRange(location: location, length: 0)],
with: insertedString as String
)
}
let cursorRange = NSRange(location: 0, length: 30)
controller.textView.selectionManager.textSelections = [.init(range: cursorRange)]
controller.cursorPositions = [CursorPosition(range: cursorRange)]
controller.moveLinesDown()
let expectedString = "And additional info\nThis is a test string\nWith multiple lines\n"
expectNoDifference(controller.string, expectedString)
}
}