Files
Memoh/internal/memory/adapters/builtin/builtin_test.go
T
晨苒 627b673a5c refactor: multi-provider memory adapters with scan-based builtin (#227)
* refactor: restructure memory into multi-provider adapters, remove manifest.json dependency

- Rename internal/memory/provider to internal/memory/adapters with per-provider subdirectories (builtin, mem0, openviking)
- Replace manifest.json-based delete/update with scan-based index from daily files
- Add mem0 and openviking provider adapters with HTTP client, chat hooks, MCP tools, and CRUD
- Wire provider lifecycle into registry (auto-instantiate on create, evict on update/delete)
- Split docker-compose into base stack + optional overlays (qdrant, browser, mem0, openviking)
- Update admin UI to support dynamic provider config schema rendering

* chore(lint): fix all golangci-lint issues for clean CI

* refactor(docker): replace compose overlay files with profiles

* feat(memory): add built-in memory multi modes

* fix(ci): golangci lint

* feat(memory): edit built-in memory sparse design
2026-03-14 06:04:13 +08:00

57 lines
1.3 KiB
Go

package builtin
import (
"testing"
"unicode/utf8"
adapters "github.com/memohai/memoh/internal/memory/adapters"
)
func TestTruncateSnippet_ASCII(t *testing.T) {
t.Parallel()
got := adapters.TruncateSnippet("hello world", 5)
if got != "hello..." {
t.Fatalf("expected %q, got %q", "hello...", got)
}
}
func TestTruncateSnippet_NoTruncation(t *testing.T) {
t.Parallel()
got := adapters.TruncateSnippet("short", 100)
if got != "short" {
t.Fatalf("expected %q, got %q", "short", got)
}
}
func TestTruncateSnippet_CJK(t *testing.T) {
t.Parallel()
// 5 CJK characters (15 bytes in UTF-8), truncate to 3 runes.
got := adapters.TruncateSnippet("你好世界啊", 3)
if !utf8.ValidString(got) {
t.Fatalf("result is not valid UTF-8: %q", got)
}
if got != "你好世..." {
t.Fatalf("expected %q, got %q", "你好世...", got)
}
}
func TestTruncateSnippet_Emoji(t *testing.T) {
t.Parallel()
// Emoji are 4 bytes each in UTF-8.
got := adapters.TruncateSnippet("😀😁😂🤣😃", 2)
if !utf8.ValidString(got) {
t.Fatalf("result is not valid UTF-8: %q", got)
}
if got != "😀😁..." {
t.Fatalf("expected %q, got %q", "😀😁...", got)
}
}
func TestTruncateSnippet_TrimWhitespace(t *testing.T) {
t.Parallel()
got := adapters.TruncateSnippet(" hello ", 100)
if got != "hello" {
t.Fatalf("expected %q, got %q", "hello", got)
}
}