Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -773,3 +774,25 @@ func TestValid(t *testing.T) {
|
||||
t.Errorf("Valid(invalid) = %v, want a SyntaxError", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAsAndNewSchema(t *testing.T) {
|
||||
type Config struct {
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
}
|
||||
cfg, err := ParseAs[Config]([]byte("host = \"db\"\nport = 5432\n"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.Host != "db" || cfg.Port != 5432 {
|
||||
t.Errorf("decoded %+v", cfg)
|
||||
}
|
||||
if _, err := ParseAs[Config]([]byte("port =\n")); err == nil {
|
||||
t.Error("ParseAs(invalid) succeeded, want an error and the zero value")
|
||||
}
|
||||
NewSchema[Config]()
|
||||
if _, ok := structSchemaCache.Load(reflect.TypeFor[Config]()); !ok {
|
||||
t.Error("NewSchema left no schema in the cache")
|
||||
}
|
||||
NewSchema[map[string]any]() // must not panic
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user