go/registry_example_test.go
Snider 5be20af4b0 feat: eliminate fmt, string concat — add core.Println, use Concat/Path everywhere
New primitive: core.Println() wraps fmt.Println.

Replaced across all test + example files:
- fmt.Println → Println (17 example files)
- fmt.Sprintf → Concat + Sprint
- dir + "/file" → Path(dir, "file") (path security)
- "str" + var → Concat("str", var) (AX consistency)

"fmt" import is now zero across all test files.
String concat with + is zero across all test files.

Remaining 9 stdlib imports (all Go infrastructure):
testing, context, time, sync, embed, io/fs, bytes, gzip, base64

558 tests, 84.5% coverage.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 19:42:39 +00:00

70 lines
1.2 KiB
Go

package core_test
import (
. "dappco.re/go/core"
)
func ExampleRegistry_Set() {
r := NewRegistry[string]()
r.Set("alpha", "first")
r.Set("bravo", "second")
Println(r.Get("alpha").Value)
// Output: first
}
func ExampleRegistry_Names() {
r := NewRegistry[int]()
r.Set("charlie", 3)
r.Set("alpha", 1)
r.Set("bravo", 2)
Println(r.Names())
// Output: [charlie alpha bravo]
}
func ExampleRegistry_List() {
r := NewRegistry[string]()
r.Set("process.run", "run")
r.Set("process.kill", "kill")
r.Set("brain.recall", "recall")
items := r.List("process.*")
Println(len(items))
// Output: 2
}
func ExampleRegistry_Each() {
r := NewRegistry[int]()
r.Set("a", 1)
r.Set("b", 2)
r.Set("c", 3)
sum := 0
r.Each(func(_ string, v int) { sum += v })
Println(sum)
// Output: 6
}
func ExampleRegistry_Disable() {
r := NewRegistry[string]()
r.Set("alpha", "first")
r.Set("bravo", "second")
r.Disable("alpha")
var names []string
r.Each(func(name string, _ string) { names = append(names, name) })
Println(names)
// Output: [bravo]
}
func ExampleRegistry_Delete() {
r := NewRegistry[string]()
r.Set("temp", "value")
Println(r.Has("temp"))
r.Delete("temp")
Println(r.Has("temp"))
// Output:
// true
// false
}