From c232e650013fe3e1b79779b82dfaf40a93fea22c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 18 Sep 2026 20:17:46 +0200 Subject: [PATCH] Test the double-quoted comma hint and the branch that names it, and match a personnummer's birth number by text --- builtins_test.go | 6 +++++- data_test.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/builtins_test.go b/builtins_test.go index 4a18ca0..92c585f 100644 --- a/builtins_test.go +++ b/builtins_test.go @@ -302,6 +302,7 @@ func TestBuiltinDateArgs(t *testing.T) { `"{date(1990-01-01,1990-01-01,'2006-01-02')}"`: "write it as text", `"{date(1990-01-01,1990-12-31,2006-01-02)}"`: "'2006-01-02'", `"{date(1990-01-01,1990-12-31,'January 2, 2006)}"`: "'", + `"{date(1990-01-01,1990-12-31,\"January 2, 2006\")}"`: "quoted: 'January 2, 2006'", `"{date(1990-01-01,1990-12-31,'x')}"`: "text", `"{date(1990-01-01,1990-12-31,'')}"`: "text", `"{date(1990-01-01,1990-12-31)}"`: "3 arguments", @@ -321,7 +322,7 @@ func TestBuiltinDateArgs(t *testing.T) { // TestBuiltinLayoutErrorsNameARunnableSpelling pins the two layout errors a user // can follow: a double-quoted layout is named single-quoted, without its own -// quotes carried into the suggestion, and a bare one says a shell ate them. +// quotes carried into the suggestion, whether it split on a comma or not. func TestBuiltinLayoutErrorsNameARunnableSpelling(t *testing.T) { _, err := compile(parse(t, `"{date(1990-01-01,1990-12-31,\"2006-01-02\")}"`)) if err == nil || !strings.Contains(err.Error(), "write '2006-01-02'") { @@ -330,6 +331,9 @@ func TestBuiltinLayoutErrorsNameARunnableSpelling(t *testing.T) { if strings.Contains(err.Error(), `'"`) { t.Errorf("%v names a layout that renders its own quotes", err) } + if !strings.Contains(err.Error(), "is double-quoted") { + t.Errorf("%v does not say which quotes were wrong", err) + } _, err = compile(parse(t, `"{time(15:04)}"`)) if err == nil || !strings.Contains(err.Error(), "write '15:04'") { t.Fatalf("a bare layout = %v, want it named quoted", err) diff --git a/data_test.go b/data_test.go index 3e9de3e..33af38e 100644 --- a/data_test.go +++ b/data_test.go @@ -188,7 +188,8 @@ func TestSwedishPersonnummer(t *testing.T) { } for i := 0; i < 200; i++ { got := fakeTemplate(t, sv, `{/sv_SE.person.sex} {/sv_SE.personnummer}`) - if f, m := strings.HasPrefix(got, "kvinna ") && got[14:17] == "238", strings.HasPrefix(got, "man ") && got[11:14] == "239"; !f && !m { + sex, id, _ := strings.Cut(got, " ") + if want := map[string]string{"kvinna": "238", "man": "239"}[sex]; want == "" || !strings.Contains(id, "-"+want) { t.Fatalf("%q: a person and a personnummer in one render disagree on sex", got) } }