Skip to content

Commit 2af68b0

Browse files
committed
Add unit tests for String Additions
1 parent e3cafb3 commit 2af68b0

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Example/FazeKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
1515
607FACEC1AFB9204008FA782 /* UIViewAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* UIViewAdditionsTests.swift */; };
1616
78B6DD4BAF21BA4B263F3EF4 /* Pods_FazeKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DB0AD919FBE4556CA363D8B /* Pods_FazeKit_Tests.framework */; };
17+
7CDA2BCA1FE872FE00CBA532 /* StringAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CDA2BC91FE872FE00CBA532 /* StringAdditionsTests.swift */; };
1718
C20FAFE21DD42EAA009E5C3F /* MulticastTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C20FAFE01DD42E7D009E5C3F /* MulticastTests.swift */; };
1819
C2B9A0321DD29F9100AF4E04 /* DateAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B9A0301DD2941C00AF4E04 /* DateAdditionsTests.swift */; };
1920
C2B9A0381DD2DAE500AF4E04 /* CollectionAdditionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B9A0361DD2DAB500AF4E04 /* CollectionAdditionsTests.swift */; };
@@ -45,6 +46,7 @@
4546
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4647
607FACEB1AFB9204008FA782 /* UIViewAdditionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewAdditionsTests.swift; sourceTree = "<group>"; };
4748
739B56FA57C1D0E13427B629 /* Pods-FazeKit_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FazeKit_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-FazeKit_Tests/Pods-FazeKit_Tests.release.xcconfig"; sourceTree = "<group>"; };
49+
7CDA2BC91FE872FE00CBA532 /* StringAdditionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringAdditionsTests.swift; sourceTree = "<group>"; };
4850
AE54F13DF076B827802B2E27 /* Pods-FazeKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FazeKit_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FazeKit_Example/Pods-FazeKit_Example.debug.xcconfig"; sourceTree = "<group>"; };
4951
C20FAFE01DD42E7D009E5C3F /* MulticastTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MulticastTests.swift; sourceTree = "<group>"; };
5052
C2B9A0301DD2941C00AF4E04 /* DateAdditionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateAdditionsTests.swift; sourceTree = "<group>"; };
@@ -133,6 +135,7 @@
133135
C2B9A0301DD2941C00AF4E04 /* DateAdditionsTests.swift */,
134136
C20FAFE01DD42E7D009E5C3F /* MulticastTests.swift */,
135137
C2E94BAD1D62CDD5007A7A4C /* ProcessInfoAdditionsTests.swift */,
138+
7CDA2BC91FE872FE00CBA532 /* StringAdditionsTests.swift */,
136139
607FACEB1AFB9204008FA782 /* UIViewAdditionsTests.swift */,
137140
607FACE91AFB9204008FA782 /* Supporting Files */,
138141
);
@@ -384,6 +387,7 @@
384387
607FACEC1AFB9204008FA782 /* UIViewAdditionsTests.swift in Sources */,
385388
C2B9A0321DD29F9100AF4E04 /* DateAdditionsTests.swift in Sources */,
386389
C20FAFE21DD42EAA009E5C3F /* MulticastTests.swift in Sources */,
390+
7CDA2BCA1FE872FE00CBA532 /* StringAdditionsTests.swift in Sources */,
387391
C2B9A0381DD2DAE500AF4E04 /* CollectionAdditionsTests.swift in Sources */,
388392
);
389393
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// Copyright 2017 NextFaze
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
// use this file except in compliance with the License. You may obtain a copy
6+
// of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
// License for the specific language governing permissions and limitations
14+
// under the License.
15+
//
16+
// StringAdditionsTests.swift
17+
// FazeKit_Tests
18+
//
19+
// Created by Ricardo Santos on 19/12/17.
20+
//
21+
22+
import Foundation
23+
import XCTest
24+
import FazeKit
25+
26+
class StringAdditionsTests: XCTestCase {
27+
28+
override func setUp() {
29+
super.setUp()
30+
}
31+
32+
override func tearDown() {
33+
super.tearDown()
34+
}
35+
36+
func testContains() {
37+
let string = "Abcdefgh"
38+
XCTAssertTrue(string.contains("A"), "String.contains: should have found a match")
39+
XCTAssertFalse(string.contains("a"), "String.contains: should not have found a match")
40+
XCTAssertFalse(string.contains("z"), "String.contains: should not have found a match")
41+
}
42+
43+
func testReplace() {
44+
var string = "The cat jumped over the hat"
45+
string = string.replace("cat", withString: "dog")
46+
XCTAssertTrue(string.contains("dog"), "String.replace: should contain the replacement substring")
47+
XCTAssertFalse(string.contains("cat"), "String.replace: should not still contain the original substring")
48+
}
49+
50+
func testSubscript() {
51+
let string = "OMG. I can't believe it's a thing!"
52+
XCTAssertTrue(string[0] == "O", "String.subscript: should return the Character O")
53+
XCTAssertTrue(string[1] == "M", "String.subscript: should return the Character O")
54+
XCTAssertTrue(string[2] == "G", "String.subscript: should return the Character O")
55+
}
56+
57+
func testSubstring() {
58+
let string = "OMG. Is this even a thing?"
59+
XCTAssertTrue(string.substring(0, length: 3) == "OMG", "String.substring: should create a new substring")
60+
}
61+
62+
func testTrim() {
63+
let string = " Hello World \n\n\n "
64+
XCTAssertTrue(string.trim() == "Hello World", "String.trim(): should remove all whitespace and newlines")
65+
}
66+
67+
}

0 commit comments

Comments
 (0)