@testable import Forji
import SwiftUI
import Testing

struct LabelColorHexTests {
    // MARK: - Six-digit colors

    @Test("six digit hex parses") func sixDigitHexParses() {
        #expect(Color(hex: "#ff0000") != nil)
        #expect(Color(hex: "00ff00") != nil)
    }

    @Test("six digit value matches") func sixDigitValueMatches() throws {
        let rgb = try #require(Color.rgbValue(hex: "#3366cc"))
        #expect(rgb == 0x3366CC)
    }

    // MARK: - Three-digit shorthand

    @Test("three digit shorthand parses") func threeDigitShorthandParses() {
        #expect(Color(hex: "#f00") != nil)
        #expect(Color(hex: "abc") != nil)
    }

    @Test("three digit shorthand expands like six digit") func threeDigitShorthandExpandsLikeSixDigit() throws {
        #expect(Color(hex: "#f00") == Color(hex: "#ff0000"))
        #expect(Color(hex: "abc") == Color(hex: "aabbcc"))
        let rgb = try #require(Color.rgbValue(hex: "#f00"))
        #expect(rgb == 0xFF0000)
    }

    // MARK: - Invalid input

    @Test("invalid hex returns nil") func invalidHexReturnsNil() {
        #expect(Color(hex: "") == nil)
        #expect(Color(hex: "#ff00") == nil)
        #expect(Color(hex: "12345") == nil)
        #expect(Color(hex: "xyzxyz") == nil)
        #expect(Color(hex: "#xyz") == nil)
    }
}
