github.com/trim21/go-phpserialize@v0.0.22-0.20240301204449-2fca0319b3f0/internal/test/marshal_array_test.go (about) 1 package test_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 "github.com/trim21/go-phpserialize" 8 "github.com/trim21/go-phpserialize/internal/test" 9 ) 10 11 func TestMarshal_array_map(t *testing.T) { 12 var data = [5]map[int]uint{ 13 {-3: 1}, 14 nil, 15 {-1: 1}, 16 } 17 18 actual, err := phpserialize.Marshal(data) 19 require.NoError(t, err) 20 expected := `a:5:{i:0;a:1:{i:-3;i:1;}i:1;N;i:2;a:1:{i:-1;i:1;}i:3;N;i:4;N;}` 21 test.StringEqual(t, expected, string(actual)) 22 } 23 24 func TestMarshal_Array_nil(t *testing.T) { 25 var data [5]int 26 27 actual, err := phpserialize.Marshal(data) 28 require.NoError(t, err) 29 expected := `a:5:{i:0;i:0;i:1;i:0;i:2;i:0;i:3;i:0;i:4;i:0;}` 30 test.StringEqual(t, expected, string(actual)) 31 }