diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-13 13:04:10 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-08-13 13:04:10 +0200 |
| commit | e14a7db4ffe3c4e0f15f6b37a980501a8d74d26b (patch) | |
| tree | 670ef0897839871a64d3a3bb2e17e242e7d6c385 /cmd/prognosis/args_test.go | |
| download | prognosis-e14a7db4ffe3c4e0f15f6b37a980501a8d74d26b.tar.gz prognosis-e14a7db4ffe3c4e0f15f6b37a980501a8d74d26b.zip | |
Initial commit: prognosis, the Go implementation
An hour-by-hour forecast for the terminal, with official IMGW warnings for
Polish locations. Replaces the Python version, whose cache file format it
keeps so the two can coexist until this reaches parity.
Open-Meteo provides the forecast, geocoding and pollen; GUGiK turns
coordinates into a TERYT powiat code; IMGW supplies the warnings, filtered
to that powiat rather than the whole country. Only the two lookups that
never change are cached. Forecasts never are.
Silence is never allowed to read as all-clear: "no warnings in force" and
"the check failed" are reported as distinct states.
Place names are resolved without guessing. A name matching several places
is refused with a numbered list carrying each candidate's region and
coordinates, and -pick N chooses one and remembers it. A stray positional
beside -l is an error, so an unquoted "Wiry, PL" cannot silently resolve to
somewhere else.
The cache is written one entry per line with sorted keys, and treated as
disposable but not worthless: an entry that will not parse is skipped and
the rest kept, and a file that will not parse at all is moved to
cache.json.bad rather than overwritten.
No third-party dependencies. `make ci` is the gate: gofmt clean, vet, tests.
Diffstat (limited to 'cmd/prognosis/args_test.go')
| -rw-r--r-- | cmd/prognosis/args_test.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cmd/prognosis/args_test.go b/cmd/prognosis/args_test.go new file mode 100644 index 0000000..4a85a2d --- /dev/null +++ b/cmd/prognosis/args_test.go @@ -0,0 +1,49 @@ +package main + +import ( + "strings" + "testing" +) + +// `prognosis -l Wiry, PL` is the unquoted form of `-l "Wiry, PL"`. The shell +// splits it, so -l gets "Wiry," and "PL" arrives as a stray positional. Dropping +// it silently is what geocoded "Wiry," to Ukraine without anyone noticing. +func TestStrayPositionalBesideDashLIsAnError(t *testing.T) { + _, err := placeFromArgs("Wiry,", []string{"PL"}) + if err == nil { + t.Fatal("expected an error; silently ignoring the argument hides a quoting mistake") + } + if !strings.Contains(err.Error(), "PL") { + t.Errorf("error %q should name the argument that was ignored", err) + } +} + +func TestDashLIsThePlaceWhenNothingElseIsGiven(t *testing.T) { + got, err := placeFromArgs("Wiry, PL", nil) + if err != nil { + t.Fatal(err) + } + if got != "Wiry, PL" { + t.Errorf("got %q, want %q", got, "Wiry, PL") + } +} + +func TestPositionalsJoinIntoThePlace(t *testing.T) { + got, err := placeFromArgs("", []string{"Wiry,", "PL"}) + if err != nil { + t.Fatal(err) + } + if got != "Wiry, PL" { + t.Errorf("got %q, want %q: bare words are still accepted as the place", got, "Wiry, PL") + } +} + +func TestNoPlaceAnywhereIsNotAnError(t *testing.T) { + got, err := placeFromArgs("", nil) + if err != nil { + t.Fatalf("unexpected error %v: the config and ~/.wegorc are consulted next", err) + } + if got != "" { + t.Errorf("got %q, want empty", got) + } +} |
