initial version

This commit is contained in:
2026-02-27 22:17:21 +03:00
parent 31f58f1c66
commit eba10f7f42
3 changed files with 120 additions and 0 deletions

88
option_test.go Normal file
View File

@@ -0,0 +1,88 @@
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)
}
})
}
}