Tests/OrgEditorAppKitTests/TabTests.swift
26 lines · 1083 bytes
1import AppKit
2import OrgDocument
3import Testing
4@testable import OrgEditorAppKit
5
6/// Tabs stop every 8 columns from the line's start, as `tab-width` 8 does in Emacs, so text
7/// aligned with spaces under a tab-indented line stays aligned.
8@MainActor
9struct TabTests {
10 static let text = "* Lists\n\t1. Spelling and\n vice-versa.\n\t\ta. Design\n should\n"
11
12 func x(_ h: Harness, _ needle: String) -> CGFloat {
13 h.layout()
14 let offset = (Self.text as NSString).range(of: needle).location
15 return h.textView.firstRect(forCharacterRange: NSRange(location: offset, length: 1), actualRange: nil).minX
16 }
17
18 @Test(arguments: [true, false]) func tabsAreEightColumns(indented: Bool) {
19 let h = Harness(DocumentState(bytes: Array(Self.text.utf8)), layout: false)
20 h.editor.indented = indented
21 h.editor.restyleOutsideEditing(0..<(Self.text as NSString).length)
22 h.drainStyling()
23 #expect(abs(x(h, "Spelling") - x(h, "vice")) < 1)
24 #expect(abs(x(h, "Design") - x(h, "should")) < 1)
25 }
26}