package render import ( "strings" "testing" ) func TestASCIIIsPureASCII(t *testing.T) { in := " ! Upał stopień 1\n 14 29° (28) zachmurzenie ↗\n 30°│███▄▄▁" got := ASCII(in, "metric") for _, r := range got { if r > 127 { t.Fatalf("non-ASCII %q survived in %q", r, got) } } } // Substitution runs after layout, so it must not change the character count -- // otherwise every column to the right of a degree sign shears. func TestASCIIPreservesLength(t *testing.T) { for _, in := range []string{ " 14 29° (28) zachmurzenie", " 30°│███▄▄▁▂", " godz temp odczuw warunki", " słońce 12h03m z 14h45m dnia", } { if got := ASCII(in, "metric"); len([]rune(got)) != len([]rune(in)) { t.Errorf("length changed: %q (%d) -> %q (%d)", in, len([]rune(in)), got, len([]rune(got))) } } } // IMGW prose already writes "30°C"; the unit letter must not be doubled. func TestASCIIDoesNotDoubleTheUnitInProse(t *testing.T) { got := ASCII("temperatura od 30°C do 33°C", "metric") if strings.Contains(got, "CC") { t.Fatalf("doubled unit: %q", got) } if got != "temperatura od 30C do 33C" { t.Fatalf("got %q", got) } } func TestASCIIUsesFahrenheitLetterInImperial(t *testing.T) { if got := ASCII("85°", "imperial"); got != "85F" { t.Fatalf("got %q, want 85F", got) } } func TestASCIIMarksUnmappedRunesRatherThanDroppingThem(t *testing.T) { if got := ASCII("東京", "metric"); got != "??" { t.Fatalf("got %q, want ??", got) } }