package idn
import (
"strconv"
"strings"
"testing"
)
func TestChromaIsABandAndDeterministic(t *testing.T) {
seen := map[int]bool{}
for _, n := range []string{"drh", "dan", "stephan", "mistachkin", "andygoth", "wyoung", "jan", "larry"} {
c := Chroma(n)
if c != 0 && c != 1 {
t.Fatalf("Chroma(%q) = %d, want 0 or 1", n, c)
}
if Chroma(n) != c {
t.Fatalf("Chroma(%q) not deterministic", n)
}
seen[c] = true
}
if len(seen) != 2 {
t.Fatalf("only band %v used across the sample; want both", seen)
}
}
func TestFillCarriesHueAndChromaHook(t *testing.T) {
f := Fill("drh", "var(--idn-l)")
for _, want := range []string{"oklch(", "var(--idn-l)", "var(--idn-c" + strconv.Itoa(Chroma("drh")) + ")", " " + strconv.Itoa(Hue("drh")) + ")"} {
if !strings.Contains(f, want) {
t.Fatalf("Fill = %q, missing %q", f, want)
}
}
if tone := Tone("drh"); !strings.Contains(tone, "--uh: "+strconv.Itoa(Hue("drh"))) || !strings.Contains(tone, "--uc: var(--idn-c") {
t.Fatalf("Tone = %q", tone)
}
}
func TestMarkUsesThemeLightnessAndIsMemoised(t *testing.T) {
m := Mark("drh")
for _, want := range []string{`class="idn"`, "var(--idn-l)", "calc(var(--idn-l) - 12%)", "oklch("} {
if !strings.Contains(m, want) {
t.Fatalf("Mark missing %q", want)
}
}
if strings.Contains(m, `fill="hsl`) || strings.Contains(m, `fill="oklch`) {
t.Fatal("var() fills must live in style=, not a presentation attribute")
}
if Mark("drh") != m {
t.Fatal("Mark not stable across calls")
}
if _, ok := memo.Load("drh"); !ok {
t.Fatal("Mark not memoised")
}
}