Documentation
¶
Index ¶
- func Act[A any](fn func(t *testcase.T) A) func(t *testcase.T) A
- func Act2[A, B any](fn func(t *testcase.T) (A, B)) func(t *testcase.T) (A, B)
- func Act3[A, B, C any](fn func(t *testcase.T) (A, B, C)) func(t *testcase.T) (A, B, C)
- func As[To, From any](Var testcase.Var[From]) testcase.Var[To]
- func Bool(s *testcase.Spec) testcase.Var[bool]
- func Contact(s *testcase.Spec, opts ...internal.ContactOption) testcase.Var[random.Contact]
- func Context(s *testcase.Spec) testcase.Var[context.Context]
- func ContextWithCancel(s *testcase.Spec) (testcase.Var[context.Context], testcase.Var[func()])
- func DurationBetween(s *testcase.Spec, min, max time.Duration) testcase.Var[time.Duration]
- func ElementFrom[V any](s *testcase.Spec, vs ...V) testcase.Var[V]deprecated
- func Email(s *testcase.Spec) testcase.Var[string]
- func Error(s *testcase.Spec) testcase.Var[error]
- func FirstName(s *testcase.Spec, opts ...internal.ContactOption) testcase.Var[string]
- func HTTPTestResponseRecorder(s *testcase.Spec) testcase.Var[*httptest.ResponseRecorder]
- func Int(s *testcase.Spec) testcase.Var[int]
- func IntB(s *testcase.Spec, min, max int) testcase.Var[int]
- func IntN(s *testcase.Spec, n int) testcase.Var[int]
- func LastName(s *testcase.Spec) testcase.Var[string]
- func OneOf[V any](s *testcase.Spec, vs ...V) testcase.Var[V]
- func String(s *testcase.Spec) testcase.Var[string]
- func StringNC(s *testcase.Spec, length int, charset string) testcase.Var[string]
- func Time(s *testcase.Spec) testcase.Var[time.Time]
- func TimeB(s *testcase.Spec, from, to time.Time) testcase.Var[time.Time]
- func UUID(s *testcase.Spec) testcase.Var[string]
- func Var[V any](s *testcase.Spec, blk func(t *testcase.T) V) testcase.Var[V]
- func Var2[V1, V2 any](s *testcase.Spec, blk func(t *testcase.T) (V1, V2)) (testcase.Var[V1], testcase.Var[V2])
- func Var3[V1, V2, V3 any](s *testcase.Spec, blk func(t *testcase.T) (V1, V2, V3)) (testcase.Var[V1], testcase.Var[V2], testcase.Var[V3])
- func VarOf[V any](s *testcase.Spec, v V) testcase.Var[V]
- func With[V any, FN withFN[V]](s *testcase.Spec, fn FN) testcase.Var[V]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Act ¶ added in v0.171.0
Act is a syntax shortcut that improves auto-completion in code editors like VS Code or IntelliJ IDEA. It represents a stateless testing action, where the closure retrieves input argument variables. This ensures that the test scenario properly arranges the variables beforehand since Act itself remains immutable.
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { // in production code var MyFunc = func(n int) bool { return n%2 == 0 } // TestMyFunc(t *testing.T) var t *testing.T s := testcase.NewSpec(t) var ( n = let.Int(s) ) act := let.Act(func(t *testcase.T) bool { return MyFunc(n.Get(t)) }) s.Then("...", func(t *testcase.T) { var got bool = act(t) _ = got // assert }) }
func Act2 ¶ added in v0.171.0
Act2 is a syntax shortcut that improves auto-completion in code editors like VS Code or IntelliJ IDEA. It represents a stateless testing action, where the closure retrieves input argument variables. This ensures that the test scenario properly arranges the variables beforehand since Act itself remains immutable.
Example ¶
package main import ( "strconv" "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" "go.llib.dev/testcase/random" ) func main() { var t *testing.T s := testcase.NewSpec(t) var ( str = let.StringNC(s, 3, random.CharsetDigit()) ) act := let.Act2(func(t *testcase.T) (int, error) { return strconv.Atoi(str.Get(t)) }) s.Then("...", func(t *testcase.T) { _, _ = act(t) }) }
func Act3 ¶ added in v0.171.0
Act3 is a syntax shortcut that improves auto-completion in code editors like VS Code or IntelliJ IDEA. It represents a stateless testing action, where the closure retrieves input argument variables. This ensures that the test scenario properly arranges the variables beforehand since Act itself remains immutable.
Example ¶
package main import ( "strconv" "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" "go.llib.dev/testcase/random" ) func main() { // package mypkg var MyFunc = func(str string) (string, int, error) { n, err := strconv.Atoi(str) return str, n, err } // package mypkg_test var t *testing.T s := testcase.NewSpec(t) var ( str = let.StringNC(s, 3, random.CharsetDigit()) ) act := let.Act3(func(t *testcase.T) (string, int, error) { return MyFunc(str.Get(t)) }) s.Then("...", func(t *testcase.T) { _, _, _ = act(t) }) }
func As ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) type MyString string str := let.As[MyString](let.String(s)) s.Test("", func(t *testcase.T) { t.Log(str.Get(t)) }) }
func Bool ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) b := let.Bool(s) s.Test("", func(t *testcase.T) { t.Log(b.Get(t)) }) }
func Context ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) ctx := let.Context(s) s.Test("", func(t *testcase.T) { t.Logf("%#v", ctx.Get(t)) }) }
func ContextWithCancel ¶ added in v0.165.0
func DurationBetween ¶ added in v0.164.0
func Email ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) email := let.Email(s) s.Test("", func(t *testcase.T) { t.Log(email.Get(t)) }) }
func Error ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) expectedErr := let.Error(s) s.Test("", func(t *testcase.T) { t.Log(expectedErr.Get(t)) }) }
func FirstName ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) firstName := let.FirstName(s) s.Test("", func(t *testcase.T) { t.Log(firstName.Get(t)) }) }
func HTTPTestResponseRecorder ¶ added in v0.170.0
func Int ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) n := let.Int(s) s.Test("", func(t *testcase.T) { t.Log(n.Get(t)) }) }
func IntB ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) n := let.IntB(s, 7, 42) s.Test("", func(t *testcase.T) { t.Log(n.Get(t)) }) }
func IntN ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) n := let.IntN(s, 42) s.Test("", func(t *testcase.T) { t.Log(n.Get(t)) }) }
func LastName ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) lastName := let.LastName(s) s.Test("", func(t *testcase.T) { t.Log(lastName.Get(t)) }) }
func OneOf ¶ added in v0.172.0
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) v := let.OneOf(s, "foo", "bar", "baz") s.Test("", func(t *testcase.T) { t.Log(v.Get(t)) }) }
func String ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) str := let.String(s) s.Test("", func(t *testcase.T) { t.Log(str.Get(t)) }) }
func StringNC ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" "go.llib.dev/testcase/random" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) str := let.StringNC(s, 42, random.CharsetASCII()) s.Test("", func(t *testcase.T) { t.Log(str.Get(t)) }) }
func Time ¶
Example ¶
package main import ( "testing" "time" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) tm := let.Time(s) s.Test("", func(t *testcase.T) { t.Log(tm.Get(t).Format(time.RFC3339)) }) }
func TimeB ¶
Example ¶
package main import ( "testing" "time" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) tm := let.TimeB(s, time.Now().AddDate(-1, 0, 0), time.Now()) s.Test("", func(t *testcase.T) { t.Log(tm.Get(t).Format(time.RFC3339)) }) }
func UUID ¶
Example ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) uuid := let.UUID(s) s.Test("", func(t *testcase.T) { t.Log(uuid.Get(t)) }) }
func Var ¶ added in v0.170.0
Var creates a stateless specification variable, serving as a blueprint for test cases to construct test runtime values. It also functions as both a getter and setter for the value associated to the test runtime.
Example ¶
package main import ( "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { var t *testcase.T s := testcase.NewSpec(t) v1 := let.Var(s, func(t *testcase.T) int { return t.Random.IntB(1, 7) }) s.Test("", func(t *testcase.T) { v1.Get(t) // the random value v1.Get(t) // the same random value }) }
func Var2 ¶ added in v0.170.0
func Var2[V1, V2 any](s *testcase.Spec, blk func(t *testcase.T) (V1, V2)) (testcase.Var[V1], testcase.Var[V2])
Var2 creates a stateless specification variable, serving as a blueprint for test cases to construct test runtime values. It also functions as both a getter and setter for the value associated to the test runtime.
Example ¶
package main import ( "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { var t *testcase.T s := testcase.NewSpec(t) v1, v2 := let.Var2(s, func(t *testcase.T) (int, string) { return t.Random.IntB(1, 7), t.Random.String() }) s.Test("", func(t *testcase.T) { v1.Get(t) // the random value constructed in the init block of Var v1.Get(t) // the same random value v2.Get(t) // the random string we made in the init block v2.Get(t) // the same value }) }
func Var3 ¶ added in v0.170.0
func Var3[V1, V2, V3 any](s *testcase.Spec, blk func(t *testcase.T) (V1, V2, V3)) (testcase.Var[V1], testcase.Var[V2], testcase.Var[V3])
Var3 creates a stateless specification variable, serving as a blueprint for test cases to construct test runtime values. It also functions as both a getter and setter for the value associated to the test runtime.
Example ¶
package main import ( "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { var t *testcase.T s := testcase.NewSpec(t) v1, v2, v3 := let.Var3(s, func(t *testcase.T) (int, string, bool) { return t.Random.IntB(1, 7), t.Random.String(), t.Random.Bool() }) s.Test("", func(t *testcase.T) { v1.Get(t) // the random value constructed in the init block of Var v1.Get(t) // the same random value v2.Get(t) // the random string we made in the init block v2.Get(t) // the same value v3.Get(t) // the random string we made in the init block v3.Get(t) // the same value }) }
func VarOf ¶ added in v0.175.0
VarOf is a shorthand for defining a testcase.Var[V] using an immutable value. So the function blocks can be skipped, which makes tests more readable.
func With ¶
Example (Func) ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) v := let.With[int](s, func() int { return 42 }) s.Test("", func(t *testcase.T) { t.Log(v.Get(t)) }) }
Example (TestcaseTFunc) ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) v := let.With[int](s, func(t *testcase.T) int { return t.Random.Int() }) s.Test("", func(t *testcase.T) { t.Log(v.Get(t)) }) }
Example (TestingTBFunc) ¶
package main import ( "testing" "go.llib.dev/testcase" "go.llib.dev/testcase/let" ) func main() { s := testcase.NewSpec((testing.TB)(nil)) v := let.With[int](s, func(tb testing.TB) int { return 42 }) s.Test("", func(t *testcase.T) { t.Log(v.Get(t)) }) }
Types ¶
This section is empty.