Assisted-by: GLM 5.3 Flash
This commit is contained in:
+14
-4
@@ -725,8 +725,8 @@ func TestDecodeErrorCarriesPath(t *testing.T) {
|
||||
if de.Err == nil || !strings.Contains(de.Err.Error(), "overflows uint8") {
|
||||
t.Fatalf("Err = %v", de.Err)
|
||||
}
|
||||
// The rendered message keeps its shape: segments joined with ": ".
|
||||
wantMsg := "items: [0]: weight: interpres: integer 300 overflows uint8"
|
||||
// The rendered message uses the Path notation.
|
||||
wantMsg := "interpres: items[0].weight: integer 300 overflows uint8"
|
||||
if err.Error() != wantMsg {
|
||||
t.Fatalf("message = %q, want %q", err.Error(), wantMsg)
|
||||
}
|
||||
@@ -1310,7 +1310,7 @@ func TestDecodeFixedArray(t *testing.T) {
|
||||
Ports [3]int `toml:"ports"`
|
||||
}
|
||||
err := Unmarshal([]byte("ports = [8080, 9090]\n"), &cfg)
|
||||
want := "ports: interpres: cannot assign 2 elements to [3]int"
|
||||
want := "interpres: ports: cannot assign 2 elements to [3]int"
|
||||
if err == nil || err.Error() != want {
|
||||
t.Errorf("err = %v, want %q", err, want)
|
||||
}
|
||||
@@ -1344,7 +1344,7 @@ func TestRequiredTag(t *testing.T) {
|
||||
Server Config `toml:"server"`
|
||||
}
|
||||
err := Unmarshal([]byte("[server]\nradius = 1\n"), &outer)
|
||||
want := `server: interpres: missing required key "host"`
|
||||
want := `interpres: server: missing required key "host"`
|
||||
if err == nil || err.Error() != want {
|
||||
t.Errorf("err = %v, want %q", err, want)
|
||||
}
|
||||
@@ -1477,3 +1477,13 @@ func TestDecodeMergesIntoNonEmptyMap(t *testing.T) {
|
||||
t.Errorf("lang = %v, want the key added", dst["lang"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathString(t *testing.T) {
|
||||
p := Path{"server", "ports", "[2]", "host"}
|
||||
if got, want := p.String(), "server.ports[2].host"; got != want {
|
||||
t.Errorf("String() = %q, want %q", got, want)
|
||||
}
|
||||
if got := (Path{}).String(); got != "" {
|
||||
t.Errorf("String() of an empty path = %q, want the empty string", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user