package main import ( "strings" "testing" ) func TestIconForForecast(t *testing.T) { icon := iconForForecast("Thunderstorms", true) if icon != "\ue31d" { t.Fatalf("expected thunderstorm icon, got %q", icon) } icon = iconForForecast("Partly Cloudy", false) if icon != "\ue379" { t.Fatalf("expected partly cloudy night icon, got %q", icon) } icon = iconForForecast("Mostly Sunny", true) if icon != "\ue30c" { t.Fatalf("expected mostly sunny icon, got %q", icon) } icon = iconForForecast("Overcast", true) if icon != "\ue312" { t.Fatalf("expected cloudy icon, got %q", icon) } icon = iconForForecast("Rain", true) if icon != "\ue318" { t.Fatalf("expected rain icon, got %q", icon) } icon = iconForForecast("Snow", true) if icon != "\ue31a" { t.Fatalf("expected snow icon, got %q", icon) } } func TestFormatOutputPopAlways(t *testing.T) { pop := 20 loc := Location{City: "Testville", State: "TS"} period := ForecastPeriod{ Temp: 70, Unit: "F", Summary: "Clear", Pop: &pop, } out := FormatOutput(loc, period, false, false) if !strings.Contains(out, "20%") { t.Fatalf("expected pop to be shown above threshold, got %q", out) } if strings.Contains(out, "\ue371") || strings.Contains(out, "\uf2dc") { t.Fatalf("expected no pop icon in plain mode, got %q", out) } } func TestFormatOutputPopIcon(t *testing.T) { pop := 60 loc := Location{City: "Testville", State: "TS"} period := ForecastPeriod{ Temp: 30, Unit: "F", Summary: "Snow", Pop: &pop, IsDaytime: true, } out := FormatOutput(loc, period, false, true) if !strings.Contains(out, "\uf2dc 60%") { t.Fatalf("expected snow pop icon before pop, got %q", out) } if !strings.Contains(out, "\ue31a 30°F") { t.Fatalf("expected precip icon before temperature, got %q", out) } if !strings.Contains(out, "\uf2dc 60% in") { t.Fatalf("expected pop to precede location, got %q", out) } }