-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathTextViewController+IndentTests.swift
105 lines (80 loc) · 4.01 KB
/
TextViewController+IndentTests.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
97
98
99
100
101
102
103
104
105
//
// TextViewController+IndentTests.swift
// CodeEditSourceEditor
//
// Created by Ludwig, Tom on 08.10.24.
//
import XCTest
@testable import CodeEditSourceEditor
final class TextViewControllerIndentTests: XCTestCase {
var controller: TextViewController!
override func setUpWithError() throws {
controller = Mock.textViewController(theme: Mock.theme())
controller.loadView()
}
func testHandleIndentWithSpacesInwards() {
controller.setText(" This is a test string")
let cursorPositions = [CursorPosition(range: NSRange(location: 0, length: 0))]
controller.cursorPositions = cursorPositions
controller.handleIndent(inwards: true)
XCTAssertEqual(controller.string, "This is a test string")
// Normally, 4 spaces are used for indentation; however, now we only insert 2 leading spaces.
// The outcome should be the same, though.
controller.setText(" This is a test string")
controller.cursorPositions = cursorPositions
controller.handleIndent(inwards: true)
XCTAssertEqual(controller.string, "This is a test string")
}
func testHandleIndentWithSpacesOutwards() {
controller.setText("This is a test string")
let cursorPositions = [CursorPosition(range: NSRange(location: 0, length: 0))]
controller.cursorPositions = cursorPositions
controller.handleIndent(inwards: false)
XCTAssertEqual(controller.string, " This is a test string")
}
func testHandleIndentWithTabsInwards() {
controller.setText("\tThis is a test string")
controller.indentOption = .tab
let cursorPositions = [CursorPosition(range: NSRange(location: 0, length: 0))]
controller.cursorPositions = cursorPositions
controller.handleIndent(inwards: true)
XCTAssertEqual(controller.string, "This is a test string")
}
func testHandleIndentWithTabsOutwards() {
controller.setText("This is a test string")
controller.indentOption = .tab
let cursorPositions = [CursorPosition(range: NSRange(location: 0, length: 0))]
controller.cursorPositions = cursorPositions
controller.handleIndent()
// Normally, we expect nothing to happen because only one line is selected.
// However, this logic is not handled inside `handleIndent`.
XCTAssertEqual(controller.string, "\tThis is a test string")
}
func testHandleIndentMultiLine() {
controller.indentOption = .tab
controller.setText("This is a test string\nWith multiple lines\nAnd some indentation")
let cursorPositions = [CursorPosition(range: NSRange(location: 0, length: 5))]
controller.cursorPositions = cursorPositions
controller.handleIndent()
let expectedString = "\tThis is a test string\nWith multiple lines\nAnd some indentation"
XCTAssertEqual(controller.string, expectedString)
}
func testHandleInwardIndentMultiLine() {
controller.indentOption = .tab
controller.setText("\tThis is a test string\n\tWith multiple lines\n\tAnd some indentation")
let cursorPositions = [CursorPosition(range: NSRange(location: 0, length: controller.string.count))]
controller.cursorPositions = cursorPositions
controller.handleIndent(inwards: true)
let expectedString = "This is a test string\nWith multiple lines\nAnd some indentation"
XCTAssertEqual(controller.string, expectedString)
}
func testMultipleLinesHighlighted() {
controller.setText("\tThis is a test string\n\tWith multiple lines\n\tAnd some indentation")
var cursorPositions = [CursorPosition(range: NSRange(location: 0, length: controller.string.count))]
controller.cursorPositions = cursorPositions
XCTAssert(controller.multipleLinesHighlighted())
cursorPositions = [CursorPosition(range: NSRange(location: 0, length: 5))]
controller.cursorPositions = cursorPositions
XCTAssertFalse(controller.multipleLinesHighlighted())
}
}