aboutsummaryrefslogtreecommitdiff
path: root/internal/render/ascii_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/render/ascii_test.go')
-rw-r--r--internal/render/ascii_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/render/ascii_test.go b/internal/render/ascii_test.go
new file mode 100644
index 0000000..7e6a805
--- /dev/null
+++ b/internal/render/ascii_test.go
@@ -0,0 +1,55 @@
+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)
+ }
+}