Skip to content

Commit

Permalink
Use private extension
Browse files Browse the repository at this point in the history
  • Loading branch information
msrutek-paylocity committed Dec 5, 2023
1 parent 0f33374 commit 7c6ebb3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 66 deletions.
50 changes: 26 additions & 24 deletions Tests/RichTextKitTests/Data/RichTextDataFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,6 @@ final class RichTextDataFormatTests: XCTestCase {
uniformType: vendorType
)

private func idResult(for format: RichTextDataFormat) -> String {
format.id
}

private func isArchivedDataResult(for format: RichTextDataFormat) -> Bool {
format.isArchivedDataFormat
}

private func formatResult(for format: RichTextDataFormat) -> [RichTextDataFormat] {
format.convertibleFormats
}

private func extensionResult(for format: RichTextDataFormat) -> String {
format.standardFileExtension
}

private func imageResult(for format: RichTextDataFormat) -> Bool {
format.supportsImages
}

private func uniformTypeResult(for format: RichTextDataFormat) -> UTType {
format.uniformType
}

func testLibraryFormatsReturnAllNonVendorFormats() {
XCTAssertEqual(RichTextDataFormat.libraryFormats, [.archivedData, .plainText, .rtf])
}
Expand Down Expand Up @@ -91,3 +67,29 @@ final class RichTextDataFormatTests: XCTestCase {
XCTAssertEqual(uniformTypeResult(for: vendorFormat), vendorType)
}
}

private extension RichTextDataFormatTests {
func idResult(for format: RichTextDataFormat) -> String {
format.id
}

func isArchivedDataResult(for format: RichTextDataFormat) -> Bool {
format.isArchivedDataFormat
}

func formatResult(for format: RichTextDataFormat) -> [RichTextDataFormat] {
format.convertibleFormats
}

func extensionResult(for format: RichTextDataFormat) -> String {
format.standardFileExtension
}

func imageResult(for format: RichTextDataFormat) -> Bool {
format.supportsImages
}

func uniformTypeResult(for format: RichTextDataFormat) -> UTType {
format.uniformType
}
}
18 changes: 10 additions & 8 deletions Tests/RichTextKitTests/Extensions/String+ParagraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ final class String_ParagraphTests: XCTestCase {
private let single = "foo\nbar baz"
private let multi = "foo\nbar\rbaz"

private func currentResult(for string: String, from location: UInt) -> UInt {
string.findIndexOfCurrentParagraph(from: location)
}

private func nextResult(for string: String, from location: UInt) -> UInt {
string.findIndexOfNextParagraph(from: location)
}

func testIndexOfCurrentParagraphIsCorrectForEmptyString() {
XCTAssertEqual(currentResult(for: "", from: 0), 0)
XCTAssertEqual(currentResult(for: "", from: 20), 0)
Expand Down Expand Up @@ -70,3 +62,13 @@ final class String_ParagraphTests: XCTestCase {
XCTAssertEqual(nextResult(for: multi, from: 10), 8)
}
}

private extension String_ParagraphTests {
func currentResult(for string: String, from location: UInt) -> UInt {
string.findIndexOfCurrentParagraph(from: location)
}

func nextResult(for string: String, from location: UInt) -> UInt {
string.findIndexOfNextParagraph(from: location)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,6 @@ final class RichTextViewComponent_AttributesTests: XCTestCase {
super.tearDown()
}

private func assertEqualAttribute(_ attr: Any?) {
XCTAssertEqual(attr as? FontRepresentable, font)
}

private func assertEqualAttributes(_ attr: [NSAttributedString.Key: Any]) {
assertEqualAttribute(attr[.font])
}

private func assertNonEqualAttribute(_ attr: Any?) {
XCTAssertNotEqual(attr as? FontRepresentable, font)
}

private func assertNonEqualAttributes(_ attr: [NSAttributedString.Key: Any]) {
assertNonEqualAttribute(attr[.font])
}


func testTextAttributesIsValidForSelectedRange() {
textView.setSelectedRange(selectedRange)
textView.setCurrentRichTextAttribute(.font, to: font)
Expand Down Expand Up @@ -96,4 +79,23 @@ final class RichTextViewComponent_AttributesTests: XCTestCase {
assertEqualAttribute(textView.typingAttributes[.font])
}
}

private extension RichTextViewComponent_AttributesTests {
func assertEqualAttribute(_ attr: Any?) {
XCTAssertEqual(attr as? FontRepresentable, font)
}

func assertEqualAttributes(_ attr: [NSAttributedString.Key: Any]) {
assertEqualAttribute(attr[.font])
}

func assertNonEqualAttribute(_ attr: Any?) {
XCTAssertNotEqual(attr as? FontRepresentable, font)
}

func assertNonEqualAttributes(_ attr: [NSAttributedString.Key: Any]) {
assertNonEqualAttribute(attr[.font])
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase {
super.tearDown()
}

private func assertEqualFont(_ attr: Any?) {
XCTAssertEqual(attr as? FontRepresentable, font)
}

private func assertEqualFontSize(_ attr: Any?) {
XCTAssertEqual((attr as? FontRepresentable)?.pointSize, size)
}

private func assertNonEqualFont(_ attr: Any?) {
XCTAssertNotEqual(attr as? FontRepresentable, font)
}

private func assertNonEqualFontSize(_ attr: Any?) {
XCTAssertNotEqual((attr as? FontRepresentable)?.pointSize, size)
}


func testCurrentFontWorksForSelectedRange() {
textView.setSelectedRange(selectedRange)
textView.setCurrentFont(font)
Expand Down Expand Up @@ -104,4 +87,22 @@ final class RichTextViewComponent_FontSizeTests: XCTestCase {
assertEqualFontSize(textView.typingAttributes[.font])
}
}

private extension RichTextViewComponent_FontSizeTests {
func assertEqualFont(_ attr: Any?) {
XCTAssertEqual(attr as? FontRepresentable, font)
}

func assertEqualFontSize(_ attr: Any?) {
XCTAssertEqual((attr as? FontRepresentable)?.pointSize, size)
}

func assertNonEqualFont(_ attr: Any?) {
XCTAssertNotEqual(attr as? FontRepresentable, font)
}

func assertNonEqualFontSize(_ attr: Any?) {
XCTAssertNotEqual((attr as? FontRepresentable)?.pointSize, size)
}
}
#endif

0 comments on commit 7c6ebb3

Please sign in to comment.