From 14aedb7cb3e07d410e5059f71a4541698154c803 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 24 Sep 2023 08:02:47 +0900 Subject: [PATCH] initial commits --- nullable_whennothing_test.go | 139 +++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 nullable_whennothing_test.go diff --git a/nullable_whennothing_test.go b/nullable_whennothing_test.go new file mode 100644 index 0000000..7a65182 --- /dev/null +++ b/nullable_whennothing_test.go @@ -0,0 +1,139 @@ +package nul_test + +import ( + "testing" + + "sourcecode.social/reiver/go-nul" +) + +func TestNullable_WhenNothing(t *testing.T) { + + + tests := []struct{ + Nullable interface{WhenNothing(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.WhenNothing(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_WhenNothing_something(t *testing.T) { + + + tests := []struct{ + Nullable interface{WhenNothing(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.WhenNothing(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 + } + } +}