vitrine

theme_test.go

package display

import (
	"testing"
)

// TestThemeHuePinned pins hue values for known seeds.
// These pins are load-bearing: a refactor that changes the hash or the modulo
// silently repaints every deployed host, and this test is what catches it.
func TestThemeHuePinned(t *testing.T) {
	cases := map[string]int{
		"langoustine": 180,
		"vitrine":     72,
		"alpha":       107,
		"zebra":       95,
		"":            61,
	}
	for seed, want := range cases {
		if got := themeHue(seed); got != want {
			t.Errorf("themeHue(%q) = %d, want %d", seed, got, want)
		}
	}
}

// TestThemeLightnessBand pins the contrast-driven lightness rule
// at the band edges and representative points; see themeLightness for the derivation.
func TestThemeLightnessBand(t *testing.T) {
	cases := map[int]int{
		0:   35, // reds: fine at 35%
		34:  35, // last hue before the band
		35:  26, // band start
		60:  26, // pure yellow, the worst offender
		180: 26, // cyan, still in the band
		200: 26, // band end
		201: 35, // blues onward: fine at 35%
		240: 35,
	}
	for hue, want := range cases {
		if got := themeLightness(hue); got != want {
			t.Errorf("themeLightness(%d) = %d, want %d", hue, got, want)
		}
	}
}

func TestHostLabel(t *testing.T) {
	cases := map[string]string{
		"langoustine":         "langoustine",
		"langoustine.exe.xyz": "langoustine",
		"a.b":                 "a",
	}
	for hostname, want := range cases {
		if got := HostLabel(hostname); got != want {
			t.Errorf("HostLabel(%q) = %q, want %q", hostname, got, want)
		}
	}
}

display/theme_test.go · 1.5 KiB · c714b15828