Weighted person names, valid personal ids and date() in both locales #21
+5
-1
@@ -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-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,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)}"`: "'",
|
||||||
|
`"{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,'x')}"`: "text",
|
||||||
`"{date(1990-01-01,1990-12-31,'')}"`: "text",
|
`"{date(1990-01-01,1990-12-31,'')}"`: "text",
|
||||||
`"{date(1990-01-01,1990-12-31)}"`: "3 arguments",
|
`"{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
|
// TestBuiltinLayoutErrorsNameARunnableSpelling pins the two layout errors a user
|
||||||
// can follow: a double-quoted layout is named single-quoted, without its own
|
// 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) {
|
func TestBuiltinLayoutErrorsNameARunnableSpelling(t *testing.T) {
|
||||||
_, err := compile(parse(t, `"{date(1990-01-01,1990-12-31,\"2006-01-02\")}"`))
|
_, 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'") {
|
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(), `'"`) {
|
if strings.Contains(err.Error(), `'"`) {
|
||||||
t.Errorf("%v names a layout that renders its own quotes", err)
|
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)}"`))
|
_, err = compile(parse(t, `"{time(15:04)}"`))
|
||||||
if err == nil || !strings.Contains(err.Error(), "write '15:04'") {
|
if err == nil || !strings.Contains(err.Error(), "write '15:04'") {
|
||||||
t.Fatalf("a bare layout = %v, want it named quoted", err)
|
t.Fatalf("a bare layout = %v, want it named quoted", err)
|
||||||
|
|||||||
+2
-1
@@ -188,7 +188,8 @@ func TestSwedishPersonnummer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for i := 0; i < 200; i++ {
|
for i := 0; i < 200; i++ {
|
||||||
got := fakeTemplate(t, sv, `{/sv_SE.person.sex} {/sv_SE.personnummer}`)
|
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)
|
t.Fatalf("%q: a person and a personnummer in one render disagree on sex", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user