feat: per-file example tests — action, registry, fs, api, string, path, service, error, array
33 new examples across 8 dedicated files. Removed phantom CleanPath
(in RFC spec but never implemented — spec drift caught by examples).
545 tests total, 84.8% coverage. Every major primitive has compilable
examples that serve as test, documentation seed, and godoc content.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 18:29:24 +00:00
|
|
|
package core_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
. "dappco.re/go/core"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ExampleAPI_RegisterProtocol() {
|
|
|
|
|
c := New()
|
|
|
|
|
c.API().RegisterProtocol("http", func(h *DriveHandle) (Stream, error) {
|
|
|
|
|
return &mockStream{response: []byte("pong")}, nil
|
|
|
|
|
})
|
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
|
|
|
Println(c.API().Protocols())
|
feat: per-file example tests — action, registry, fs, api, string, path, service, error, array
33 new examples across 8 dedicated files. Removed phantom CleanPath
(in RFC spec but never implemented — spec drift caught by examples).
545 tests total, 84.8% coverage. Every major primitive has compilable
examples that serve as test, documentation seed, and godoc content.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 18:29:24 +00:00
|
|
|
// Output: [http]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExampleAPI_Stream() {
|
|
|
|
|
c := New()
|
|
|
|
|
c.API().RegisterProtocol("http", func(h *DriveHandle) (Stream, error) {
|
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
|
|
|
return &mockStream{response: []byte(Concat("connected to ", h.Name))}, nil
|
feat: per-file example tests — action, registry, fs, api, string, path, service, error, array
33 new examples across 8 dedicated files. Removed phantom CleanPath
(in RFC spec but never implemented — spec drift caught by examples).
545 tests total, 84.8% coverage. Every major primitive has compilable
examples that serve as test, documentation seed, and godoc content.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 18:29:24 +00:00
|
|
|
})
|
|
|
|
|
c.Drive().New(NewOptions(
|
|
|
|
|
Option{Key: "name", Value: "charon"},
|
|
|
|
|
Option{Key: "transport", Value: "http://10.69.69.165:9101"},
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
r := c.API().Stream("charon")
|
|
|
|
|
if r.OK {
|
|
|
|
|
stream := r.Value.(Stream)
|
|
|
|
|
resp, _ := stream.Receive()
|
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
|
|
|
Println(string(resp))
|
feat: per-file example tests — action, registry, fs, api, string, path, service, error, array
33 new examples across 8 dedicated files. Removed phantom CleanPath
(in RFC spec but never implemented — spec drift caught by examples).
545 tests total, 84.8% coverage. Every major primitive has compilable
examples that serve as test, documentation seed, and godoc content.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 18:29:24 +00:00
|
|
|
stream.Close()
|
|
|
|
|
}
|
|
|
|
|
// Output: connected to charon
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExampleCore_RemoteAction() {
|
|
|
|
|
c := New()
|
|
|
|
|
// Local action
|
|
|
|
|
c.Action("status", func(_ context.Context, _ Options) Result {
|
|
|
|
|
return Result{Value: "running", OK: true}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// No colon — resolves locally
|
|
|
|
|
r := c.RemoteAction("status", context.Background(), NewOptions())
|
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
|
|
|
Println(r.Value)
|
feat: per-file example tests — action, registry, fs, api, string, path, service, error, array
33 new examples across 8 dedicated files. Removed phantom CleanPath
(in RFC spec but never implemented — spec drift caught by examples).
545 tests total, 84.8% coverage. Every major primitive has compilable
examples that serve as test, documentation seed, and godoc content.
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 18:29:24 +00:00
|
|
|
// Output: running
|
|
|
|
|
}
|