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>
42 lines
811 B
Go
42 lines
811 B
Go
package core_test
|
|
|
|
import (
|
|
|
|
. "dappco.re/go/core"
|
|
)
|
|
|
|
func ExampleFs_WriteAtomic() {
|
|
f := (&Fs{}).New("/")
|
|
dir := f.TempDir("example")
|
|
defer f.DeleteAll(dir)
|
|
|
|
path := Path(dir, "status.json")
|
|
f.WriteAtomic(path, `{"status":"completed"}`)
|
|
|
|
r := f.Read(path)
|
|
Println(r.Value)
|
|
// Output: {"status":"completed"}
|
|
}
|
|
|
|
func ExampleFs_NewUnrestricted() {
|
|
f := (&Fs{}).New("/")
|
|
dir := f.TempDir("example")
|
|
defer f.DeleteAll(dir)
|
|
|
|
// Write outside sandbox using Core's Fs
|
|
outside := Path(dir, "outside.txt")
|
|
f.Write(outside, "hello")
|
|
|
|
sandbox := (&Fs{}).New(Path(dir, "sandbox"))
|
|
unrestricted := sandbox.NewUnrestricted()
|
|
|
|
r := unrestricted.Read(outside)
|
|
Println(r.Value)
|
|
// Output: hello
|
|
}
|
|
|
|
func ExampleFs_Root() {
|
|
f := (&Fs{}).New("/srv/workspaces")
|
|
Println(f.Root())
|
|
// Output: /srv/workspaces
|
|
}
|