let

package
v0.151.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

README

Package let

Package let contains Common Testcase variable #Let declarations for testing purpose.

var (
	ctx  = let.Context(s)
	name = let.FirstName(s)
)
act := func(t *testcase.T) error {
	return MyFunc(ctx.Get(t), name.Get(t))
}

Documentation

Overview

Package let contains Common Testcase Variable Let declarations for testing purpose.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[To, From any](Var testcase.Var[From]) testcase.Var[To]
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))
	})
}
Output:

func Bool

func Bool(s *testcase.Spec) testcase.Var[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))
	})
}
Output:

func Context

func Context(s *testcase.Spec) testcase.Var[context.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))
	})
}
Output:

func ElementFrom

func ElementFrom[V any](s *testcase.Spec, vs ...V) testcase.Var[V]
Example
package main

import (
	"testing"

	"go.llib.dev/testcase"
	"go.llib.dev/testcase/let"
)

func main() {
	s := testcase.NewSpec((testing.TB)(nil))

	v := let.ElementFrom(s, "foo", "bar", "baz")

	s.Test("", func(t *testcase.T) {
		t.Log(v.Get(t))
	})
}
Output:

func Email

func Email(s *testcase.Spec) testcase.Var[string]
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))
	})
}
Output:

func Error

func Error(s *testcase.Spec) testcase.Var[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))
	})
}
Output:

func FirstName

func FirstName(s *testcase.Spec, opts ...internal.ContactOption) testcase.Var[string]
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))
	})
}
Output:

func Int

func Int(s *testcase.Spec) testcase.Var[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))
	})
}
Output:

func IntB

func IntB(s *testcase.Spec, min, max int) testcase.Var[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.IntB(s, 7, 42)

	s.Test("", func(t *testcase.T) {
		t.Log(n.Get(t))
	})
}
Output:

func IntN

func IntN(s *testcase.Spec, n int) testcase.Var[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.IntN(s, 42)

	s.Test("", func(t *testcase.T) {
		t.Log(n.Get(t))
	})
}
Output:

func LastName

func LastName(s *testcase.Spec) testcase.Var[string]
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))
	})
}
Output:

func String

func String(s *testcase.Spec) testcase.Var[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))
	})
}
Output:

func StringNC

func StringNC(s *testcase.Spec, length int, charset string) testcase.Var[string]
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))
	})
}
Output:

func Time

func Time(s *testcase.Spec) testcase.Var[time.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))
	})
}
Output:

func TimeB

func TimeB(s *testcase.Spec, from, to time.Time) testcase.Var[time.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.TimeB(s, time.Now().AddDate(-1, 0, 0), time.Now())

	s.Test("", func(t *testcase.T) {
		t.Log(tm.Get(t).Format(time.RFC3339))
	})
}
Output:

func UUID

func UUID(s *testcase.Spec) testcase.Var[string]
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))
	})
}
Output:

func With

func With[V any, FN withFN[V]](s *testcase.Spec, fn FN) testcase.Var[V]
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))
	})
}
Output:

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))
	})
}
Output:

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))
	})
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL