From 0aed46e2fee2dd788a334658f58d9634598b355e Mon Sep 17 00:00:00 2001 From: Marcin Krzyzanowski Date: Fri, 23 Aug 2024 20:18:12 +0200 Subject: [PATCH] fix tests build --- Package.swift | 3 +- .../STTextViewAppKitTests/ContentTests.swift | 29 ++++--- .../TextSelectionNavigationTests.swift | 76 +++++++++---------- .../TypingAttributesTests.swift | 6 +- Tests/STTextViewAppKitTests/UndoTests.swift | 30 ++++---- 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/Package.swift b/Package.swift index a2061ba..0cab2ce 100644 --- a/Package.swift +++ b/Package.swift @@ -34,7 +34,8 @@ let package = Package( dependencies: [ .target(name: "STTextViewCommon"), .target(name: "STObjCLandShim", condition: .when(platforms: [.macOS])), - .product(name: "STTextKitPlus", package: "STTextKitPlus") + .product(name: "STTextKitPlus", package: "STTextKitPlus"), + .product(name: "CoreTextSwift", package: "CoreTextSwift") ] ), .target( diff --git a/Tests/STTextViewAppKitTests/ContentTests.swift b/Tests/STTextViewAppKitTests/ContentTests.swift index 6f5a4c4..e26c8dc 100644 --- a/Tests/STTextViewAppKitTests/ContentTests.swift +++ b/Tests/STTextViewAppKitTests/ContentTests.swift @@ -6,35 +6,35 @@ class ContentTests : XCTestCase { func testContentUpdate() { let textView = STTextView() - XCTAssertTrue(textView.string.isEmpty) + XCTAssertTrue(textView.text!.isEmpty) XCTAssertEqual(textView.attributedString().length, 0) - textView.string = "1234" - XCTAssertEqual(textView.string.count, 4) + textView.text = "1234" + XCTAssertEqual(textView.text!.count, 4) XCTAssertEqual(textView.attributedString().length, 4) - textView.string = "5678" - XCTAssertEqual(textView.string.count, 4) + textView.text = "5678" + XCTAssertEqual(textView.text!.count, 4) XCTAssertEqual(textView.attributedString().length, 4) - textView.setAttributedString(NSAttributedString(string: "12345")) - XCTAssertEqual(textView.string.count, 5) + textView.attributedText = NSAttributedString(string: "12345") + XCTAssertEqual(textView.text!.count, 5) XCTAssertEqual(textView.attributedString().length, 5) - textView.setAttributedString(NSAttributedString(string: "6789")) - XCTAssertEqual(textView.string.count, 4) + textView.attributedText = NSAttributedString(string: "6789") + XCTAssertEqual(textView.text!.count, 4) XCTAssertEqual(textView.attributedString().length, 4) - textView.string = "" - XCTAssertEqual(textView.string.count, 0) + textView.text = "" + XCTAssertEqual(textView.text!.count, 0) XCTAssertEqual(textView.attributedString().length, 0) } func testContentUpdateStringAfterAttributedString() { let textView = STTextView() - textView.setAttributedString(NSAttributedString(string: "1234")) - textView.string = "" - XCTAssertEqual(textView.string.count, 0) + textView.attributedText = NSAttributedString(string: "1234") + textView.text = "" + XCTAssertEqual(textView.text!.count, 0) XCTAssertEqual(textView.attributedString().length, 0) } @@ -54,7 +54,6 @@ class ContentTests : XCTestCase { XCTAssertEqual(textView.typingAttributes[.font] as! NSFont, NSFont.systemFont(ofSize: 96)) XCTExpectFailure("nil NSFont given") - textView.font = nil XCTAssertNotNil(textView.font) XCTAssertNotNil(textView.typingAttributes[.font]) } diff --git a/Tests/STTextViewAppKitTests/TextSelectionNavigationTests.swift b/Tests/STTextViewAppKitTests/TextSelectionNavigationTests.swift index 76a3baf..8708782 100644 --- a/Tests/STTextViewAppKitTests/TextSelectionNavigationTests.swift +++ b/Tests/STTextViewAppKitTests/TextSelectionNavigationTests.swift @@ -5,7 +5,7 @@ import XCTest final class TextSelectionNavigationTests: XCTestCase { func testMoveLeft() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveLeft(nil) @@ -16,7 +16,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveLeftAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveLeftAndModifySelection(nil) @@ -27,7 +27,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveRight() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 1, length: 0)) textView.moveRight(nil) @@ -38,7 +38,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveRightAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 1, length: 0)) textView.moveRightAndModifySelection(nil) @@ -51,7 +51,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveUp() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 9, length: 0)) textView.moveUp(nil) @@ -62,7 +62,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveUpAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 9, length: 0)) textView.moveUpAndModifySelection(nil) @@ -71,7 +71,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveDown() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 1, length: 0)) textView.moveDown(nil) @@ -80,7 +80,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveDownAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 1, length: 0)) textView.moveDownAndModifySelection(nil) @@ -89,7 +89,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveForward() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 1, length: 0)) textView.moveForward(nil) @@ -102,7 +102,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveForwardAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 1, length: 0)) textView.moveForwardAndModifySelection(nil) @@ -115,7 +115,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveBackward() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveBackward(nil) @@ -128,7 +128,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveBackwardAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 4, length: 0)) textView.moveBackwardAndModifySelection(nil) @@ -141,7 +141,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordLeft() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 0, length: 0)) textView.moveWordLeft(nil) @@ -150,7 +150,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordLeftAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 0, length: 0)) textView.moveWordLeftAndModifySelection(nil) @@ -159,7 +159,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordRight() { let textView = STTextView() - textView.setAttributedString(.init("Hello world\nSecond Line")) + textView.attributedText = .init("Hello world\nSecond Line") textView.setSelectedRange(NSRange(location: 0, length: 0)) textView.moveWordRight(nil) @@ -172,7 +172,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordRightAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("Hello world\nSecond Line")) + textView.attributedText = .init("Hello world\nSecond Line") textView.setSelectedRange(NSRange(location: 0, length: 0)) textView.moveWordRightAndModifySelection(nil) @@ -185,7 +185,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordForward() { let textView = STTextView() - textView.setAttributedString(.init("Hello world\nSecond Line")) + textView.attributedText = .init("Hello world\nSecond Line") textView.setSelectedRange(NSRange(location: 0, length: 0)) textView.moveWordForward(nil) @@ -198,7 +198,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordForwardAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("Hello world\nSecond Line")) + textView.attributedText = .init("Hello world\nSecond Line") textView.setSelectedRange(NSRange(location: 0, length: 0)) textView.moveWordForwardAndModifySelection(nil) @@ -211,7 +211,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordBackward() { let textView = STTextView() - textView.setAttributedString(.init("Hello world\nSecond Line")) + textView.attributedText = .init("Hello world\nSecond Line") textView.setSelectedRange(NSRange(location: 12, length: 0)) textView.moveWordBackward(nil) @@ -222,7 +222,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveWordBackwardAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("Hello world\nSecond Line")) + textView.attributedText = .init("Hello world\nSecond Line") textView.setSelectedRange(NSRange(location: 12, length: 0)) textView.moveWordBackwardAndModifySelection(nil) @@ -233,7 +233,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToBeginningOfLine() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToBeginningOfLine(nil) @@ -244,7 +244,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToBeginningOfLineAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToBeginningOfLineAndModifySelection(nil) @@ -255,7 +255,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToLeftEndOfLine() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToLeftEndOfLine(nil) @@ -266,7 +266,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToLeftEndOfLineAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToLeftEndOfLineAndModifySelection(nil) @@ -277,7 +277,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToEndOfLine() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToEndOfLine(nil) @@ -288,7 +288,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToEndOfLineAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToEndOfLineAndModifySelection(nil) @@ -299,7 +299,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToRightEndOfLine() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToRightEndOfLine(nil) @@ -310,7 +310,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToRightEndOfLineAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToRightEndOfLineAndModifySelection(nil) @@ -321,7 +321,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveParagraphForwardAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveParagraphForwardAndModifySelection(nil) @@ -332,7 +332,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveParagraphBackwardAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveParagraphBackwardAndModifySelection(nil) @@ -343,7 +343,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToBeginningOfParagraph() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToBeginningOfParagraph(nil) @@ -354,7 +354,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToBeginningOfParagraphAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToBeginningOfParagraphAndModifySelection(nil) @@ -365,7 +365,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToEndOfParagraph() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToEndOfParagraph(nil) @@ -376,7 +376,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToEndOfParagraphAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToEndOfParagraphAndModifySelection(nil) @@ -387,7 +387,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToBeginningOfDocument() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToBeginningOfDocument(nil) @@ -398,7 +398,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToBeginningOfDocumentAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToBeginningOfDocumentAndModifySelection(nil) @@ -409,7 +409,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToEndOfDocument() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToEndOfDocument(nil) @@ -420,7 +420,7 @@ final class TextSelectionNavigationTests: XCTestCase { func testMoveToEndOfDocumentAndModifySelection() { let textView = STTextView() - textView.setAttributedString(.init("012\n456\n89")) + textView.attributedText = .init("012\n456\n89") textView.setSelectedRange(NSRange(location: 5, length: 0)) textView.moveToEndOfDocumentAndModifySelection(nil) diff --git a/Tests/STTextViewAppKitTests/TypingAttributesTests.swift b/Tests/STTextViewAppKitTests/TypingAttributesTests.swift index fd6e9e7..594a740 100644 --- a/Tests/STTextViewAppKitTests/TypingAttributesTests.swift +++ b/Tests/STTextViewAppKitTests/TypingAttributesTests.swift @@ -44,7 +44,7 @@ class TypingAttributesTests : XCTestCase { XCTAssertTrue(nstv.string.utf16.count == 10) sttv.insertText(attributedString, replacementRange: NSRange(location: 0, length: 0)) - XCTAssertEqual(nstv.string.utf16.count, sttv.string.utf16.count) + XCTAssertEqual(nstv.string.utf16.count, sttv.text!.utf16.count) XCTAssertEqual(nstv.font, sttv.font) XCTAssertEqual(nstv.selectedRange(), sttv.selectedRange()) @@ -62,7 +62,7 @@ class TypingAttributesTests : XCTestCase { func testSetFontContent() { let textView = STTextView() - textView.string = "0123456789" + textView.text! = "0123456789" XCTAssertNotNil(textView.font) textView.font = NSFont.boldSystemFont(ofSize: 99) @@ -73,7 +73,7 @@ class TypingAttributesTests : XCTestCase { func testSetFontContentRange() { let textView = STTextView() - textView.string = "0123456789" + textView.text! = "0123456789" let beforeChange = textView.typingAttributes // "12" is size of 55 textView.addAttributes([.font: NSFont.systemFont(ofSize: 55)], range: NSRange(location: 1, length: 2)) diff --git a/Tests/STTextViewAppKitTests/UndoTests.swift b/Tests/STTextViewAppKitTests/UndoTests.swift index c172ca9..e8b5241 100644 --- a/Tests/STTextViewAppKitTests/UndoTests.swift +++ b/Tests/STTextViewAppKitTests/UndoTests.swift @@ -9,22 +9,22 @@ final class UndoTests: XCTestCase { textView.insertText("b") textView.undo(nil) - XCTAssertEqual(textView.string, "a") + XCTAssertEqual(textView.text!, "a") XCTAssertEqual(textView.selectedRange(), NSRange(location: 1, length: 0)) } func testPasteLongerThanCurrentContentUndo() { let textView = STTextView() - textView.string = "first line\nsecond line" + textView.text! = "first line\nsecond line" textView.setSelectedRange(NSRange(location: 11, length: 11)) NSPasteboard.general.clearContents() NSPasteboard.general.setString("new second line\nthird line", forType: .string) textView.paste(nil) - XCTAssertEqual(textView.string, "first line\nnew second line\nthird line") + XCTAssertEqual(textView.text!, "first line\nnew second line\nthird line") textView.undo(nil) - XCTAssertEqual(textView.string, "first line\nsecond line") + XCTAssertEqual(textView.text!, "first line\nsecond line") textView.setSelectedRange(NSRange(location: 11, length: 11)) } @@ -34,11 +34,11 @@ final class UndoTests: XCTestCase { textView.setSelectedRange(NSRange(location: 3, length: 3)) textView.insertText("a") - XCTAssertEqual(textView.string, "123a789") + XCTAssertEqual(textView.text!, "123a789") textView.undo(nil) XCTAssertEqual(textView.selectedRange(), NSRange(location: 3, length: 3)) - XCTAssertEqual(textView.string, "123456789") + XCTAssertEqual(textView.text!, "123456789") } func testTypingCoalescing() throws { @@ -48,16 +48,16 @@ final class UndoTests: XCTestCase { textView.keyDown(with: try .create(key: .return)) textView.keyDown(with: try .create(characters: "c")) textView.keyDown(with: try .create(characters: "d")) - XCTAssertEqual(textView.string, "ab\ncd") + XCTAssertEqual(textView.text!, "ab\ncd") textView.undo(nil) - XCTAssertEqual(textView.string, "ab\n") + XCTAssertEqual(textView.text!, "ab\n") textView.undo(nil) - XCTAssertEqual(textView.string, "ab") + XCTAssertEqual(textView.text!, "ab") textView.undo(nil) - XCTAssertEqual(textView.string, "") + XCTAssertEqual(textView.text!, "") } func testRedo() { @@ -66,19 +66,19 @@ final class UndoTests: XCTestCase { textView.setSelectedRange(NSRange(location: 3, length: 3)) textView.insertText("a") - XCTAssertEqual(textView.string, "123a789") + XCTAssertEqual(textView.text!, "123a789") textView.undo(nil) - XCTAssertEqual(textView.string, "123456789") + XCTAssertEqual(textView.text!, "123456789") textView.undo(nil) - XCTAssertEqual(textView.string, "") + XCTAssertEqual(textView.text!, "") textView.redo(nil) - XCTAssertEqual(textView.string, "123456789") + XCTAssertEqual(textView.text!, "123456789") textView.redo(nil) - XCTAssertEqual(textView.string, "123a789") + XCTAssertEqual(textView.text!, "123a789") } } #endif