forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringExtensionsTests.swift
55 lines (46 loc) · 1.93 KB
/
StringExtensionsTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* 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 Foundation
import XCTest
class StringExtensionsTests: XCTestCase {
func testContains() {
XCTAssertTrue("abcde".contains("abcde"))
XCTAssertTrue("abcde".contains(""))
XCTAssertTrue("abcde".contains("a"))
XCTAssertTrue("abcde".contains("e"))
XCTAssertFalse("abcde".contains("f"))
XCTAssertFalse("abcde".contains("fa"))
XCTAssertFalse("abcde".contains("ef"))
}
func testStartsWith() {
XCTAssertTrue("abcde".startsWith("abcde"))
XCTAssertTrue("abcde".startsWith(""))
XCTAssertTrue("abcde".startsWith("a"))
XCTAssertTrue("abcdea".startsWith("a"))
XCTAssertFalse("abcde".startsWith("fa"))
XCTAssertFalse("abcde".startsWith("af"))
XCTAssertFalse("abcde".startsWith("b"))
}
func testEndsWith() {
XCTAssertTrue("abcde".endsWith("abcde"))
XCTAssertTrue("abcde".endsWith(""))
XCTAssertTrue("abcde".endsWith("e"))
XCTAssertTrue("abcdea".endsWith("a"))
XCTAssertFalse("abcde".endsWith("fe"))
XCTAssertFalse("abcde".endsWith("ef"))
XCTAssertFalse("abcde".endsWith("d"))
}
func testEllipsize() {
// Odd maxLength. Note that we ellipsize with a Unicode join character to avoid wrapping.
XCTAssertEqual("abcd…\u{2060}fgh", "abcdefgh".ellipsize(maxLength: 7))
// Even maxLength.
XCTAssertEqual("abcd…\u{2060}ijkl", "abcdefghijkl".ellipsize(maxLength: 8))
// String shorter than maxLength.
XCTAssertEqual("abcd", "abcd".ellipsize(maxLength: 7))
// Empty String.
XCTAssertEqual("", "".ellipsize(maxLength: 8))
// maxLength < 2.
XCTAssertEqual("abcdefgh", "abcdefgh".ellipsize(maxLength: 0))
}
}