blob: 17b9cb0f5d46cad2fd912e3e1e50351acf0c7ec1 (
plain)
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
|
import Testing
@testable import NorgKeyboardToolbar
struct LineScannerTests {
@Test func lineStartFindsBeginningOfCurrentLine() {
let chars = Array("first\nsecond")
// Cursor inside "second" (offset 9 -> the 'o').
#expect(LineScanner.lineStart(in: chars, at: 9) == 6)
}
@Test func lineStartAtBufferStartIsZero() {
let chars = Array("hello")
#expect(LineScanner.lineStart(in: chars, at: 3) == 0)
}
@Test func lineStartJustAfterNewlineIsTheNewLine() {
let chars = Array("a\nb")
// Offset 2 sits at 'b', whose line starts right after the newline.
#expect(LineScanner.lineStart(in: chars, at: 2) == 2)
}
@Test func lineEndFindsNextNewline() {
let chars = Array("first\nsecond")
#expect(LineScanner.lineEnd(in: chars, at: 2) == 5)
}
@Test func lineEndAtLastLineIsBufferCount() {
let chars = Array("first\nsecond")
#expect(LineScanner.lineEnd(in: chars, at: 8) == chars.count)
}
@Test func lineEndOnNewlineStaysPut() {
let chars = Array("a\nb")
// Offset 1 is the newline itself.
#expect(LineScanner.lineEnd(in: chars, at: 1) == 1)
}
@Test func handlesEmptyBuffer() {
let chars: [Character] = []
#expect(LineScanner.lineStart(in: chars, at: 0) == 0)
#expect(LineScanner.lineEnd(in: chars, at: 0) == 0)
}
}
|