1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)
}
}
|