From 3364f522cd69ae563515c0e42e0c8a30d9f5424c Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 24 Sep 2023 09:28:48 +0900 Subject: [PATCH] initial commits --- nullable_whennull_test.go | 205 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 nullable_whennull_test.go diff --git a/nullable_whennull_test.go b/nullable_whennull_test.go new file mode 100644 index 0000000..906ff57 --- /dev/null +++ b/nullable_whennull_test.go @@ -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 + } + } +}