@@ -2,6 +2,7 @@ package sentinel_test
22
33import (
44 "github.com/onkernel/kernel-go-sdk/internal/encoding/json/sentinel"
5+ "github.com/onkernel/kernel-go-sdk/packages/param"
56 "reflect"
67 "slices"
78 "testing"
@@ -15,25 +16,19 @@ type Pair struct {
1516func TestNullSlice (t * testing.T ) {
1617 var nilSlice []int = nil
1718 var nonNilSlice []int = []int {1 , 2 , 3 }
18- var nullSlice []int = sentinel .NullSlice [int ]()
19+ var nullSlice []int = param .NullSlice [[] int ]()
1920
2021 cases := map [string ]Pair {
21- "nilSlice" : {sentinel .IsNullSlice (nilSlice ), false },
22- "nullSlice" : {sentinel .IsNullSlice (nullSlice ), true },
23- "newNullSlice" : {sentinel .IsNullSlice ( sentinel .NullSlice [int ]()), true },
22+ "nilSlice" : {sentinel .IsNull (nilSlice ), false },
23+ "nullSlice" : {sentinel .IsNull (nullSlice ), true },
24+ "newNullSlice" : {sentinel .IsNull ( param .NullSlice [[] int ]()), true },
2425 "lenNullSlice" : {len (nullSlice ) == 0 , true },
25- "nilSliceValue" : {sentinel .IsValueNullSlice (reflect .ValueOf (nilSlice )), false },
26- "nullSliceValue" : {sentinel .IsValueNullSlice (reflect .ValueOf (nullSlice )), true },
26+ "nilSliceValue" : {sentinel .IsValueNull (reflect .ValueOf (nilSlice )), false },
27+ "nullSliceValue" : {sentinel .IsValueNull (reflect .ValueOf (nullSlice )), true },
2728 "compareSlices" : {slices .Compare (nilSlice , nullSlice ) == 0 , true },
2829 "compareNonNilSlices" : {slices .Compare (nonNilSlice , nullSlice ) == 0 , false },
2930 }
3031
31- nilSlice = append (nullSlice , 12 )
32- cases ["append_result" ] = Pair {sentinel .IsNullSlice (nilSlice ), false }
33- cases ["mutated_result" ] = Pair {sentinel .IsNullSlice (nullSlice ), true }
34- cases ["append_result_len" ] = Pair {len (nilSlice ) == 1 , true }
35- cases ["append_null_slice_len" ] = Pair {len (nullSlice ) == 0 , true }
36-
3732 for name , c := range cases {
3833 t .Run (name , func (t * testing.T ) {
3934 got , want := c .got , c .want
@@ -44,37 +39,20 @@ func TestNullSlice(t *testing.T) {
4439 }
4540}
4641
47- func TestNullPtr (t * testing.T ) {
48- var s * string = nil
49- var i * int = nil
50- var slice * []int = nil
51-
52- var nullptrStr * string = sentinel .NullPtr [string ]()
53- var nullptrInt * int = sentinel .NullPtr [int ]()
54- var nullptrSlice * []int = sentinel .NullPtr [[]int ]()
55-
56- if * nullptrStr != "" {
57- t .Errorf ("Failed to safely deref" )
58- }
59- if * nullptrInt != 0 {
60- t .Errorf ("Failed to safely deref" )
61- }
62- if len (* nullptrSlice ) != 0 {
63- t .Errorf ("Failed to safely deref" )
64- }
42+ func TestNullMap (t * testing.T ) {
43+ var nilMap map [string ]int = nil
44+ var nonNilMap map [string ]int = map [string ]int {"a" : 1 , "b" : 2 }
45+ var nullMap map [string ]int = param .NullMap [map [string ]int ]()
6546
6647 cases := map [string ]Pair {
67- "nilStr" : {sentinel .IsNullPtr (s ), false },
68- "nullStr" : {sentinel .IsNullPtr (nullptrStr ), true },
69-
70- "nilInt" : {sentinel .IsNullPtr (i ), false },
71- "nullInt" : {sentinel .IsNullPtr (nullptrInt ), true },
72-
73- "nilSlice" : {sentinel .IsNullPtr (slice ), false },
74- "nullSlice" : {sentinel .IsNullPtr (nullptrSlice ), true },
75-
76- "nilValuePtr" : {sentinel .IsValueNullPtr (reflect .ValueOf (i )), false },
77- "nullValuePtr" : {sentinel .IsValueNullPtr (reflect .ValueOf (nullptrInt )), true },
48+ "nilMap" : {sentinel .IsNull (nilMap ), false },
49+ "nullMap" : {sentinel .IsNull (nullMap ), true },
50+ "newNullMap" : {sentinel .IsNull (param .NullMap [map [string ]int ]()), true },
51+ "lenNullMap" : {len (nullMap ) == 0 , true },
52+ "nilMapValue" : {sentinel .IsValueNull (reflect .ValueOf (nilMap )), false },
53+ "nullMapValue" : {sentinel .IsValueNull (reflect .ValueOf (nullMap )), true },
54+ "compareMaps" : {reflect .DeepEqual (nilMap , nullMap ), false },
55+ "compareNonNilMaps" : {reflect .DeepEqual (nonNilMap , nullMap ), false },
7856 }
7957
8058 for name , test := range cases {
@@ -86,3 +64,28 @@ func TestNullPtr(t *testing.T) {
8664 })
8765 }
8866}
67+
68+ func TestIsNullRepeated (t * testing.T ) {
69+ // Test for slices
70+ nullSlice1 := param .NullSlice [[]int ]()
71+ nullSlice2 := param .NullSlice [[]int ]()
72+ if ! sentinel .IsNull (nullSlice1 ) {
73+ t .Errorf ("IsNull(nullSlice1) = false, want true" )
74+ }
75+ if ! sentinel .IsNull (nullSlice2 ) {
76+ t .Errorf ("IsNull(nullSlice2) = false, want true" )
77+ }
78+ if ! sentinel .IsNull (nullSlice1 ) || ! sentinel .IsNull (nullSlice2 ) {
79+ t .Errorf ("IsNull should return true for all NullSlice instances" )
80+ }
81+
82+ // Test for maps
83+ nullMap1 := param .NullMap [map [string ]int ]()
84+ nullMap2 := param .NullMap [map [string ]int ]()
85+ if ! sentinel .IsNull (nullMap1 ) {
86+ t .Errorf ("IsNull(nullMap1) = false, want true" )
87+ }
88+ if ! sentinel .IsNull (nullMap2 ) {
89+ t .Errorf ("IsNull(nullMap2) = false, want true" )
90+ }
91+ }
0 commit comments