[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find ONE feature... #44
3 changed files with 34 additions and 1 deletions
|
|
@ -338,4 +338,4 @@ All grammar functions are available as Go template functions via `TemplateFuncs(
|
|||
template.New("").Funcs(i18n.TemplateFuncs())
|
||||
```
|
||||
|
||||
Available functions: `title`, `lower`, `upper`, `past`, `gerund`, `plural`, `pluralForm`, `article`, `quote`.
|
||||
Available functions: `title`, `lower`, `upper`, `past`, `gerund`, `plural`, `pluralForm`, `article`, `quote`, `label`, `progress`, `progressSubject`, `actionResult`, `actionFailed`, `timeAgo`, `formatAgo`.
|
||||
|
|
|
|||
|
|
@ -690,6 +690,8 @@ func TemplateFuncs() template.FuncMap {
|
|||
"progressSubject": ProgressSubject,
|
||||
"actionResult": ActionResult,
|
||||
"actionFailed": ActionFailed,
|
||||
"timeAgo": TimeAgo,
|
||||
"formatAgo": FormatAgo,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPastTense(t *testing.T) {
|
||||
|
|
@ -878,6 +879,8 @@ func TestTemplateFuncs(t *testing.T) {
|
|||
"progressSubject",
|
||||
"actionResult",
|
||||
"actionFailed",
|
||||
"timeAgo",
|
||||
"formatAgo",
|
||||
}
|
||||
for _, name := range expected {
|
||||
if _, ok := funcs[name]; !ok {
|
||||
|
|
@ -927,6 +930,34 @@ func TestTemplateFuncs_CompositeHelpers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTemplateFuncs_TimeHelpers(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() failed: %v", err)
|
||||
}
|
||||
SetDefault(svc)
|
||||
|
||||
tmpl, err := template.New("").Funcs(TemplateFuncs()).Parse(
|
||||
`{{formatAgo 3 "hour"}}|{{timeAgo .}}`,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Parse() failed: %v", err)
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
if err := tmpl.Execute(&buf, time.Now().Add(-5*time.Minute)); err != nil {
|
||||
t.Fatalf("Execute() failed: %v", err)
|
||||
}
|
||||
|
||||
got := buf.String()
|
||||
if !strings.HasPrefix(got, "3 hours ago|") {
|
||||
t.Fatalf("template time helpers prefix = %q, want %q", got, "3 hours ago|")
|
||||
}
|
||||
if !strings.Contains(got, "minutes ago") && !strings.Contains(got, "just now") {
|
||||
t.Fatalf("template time helpers suffix = %q, want relative time output", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompositeHelpersRespectWordMap(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue