-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup test with extension file #498
Merged
andrewtavis
merged 7 commits into
scribe-org:main
from
vickcoo:setup-test-with-extension-file
Sep 2, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d40635
Setup unit test with first test file
vickcoo b8f8f38
Add unit tests to extension
vickcoo c20ec76
Revert xcscheme
vickcoo 697e67d
Add `*.xcscheme` to gitignore
vickcoo d76eafd
Update Extension unit tests
vickcoo 2b6b964
Revert Scribe.xcscheme mistake
vickcoo 2d3772d
Reorder tests directories and validate running tests
andrewtavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
import Foundation | ||
@testable import Scribe | ||
import XCTest | ||
|
||
// MARK: secondToLast | ||
|
||
class ExtensionTest: XCTestCase { | ||
func testSecondToLast_notNil() { | ||
let array = [1, 2, 3, 4, 5] | ||
|
||
let result = array.secondToLast()! | ||
|
||
XCTAssertEqual(result, 4) | ||
} | ||
|
||
func testSecondToLast_nil() { | ||
let array = [String]() | ||
|
||
let result = array.secondToLast() | ||
|
||
XCTAssertEqual(result, nil) | ||
} | ||
} | ||
|
||
// MARK: unique | ||
|
||
extension ExtensionTest { | ||
func testUnique_uniqueElements_withoutDuplicates() { | ||
let array = [1, 2, 3, 4, 5] | ||
let expectedResult = [1, 2, 3, 4, 5] | ||
|
||
let result = array.unique() | ||
|
||
XCTAssertEqual(result, expectedResult) | ||
} | ||
|
||
func testUnique_uniqueElements_withDuplicates() { | ||
let array = [1, 2, 2, 4, 5] | ||
let expectedResult = [1, 2, 4, 5] | ||
|
||
let result = array.unique() | ||
|
||
XCTAssertEqual(result, expectedResult) | ||
} | ||
} | ||
|
||
// MARK: index | ||
|
||
extension ExtensionTest { | ||
func testIndex_correctIndex_withValidIndex() { | ||
let string = "Hello, World!" | ||
let index = 5 | ||
|
||
let result = string.index(fromIdx: index) | ||
|
||
XCTAssertEqual(result, string.index(string.startIndex, offsetBy: index)) | ||
} | ||
} | ||
|
||
// MARK: substring | ||
|
||
extension ExtensionTest { | ||
func testSubstringFromIdx_correctString_withValidIndex() { | ||
let string = "Hello, World!" | ||
let index = 7 | ||
|
||
let result = string.substring(fromIdx: index) | ||
|
||
XCTAssertEqual(result, "World!") | ||
} | ||
|
||
func testSubstringToIdx_correctString_withValidIndex() { | ||
let string = "Hello, World!" | ||
let index = 5 | ||
|
||
let result = string.substring(toIdx: index) | ||
|
||
XCTAssertEqual(result, "Hello") | ||
} | ||
|
||
func testSubstringWithRange_correctString_withValidRange() { | ||
let string = "Hello, World!" | ||
let range = Range(2 ... 4) | ||
|
||
let result = string.substring(with: range) | ||
|
||
XCTAssertEqual(result, "llo") | ||
} | ||
} | ||
|
||
// MARK: insertPriorToCursor | ||
|
||
extension ExtensionTest { | ||
func testInsertPriorToCursor() { | ||
let string = "Hello" | ||
let char = "Scribe" | ||
let expectedResult = "HellScribe│" | ||
|
||
let result = string.insertPriorToCursor(char: char) | ||
|
||
XCTAssertEqual(result, expectedResult) | ||
} | ||
} | ||
|
||
// MARK: deletePriorToCursor | ||
|
||
extension ExtensionTest { | ||
func testDeletePriorToCursor() { | ||
let string = "Hello" | ||
let expectedResult = "Hel│" | ||
|
||
let result = string.deletePriorToCursor() | ||
|
||
XCTAssertEqual(result, expectedResult) | ||
} | ||
} | ||
|
||
// MARK: isLowercase | ||
|
||
extension ExtensionTest { | ||
func testIsLowercase() { | ||
XCTAssertEqual("hello".isLowercase, true) | ||
XCTAssertEqual("HELLO".isLowercase, false) | ||
XCTAssertEqual("Hello".isLowercase, false) | ||
// XCTAssertEqual("".isLowercase, false) | ||
XCTAssertEqual("👋🏻hello".isLowercase, true) | ||
} | ||
} | ||
|
||
// MARK: isUppercase | ||
|
||
extension ExtensionTest { | ||
func testIsUppercase() { | ||
XCTAssertEqual("HELLO".isUppercase, true) | ||
XCTAssertEqual("Hello".isUppercase, false) | ||
XCTAssertEqual("hello".isUppercase, false) | ||
// XCTAssertEqual("".isUppercase, false) | ||
XCTAssertEqual("👋🏻HELLO".isUppercase, true) | ||
} | ||
} | ||
|
||
// MARK: isCapitalized | ||
|
||
extension ExtensionTest { | ||
func testIsCapitalized() { | ||
XCTAssertEqual("Hello".isCapitalized, true) | ||
XCTAssertEqual("hello".isCapitalized, false) | ||
XCTAssertEqual("HELLO".isCapitalized, false) | ||
// XCTAssertEqual("".isCapitalized, false) | ||
XCTAssertEqual("👋🏻HELLO".isCapitalized, false) | ||
} | ||
} | ||
|
||
// MARK: count | ||
|
||
extension ExtensionTest { | ||
func testCount() { | ||
XCTAssertEqual("Hello!World!".count(of: "!"), 2) | ||
XCTAssertEqual("Hello!World!".count(of: ","), 0) | ||
XCTAssertEqual("Hello!World!".count(of: "l"), 3) | ||
XCTAssertEqual("".count(of: "!"), 0) | ||
XCTAssertEqual("👋🏻".count(of: "👋🏻"), 1) | ||
} | ||
} | ||
|
||
// MARK: capitalize | ||
|
||
extension ExtensionTest { | ||
func testCapitalize() { | ||
XCTAssertEqual("hello".capitalize(), "Hello") | ||
XCTAssertEqual("HELLO".capitalize(), "Hello") | ||
XCTAssertEqual("hELLO".capitalize(), "Hello") | ||
XCTAssertEqual("".capitalize(), "") | ||
XCTAssertEqual("👋🏻hello".capitalize(), "👋🏻hello") | ||
} | ||
} | ||
|
||
// MARK: isNumeric | ||
|
||
extension ExtensionTest { | ||
func testIsNumberic() { | ||
XCTAssertEqual("123".isNumeric, true) | ||
XCTAssertEqual("0123".isNumeric, true) | ||
XCTAssertEqual("hello".isNumeric, false) | ||
XCTAssertEqual("👋🏻".isNumeric, false) | ||
} | ||
} | ||
|
||
// MARK: trailingSpacesTrimmed | ||
|
||
extension ExtensionTest { | ||
func testTrailingSpacesTrimmed() { | ||
XCTAssertEqual("".trailingSpacesTrimmed, "") | ||
XCTAssertEqual("Hello ".trailingSpacesTrimmed, "Hello") | ||
XCTAssertEqual("Hello".trailingSpacesTrimmed, "Hello") | ||
} | ||
} | ||
|
||
// MARK: setColorForText | ||
|
||
extension ExtensionTest { | ||
func testSetColorForText() { | ||
let string = "Hello, World!" | ||
let attributedString = NSMutableAttributedString(string: string) | ||
let textForAttribute = "World" | ||
let color = UIColor.scribeBlue | ||
|
||
attributedString.setColorForText(textForAttribute: textForAttribute, withColor: color) | ||
|
||
let range = (attributedString.string as NSString).range(of: textForAttribute, options: .caseInsensitive) | ||
|
||
attributedString.enumerateAttribute(.foregroundColor, in: range, options: []) { value, _, _ in | ||
XCTAssertEqual(value as! UIColor, color) | ||
} | ||
} | ||
|
||
func testSetColor_doNotSetColor_withNonExistingText() { | ||
let string = "Hello, World!" | ||
let attributedString = NSMutableAttributedString(string: string) | ||
let textForAttribute = "Universe" | ||
let color = UIColor.red | ||
|
||
attributedString.setColorForText(textForAttribute: textForAttribute, withColor: color) | ||
|
||
let range = (attributedString.string as NSString).range(of: textForAttribute, options: .caseInsensitive) | ||
XCTAssertEqual(range.location, NSNotFound) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this should be
Hell│
as we're just deleting once, right? (I'm fine with this being the result, btw) 😇There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's deleting it once!