initial commits

master
Charles Iliya Krempeaux 2023-09-24 09:28:48 +09:00
parent 96c7683a06
commit 3364f522cd
1 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,205 @@
package nul_test
import (
"testing"
"sourcecode.social/reiver/go-nul"
)
func TestNullable_WhenNull_nothing(t *testing.T) {
tests := []struct{
Nullable interface{WhenNull(func())}
}{
{
Nullable: nul.Nothing[string](),
},
{
Nullable: nul.Nothing[int](),
},
{
Nullable: nul.Nothing[int8](),
},
{
Nullable: nul.Nothing[int16](),
},
{
Nullable: nul.Nothing[int32](),
},
{
Nullable: nul.Nothing[int64](),
},
{
Nullable: nul.Nothing[uint](),
},
{
Nullable: nul.Nothing[uint8](),
},
{
Nullable: nul.Nothing[uint16](),
},
{
Nullable: nul.Nothing[uint32](),
},
{
Nullable: nul.Nothing[uint64](),
},
}
for testNumber, test := range tests {
var worked bool = false
test.Nullable.WhenNull(func(){
worked = true
})
if worked {
t.Errorf("For test #%d, the call to the method worked, but it should not have.", testNumber)
t.Logf("WORKED: %t", worked)
t.Logf("NULLABLE: (%T) %#v", test.Nullable, test.Nullable)
//////////////// CONTINUE
continue
}
}
}
func TestNullable_WhenNull_null(t *testing.T) {
tests := []struct{
Nullable interface{WhenNull(func())}
}{
{
Nullable: nul.Null[string](),
},
{
Nullable: nul.Null[int](),
},
{
Nullable: nul.Null[int8](),
},
{
Nullable: nul.Null[int16](),
},
{
Nullable: nul.Null[int32](),
},
{
Nullable: nul.Null[int64](),
},
{
Nullable: nul.Null[uint](),
},
{
Nullable: nul.Null[uint8](),
},
{
Nullable: nul.Null[uint16](),
},
{
Nullable: nul.Null[uint32](),
},
{
Nullable: nul.Null[uint64](),
},
}
for testNumber, test := range tests {
var worked bool = false
test.Nullable.WhenNull(func(){
worked = true
})
if !worked {
t.Errorf("For test #%d, the call to the method did not seem work.", testNumber)
t.Logf("WORKED: %t", worked)
t.Logf("NULLABLE: (%T) %#v", test.Nullable, test.Nullable)
//////////////// CONTINUE
continue
}
}
}
func TestNullable_WhenNull_something(t *testing.T) {
tests := []struct{
Nullable interface{WhenNull(func())}
}{
{
Nullable: nul.Something[string]("once twice thrice fource"),
},
{
Nullable: nul.Something[int](-1),
},
{
Nullable: nul.Something[int8](-101),
},
{
Nullable: nul.Something[int16](-10101),
},
{
Nullable: nul.Something[int32](-1010101),
},
{
Nullable: nul.Something[int64](-101010101),
},
{
Nullable: nul.Something[uint](1),
},
{
Nullable: nul.Something[uint8](101),
},
{
Nullable: nul.Something[uint16](10101),
},
{
Nullable: nul.Something[uint32](1010101),
},
{
Nullable: nul.Something[uint64](101010101),
},
}
for testNumber, test := range tests {
var worked bool = false
test.Nullable.WhenNull(func(){
worked = true
})
if worked {
t.Errorf("For test #%d, the call to the method worked, but it should not have.", testNumber)
t.Logf("WORKED: %t", worked)
t.Logf("NULLABLE: (%T) %#v", test.Nullable, test.Nullable)
//////////////// CONTINUE
continue
}
}
}