chore: sync from fn-registry agent
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"fn-registry/registry"
|
||||
)
|
||||
|
||||
func TestRenderFunctionMarkdown(t *testing.T) {
|
||||
f := ®istry.Function{
|
||||
ID: "filter_slice_go_core",
|
||||
Name: "filter_slice",
|
||||
Kind: "function",
|
||||
Lang: "go",
|
||||
Domain: "core",
|
||||
Purity: "pure",
|
||||
Version: "1.0.0",
|
||||
Signature: "func FilterSlice[T any](xs []T, pred func(T) bool) []T",
|
||||
Description: "Filtra un slice.",
|
||||
Tags: []string{"slice", "functional"},
|
||||
Code: "func FilterSlice[T any](xs []T, pred func(T) bool) []T { return nil }",
|
||||
FilePath: "functions/core/filter_slice.go",
|
||||
}
|
||||
out := renderFunctionMarkdown(f)
|
||||
wants := []string{
|
||||
"# filter_slice_go_core",
|
||||
"- name: filter_slice",
|
||||
"- purity: pure",
|
||||
"- signature: `func FilterSlice",
|
||||
"## code\n\n```go",
|
||||
"Filtra un slice.",
|
||||
}
|
||||
for _, w := range wants {
|
||||
if !strings.Contains(out, w) {
|
||||
t.Errorf("markdown missing %q\n---\n%s", w, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLangFence(t *testing.T) {
|
||||
cases := map[string]string{"go": "go", "py": "python", "ts": "typescript", "bash": "bash", "ps": "powershell", "cpp": "cpp"}
|
||||
for in, want := range cases {
|
||||
if got := langFence(in); got != want {
|
||||
t.Errorf("langFence(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
if got := truncate("abc", 10); got != "abc" {
|
||||
t.Errorf("no-trunc: %q", got)
|
||||
}
|
||||
if got := truncate("abcdefghij", 5); !strings.HasPrefix(got, "abcde") || !strings.Contains(got, "truncated") {
|
||||
t.Errorf("trunc: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user