Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] add color name test #33

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

// ref: https://www.w3.org/wiki/CSS/Properties/color/keywords
public enum MarkupStyleColorName: String {
public enum MarkupStyleColorName: String, CaseIterable {
case aliceblue
case antiquewhite
case aqua
Expand Down
46 changes: 46 additions & 0 deletions Tests/ZMarkupParserTests/Core/HTMLStringTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// HTMLStringTests.swift
//
//
// Created by zhgchgli on 2023/8/15.
//

import Foundation
@testable import ZMarkupParser
import XCTest

final class HTMLStringTests: XCTestCase {
func testAddingUnicodeEntities() {
let string = "Fish & Chips"
let result = string.addingUnicodeEntities()
XCTAssertEqual(result, "Fish & Chips")
}

func testAddingASCIIEntities() {
let string = "Fish & Chips"
let result = string.addingASCIIEntities()
XCTAssertEqual(result, "Fish & Chips")

let stringWithUnicode = "Σ"
let resultWithUnicode = stringWithUnicode.addingASCIIEntities()
XCTAssertEqual(resultWithUnicode, "Σ")

let stringWithEmoji = "🇺🇸"
let resultWithEmoji = stringWithEmoji.addingASCIIEntities()
XCTAssertEqual(resultWithEmoji, "🇺🇸")
}

func testRemovingHTMLEntities() {
let string = "Fish & Chips"
let result = string.removingHTMLEntities()
XCTAssertEqual(result, "Fish & Chips")

let stringWithUnicode = "Σ"
let resultWithUnicode = stringWithUnicode.removingHTMLEntities()
XCTAssertEqual(resultWithUnicode, "Σ")

let stringWithEmoji = "🇺🇸"
let resultWithEmoji = stringWithEmoji.removingHTMLEntities()
XCTAssertEqual(resultWithEmoji, "🇺🇸")
}
}
19 changes: 11 additions & 8 deletions Tests/ZMarkupParserTests/Core/MarkupStyleColorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import AppKit

// helper: https://www.uicolor.io
final class MarkupStyleColorTests: XCTestCase {

func testInitStyleFromColorName() throws {
let allCases = MarkupStyleColorName.allCases
for colorName in allCases {
let markupStyleColor = MarkupStyleColor(name: colorName)
XCTAssertEqual(markupStyleColor?.red, colorName.rgb.0)
XCTAssertEqual(markupStyleColor?.green, colorName.rgb.1)
XCTAssertEqual(markupStyleColor?.blue, colorName.rgb.2)
XCTAssertEqual(markupStyleColor?.alpha, 1)
}
}

func testInitStyleFromColorHEXString() throws {
#if canImport(UIKit)
Expand Down Expand Up @@ -59,14 +70,6 @@ final class MarkupStyleColorTests: XCTestCase {
XCTAssertNil(MarkupStyleColor(string: "rgb(15,30,60,2)")?.getColor())
}

func testInitStyleFromColorName() throws {
let markupStyleColor = MarkupStyleColor(name: .antiquewhite)
XCTAssertEqual(markupStyleColor?.red, MarkupStyleColorName.antiquewhite.rgb.0)
XCTAssertEqual(markupStyleColor?.green, MarkupStyleColorName.antiquewhite.rgb.1)
XCTAssertEqual(markupStyleColor?.blue, MarkupStyleColorName.antiquewhite.rgb.2)
XCTAssertEqual(markupStyleColor?.alpha, 1)
}

func testInitStyleFromUINSColor() throws {
#if canImport(UIKit)
XCTAssertEqual(MarkupStyleColor(color: .green).getColor(), UIColor.green)
Expand Down