Files
option/option_test.go

89 lines
1.3 KiB
Go
Raw Permalink Normal View History

2026-02-27 22:17:21 +03:00
package option_test
import (
"testing"
"code.uint32.ru/tiny/option"
)
func TestIsSome(t *testing.T) {
tc := []struct {
name string
opt option.Option[int]
want bool
}{
{
name: "Some",
opt: option.Some(5),
want: true,
},
{
name: "None",
opt: option.None[int](),
want: false,
},
}
for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
if got := c.opt.IsSome(); got != c.want {
t.Errorf("IsSome() = %v; want %v", got, c.want)
}
})
}
}
func TestIsNone(t *testing.T) {
tc := []struct {
name string
opt option.Option[int]
want bool
}{
{
name: "Some",
opt: option.Some(5),
want: false,
},
{
name: "None",
opt: option.None[int](),
want: true,
},
}
for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
if got := c.opt.IsNone(); got != c.want {
t.Errorf("IsNone() = %v; want %v", got, c.want)
}
})
}
}
func TestTake(t *testing.T) {
tc := []struct {
name string
opt option.Option[int]
want int
}{
{
name: "Some",
opt: option.Some(5),
want: 5,
},
{
name: "None",
opt: option.None[int](),
want: 0,
},
}
for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
if got := c.opt.Take(); got != c.want {
t.Errorf("Take() = %v; want %v", got, c.want)
}
})
}
}