package main import "testing" // A colour the Flex refuses is a spot that never appears, and the command error // goes to a log nobody is reading. Anything that is not #AARRGGBB must be // dropped here rather than sent. func TestHexARGB(t *testing.T) { for _, ok := range []string{"#FFFF3B30", "#00000000", "#ffabcdef", "#40FF6B22"} { if !hexARGB(ok) { t.Errorf("%q should be accepted", ok) } } for _, bad := range []string{ "", "#FFF", "#FF3B30", "FFFF3B30", "#FFFF3B3", "#FFFF3B300", "#GGFF3B30", "#FFFF3B3G", "red", "rgb(255,0,0)", } { if hexARGB(bad) { t.Errorf("%q should be refused", bad) } } } // The stored palette must survive a round trip, and must not carry a status the // resolver does not know — an unknown key would be a colour nothing can ever use // and a field nobody can remove from the panel. func TestNormSpotColors(t *testing.T) { in := SpotColors{Enabled: true, Colors: map[string]SpotColor{ "new": {Text: "#FFFF3B30", Bg: "#40FF3B30"}, "new-band": {Text: "not a colour", Bg: "#40FFCC00"}, // half valid "worked": {Text: "", Bg: ""}, // nothing at all "invented": {Text: "#FF000000"}, // not a status }} out := normSpotColors(in) if got := out.Colors["new"].Text; got != "#FFFF3B30" { t.Errorf("valid pair lost: %q", got) } if c := out.Colors["new-band"]; c.Text != "" || c.Bg != "#40FFCC00" { t.Errorf("half-valid pair = %+v, want the background kept and the text dropped", c) } if _, ok := out.Colors["worked"]; ok { t.Errorf("an entry with no colour at all must not be stored") } if _, ok := out.Colors["invented"]; ok { t.Errorf("an unknown status must not be stored") } } func TestSpotComment(t *testing.T) { // The cluster's own text is kept: it carries the signal report and the // operator's note, which is why the spot is readable in the first place. if got := spotComment("CQ up 2", "new"); got != "CQ up 2 [NEW DXCC]" { t.Fatalf("got %q", got) } // An empty comment must not produce a leading space on the panadapter. if got := spotComment("", "new-band"); got != "[NEW BAND]" { t.Fatalf("got %q", got) } // Nothing to say about a station already in the log. if got := spotComment("loud", "worked"); got != "loud" { t.Fatalf("got %q", got) } if got := spotComment("loud", "none"); got != "loud" { t.Fatalf("got %q", got) } // Every colourable status except the two quiet ones is labelled, or the // palette would say something the text does not. for _, s := range spotColorOrder { if s == "worked" || s == "none" { continue } if spotStatusTag(s) == "" { t.Fatalf("status %q has a colour but no tag", s) } } }