-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
Tests/MessagingInApp/Gist/Utilities/StringPercentEncodeTests.swift
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,69 @@ | ||
@testable import CioMessagingInApp | ||
import XCTest | ||
|
||
class StringPercentEncodeTests: XCTestCase { | ||
func test_givenValidCharacter_expectEncodedURL() { | ||
let input = "https://example.com/path#fragment" | ||
|
||
let encoded = input.percentEncode(character: "#") | ||
|
||
XCTAssertEqual(encoded, "https://example.com/path%23fragment") | ||
} | ||
|
||
func test_givenMultipleOccurrences_expectAllEncoded() { | ||
let input = "https://example.com/path#fragment#another" | ||
|
||
let encoded = input.percentEncode(character: "#") | ||
|
||
XCTAssertEqual(encoded, "https://example.com/path%23fragment%23another") | ||
} | ||
|
||
func test_givenMultipleCharacter_expectEncodedGivenOnly() { | ||
let input = "https://example.com/path#source=link&medium=email" | ||
|
||
let encoded = input.percentEncode(character: "#") | ||
|
||
XCTAssertEqual(encoded, "https://example.com/path%23source=link&medium=email") | ||
} | ||
|
||
func test_givenCharacterInAllowedSet_expectUnchangedString() { | ||
let input = "https://example.com/path/fragment" | ||
|
||
// '/' is allowed in `.urlPathAllowed` | ||
let encoded = input.percentEncode(character: "/") | ||
|
||
XCTAssertEqual(encoded, input, "The '/' character should not be encoded as it is allowed in the path") | ||
} | ||
|
||
func test_givenCustomAllowedCharacterSet_expectEncodedSpaces() { | ||
let input = "https://example.com/path with spaces" | ||
|
||
let encoded = input.percentEncode(character: " ", withAllowedCharacters: .alphanumerics) | ||
|
||
XCTAssertEqual(encoded, "https://example.com/path%20with%20spaces") | ||
} | ||
|
||
func test_givenNoTargetCharacter_expectUnchangedString() { | ||
let input = "https://example.com/path/fragment" | ||
|
||
let encoded = input.percentEncode(character: "#") | ||
|
||
XCTAssertEqual(encoded, input) | ||
} | ||
|
||
func test_givenEmptyTargetCharacter_expectUnchangedString() { | ||
let input = "https://example.com/path/fragment" | ||
|
||
let encoded = input.percentEncode(character: "") | ||
|
||
XCTAssertEqual(encoded, input) | ||
} | ||
|
||
func test_givenEmptyInput_expectEmptyString() { | ||
let input = "" | ||
|
||
let encoded = input.percentEncode(character: "#") | ||
|
||
XCTAssertEqual(encoded, "") | ||
} | ||
} |