Skip to content

Commit

Permalink
[Test] add color name test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgchgli0718 committed Aug 15, 2023
1 parent 010e055 commit 83c8ad1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
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

0 comments on commit 83c8ad1

Please sign in to comment.