Skip to content

Commit

Permalink
Add selection state and button action tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonisevener committed Dec 15, 2023
1 parent 8d73c22 commit 8d2ea94
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,44 @@ final class WKSourceEditorFormatterButtonActionTests: XCTestCase {
mediator.templateFormatter?.toggleTemplateFormatting(action: .remove, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four")
}

func testReferenceInsertAndRemove() throws {
let text = "One Two Three Four"
mediator.textView.attributedText = NSAttributedString(string: text)
mediator.textView.selectedRange = NSRange(location: 4, length: 3)
mediator.referenceFormatter?.toggleReferenceFormatting(action: .add, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One <ref>Two</ref> Three Four")
mediator.referenceFormatter?.toggleReferenceFormatting(action: .remove, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four")
}

func testReferenceInsertAndRemoveCursor() throws {
let text = "One Two Three Four"
mediator.textView.attributedText = NSAttributedString(string: text)
mediator.textView.selectedRange = NSRange(location: 4, length: 0)
mediator.referenceFormatter?.toggleReferenceFormatting(action: .add, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One <ref> </ref>Two Three Four")
mediator.referenceFormatter?.toggleReferenceFormatting(action: .remove, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four")
}

func testReferenceNamedRemoveAndInsert() throws {
let text = "One <ref name=\"testing\">Two</ref> Three Four"
mediator.textView.attributedText = NSAttributedString(string: text)
mediator.textView.selectedRange = NSRange(location: 24, length: 3)
mediator.referenceFormatter?.toggleReferenceFormatting(action: .remove, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four")
mediator.referenceFormatter?.toggleReferenceFormatting(action: .add, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One <ref>Two</ref> Three Four")
}

func testReferenceNamedRemoveAndInsertCursor() throws {
let text = "One <ref name=\"testing\">Two</ref> Three Four"
mediator.textView.attributedText = NSAttributedString(string: text)
mediator.textView.selectedRange = NSRange(location: 25, length: 0)
mediator.referenceFormatter?.toggleReferenceFormatting(action: .remove, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One Two Three Four")
mediator.referenceFormatter?.toggleReferenceFormatting(action: .add, in: mediator.textView)
XCTAssertEqual(mediator.textView.attributedText.string, "One <ref>Two</ref> Three Four")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,36 @@ final class WKSourceEditorTextFrameworkMediatorTests: XCTestCase {
let selectionStates1 = mediator.selectionState(selectedDocumentRange: NSRange(location: 1, length: 0))
XCTAssertFalse(selectionStates1.isHorizontalTemplate)
}

func testReferenceSelectionState() throws {
let text = "Testing <ref>Testing</ref> Testing"
mediator.textView.attributedText = NSAttributedString(string: text)

let selectionStates = mediator.selectionState(selectedDocumentRange: NSRange(location: 13, length: 7))
XCTAssertTrue(selectionStates.isHorizontalReference)
}

func testReferenceSelectionStateCursor() throws {
let text = "Testing <ref>Testing</ref> Testing"
mediator.textView.attributedText = NSAttributedString(string: text)

let selectionStates = mediator.selectionState(selectedDocumentRange: NSRange(location: 16, length: 0))
XCTAssertTrue(selectionStates.isHorizontalReference)
}

func testReferenceNamedSelectionState() throws {
let text = "Testing <ref name=\"testing\">Testing</ref> Testing"
mediator.textView.attributedText = NSAttributedString(string: text)

let selectionStates = mediator.selectionState(selectedDocumentRange: NSRange(location: 28, length: 7))
XCTAssertTrue(selectionStates.isHorizontalReference)
}

func testReferenceNamedSelectionStateCursor() throws {
let text = "Testing <ref name=\"testing\">Testing</ref> Testing"
mediator.textView.attributedText = NSAttributedString(string: text)

let selectionStates = mediator.selectionState(selectedDocumentRange: NSRange(location: 31, length: 0))
XCTAssertTrue(selectionStates.isHorizontalReference)
}
}

0 comments on commit 8d2ea94

Please sign in to comment.