2026-03-25 18:39:36 +00:00
|
|
|
package core_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
. "dappco.re/go/core"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ExampleTask_Run() {
|
|
|
|
|
c := New()
|
|
|
|
|
var order string
|
|
|
|
|
|
|
|
|
|
c.Action("step.a", func(_ context.Context, _ Options) Result {
|
|
|
|
|
order += "a"
|
|
|
|
|
return Result{Value: "from-a", OK: true}
|
|
|
|
|
})
|
|
|
|
|
c.Action("step.b", func(_ context.Context, opts Options) Result {
|
|
|
|
|
order += "b"
|
|
|
|
|
input := opts.Get("_input")
|
|
|
|
|
if input.OK {
|
|
|
|
|
return Result{Value: "got:" + input.Value.(string), OK: true}
|
|
|
|
|
}
|
|
|
|
|
return Result{OK: true}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
c.Task("pipe", Task{
|
|
|
|
|
Steps: []Step{
|
|
|
|
|
{Action: "step.a"},
|
|
|
|
|
{Action: "step.b", Input: "previous"},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
r := c.Task("pipe").Run(context.Background(), c, 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(order)
|
|
|
|
|
Println(r.Value)
|
2026-03-25 18:39:36 +00:00
|
|
|
// Output:
|
|
|
|
|
// ab
|
|
|
|
|
// got:from-a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ExampleCore_PerformAsync() {
|
|
|
|
|
c := New()
|
|
|
|
|
c.Action("bg.work", func(_ context.Context, _ Options) Result {
|
|
|
|
|
return Result{Value: "done", OK: true}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
r := c.PerformAsync("bg.work", 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(HasPrefix(r.Value.(string), "id-"))
|
2026-03-25 18:39:36 +00:00
|
|
|
// Output: true
|
|
|
|
|
}
|