Revision control
Copy as Markdown
// 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
import XCTest
@testable import WebEngine
final class StringExtensionTests: XCTestCase {
// MARK: Tests for HtmlEntityEncoding string
func testHtmlEntityEncodingGivenNoSpecialCharacters() {
let input = "John Doe"
XCTAssertEqual(input.htmlEntityEncodedString, "John Doe")
}
func testHtmlEntityEncodingGivenSpecialCharacters() {
let input = "<John Doe>"
XCTAssertEqual(input.htmlEntityEncodedString, "<John Doe>")
}
func testHtmlEntityEncodingGivenXssPayload() {
let input = "<script>alert('XSS')</script>"
XCTAssertEqual(input.htmlEntityEncodedString, "<script>alert('XSS')</script>")
}
func testHtmlEntityEncodingGivenHtmlEntities() {
let input = ""John Doe""
XCTAssertEqual(input.htmlEntityEncodedString, "&quot;John Doe&quot;")
}
func testHtmlEntityEncodingGivenMultipleSpecialCharacters() {
let input = "<John & 'Doe'>"
XCTAssertEqual(input.htmlEntityEncodedString, "<John & 'Doe'>")
}
func testHtmlEntityEncodingGivenwithUnicodeCharacters() {
let input = "Mëtàl Hëàd"
XCTAssertEqual(input.htmlEntityEncodedString, "Mëtàl Hëàd")
}
func testHtmlEntityEncodingGivenwithNumbers() {
let input = "12345"
XCTAssertEqual(input.htmlEntityEncodedString, "12345")
}
func testHtmlEntityEncodingGivenwithEmptyString() {
let input = ""
XCTAssertEqual(input.htmlEntityEncodedString, "")
}
}