This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
The string extensions method _truncated_ did not truncate the string to the specified limit including the leader. For example, with a limit of 15 and the deafult leader the truncated string length was 18 for .head and 16 for .tail and .middle
- Loading branch information
Showing
3 changed files
with
62 additions
and
7 deletions.
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
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,51 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import XCTest | ||
@testable import Firefox_Focus | ||
|
||
class StringExtensionTest: XCTestCase { | ||
|
||
|
||
func testStringShouldBeTruncated() { | ||
let originalString = "This is a long title string" | ||
|
||
let headTruncatedString = originalString.truncated(limit: 15, position: .head, leader: "..") | ||
XCTAssertEqual(headTruncatedString.count, 15) | ||
XCTAssertEqual(headTruncatedString, ".. title string") | ||
|
||
let middleTruncatedString = originalString.truncated(limit: 15, position: .middle, leader: "..") | ||
XCTAssertEqual(middleTruncatedString.count, 15) | ||
XCTAssertEqual(middleTruncatedString, "This i.. string") | ||
|
||
let tailTruncatedString = originalString.truncated(limit: 15, position: .tail, leader: "..") | ||
XCTAssertEqual(tailTruncatedString.count, 15) | ||
XCTAssertEqual(tailTruncatedString, "This is a lon..") | ||
} | ||
|
||
func testStringShouldStartWithString() { | ||
let originalString = "This is a long title string" | ||
let startString = "This is" | ||
|
||
let isStarting = originalString.startsWith(other: startString) | ||
XCTAssertEqual(isStarting, true) | ||
} | ||
|
||
func testStringShouldStartWithEmptyString() { | ||
let originalString = "This is a long title string" | ||
let startString = "" | ||
|
||
let isStarting = originalString.startsWith(other: startString) | ||
XCTAssertEqual(isStarting, true) | ||
} | ||
|
||
func testStringShouldNotStartWithString() { | ||
let originalString = "This is a long title string" | ||
let startString = "TX" | ||
|
||
let isStarting = originalString.startsWith(other: startString) | ||
XCTAssertEqual(isStarting, false) | ||
} | ||
|
||
} |