@@ -2,9 +2,10 @@ package phpserialize_test
2
2
3
3
import (
4
4
"errors"
5
- "github.com/elliotchance/phpserialize"
6
5
"reflect"
7
6
"testing"
7
+
8
+ "github.com/elliotchance/phpserialize"
8
9
)
9
10
10
11
func expectErrorToNotHaveOccurred (t * testing.T , err error ) {
@@ -313,6 +314,46 @@ func TestUnmarshalArray(t *testing.T) {
313
314
[]interface {}{true , false },
314
315
nil ,
315
316
},
317
+ "[]interface{}: [1, 2, 'foo']" : {
318
+ []byte (`a:3:{i:0;i:1;i:1;i:2;i:2;s:3:"foo";}` ),
319
+ []interface {}{int64 (1 ), int64 (2 ), "foo" },
320
+ nil ,
321
+ },
322
+ "[]interface{}: [1, 2, 'foo', '中文']" : {
323
+ []byte (`a:4:{i:0;i:1;i:1;i:2;i:2;s:3:"foo";i:3;s:6:"中文";}` ),
324
+ []interface {}{int64 (1 ), int64 (2 ), "foo" , "中文" },
325
+ nil ,
326
+ },
327
+ "[]interface{}: [1, 2, 'foo', '中文', ['a' => 'a']]" : {
328
+ []byte (`a:5:{i:0;i:1;i:1;i:2;i:2;s:3:"foo";i:3;s:6:"中文";i:4;a:1:{s:1:"a";s:1:"a";}}` ),
329
+ []interface {}{int64 (1 ), int64 (2 ), "foo" , "中文" , map [interface {}]interface {}{"a" : "a" }},
330
+ nil ,
331
+ },
332
+ "[]interface{}: [1, 2, 'foo', ['a' => 'a']]" : {
333
+ []byte (`a:4:{i:0;i:1;i:1;i:2;i:2;s:3:"foo";i:3;a:1:{s:1:"a";s:1:"a";}}` ),
334
+ []interface {}{int64 (1 ), int64 (2 ), "foo" , map [interface {}]interface {}{"a" : "a" }},
335
+ nil ,
336
+ },
337
+ "[]interface{}: [1, 2, 'foo', ['a' => 'a'], ['a' => 'a']]" : {
338
+ []byte (`a:5:{i:0;i:1;i:1;i:2;i:2;s:3:"foo";i:3;a:1:{s:1:"a";s:1:"a";}i:4;a:1:{s:1:"a";s:1:"a";}}` ),
339
+ []interface {}{int64 (1 ), int64 (2 ), "foo" , map [interface {}]interface {}{"a" : "a" }, map [interface {}]interface {}{"a" : "a" }},
340
+ nil ,
341
+ },
342
+ "[]interface{}: [1, 2, 'foo', '中文', ['a' => 'a'], ['a' => 'a']]" : {
343
+ []byte (`a:6:{i:0;i:1;i:1;i:2;i:2;s:3:"foo";i:3;s:6:"中文";i:4;a:1:{s:1:"a";s:1:"a";}i:5;a:1:{s:1:"a";s:1:"a";}}` ),
344
+ []interface {}{int64 (1 ), int64 (2 ), "foo" , "中文" , map [interface {}]interface {}{"a" : "a" }, map [interface {}]interface {}{"a" : "a" }},
345
+ nil ,
346
+ },
347
+ "[]interface{}: [['id'=> '1'], ['id'=> '2']]" : {
348
+ []byte (`a:2:{i:0;a:1:{s:2:"id";s:1:"1";}i:1;a:1:{s:2:"id";s:1:"2";}}` ),
349
+ []interface {}{map [interface {}]interface {}{"id" : "1" }, map [interface {}]interface {}{"id" : "2" }},
350
+ nil ,
351
+ },
352
+ "[]interface{}: [['id'=> '1', 'name' => '1'], ['id'=> '2', 'name' => '2'], ['id'=> '3', 'name' => '3']]" : {
353
+ []byte (`a:3:{i:0;a:2:{s:2:"id";s:1:"1";s:4:"name";s:1:"1";}i:1;a:2:{s:2:"id";s:1:"2";s:4:"name";s:1:"2";}i:2;a:2:{s:2:"id";s:1:"3";s:4:"name";s:1:"3";}}` ),
354
+ []interface {}{map [interface {}]interface {}{"id" : "1" , "name" : "1" }, map [interface {}]interface {}{"id" : "2" , "name" : "2" }, map [interface {}]interface {}{"id" : "3" , "name" : "3" }},
355
+ nil ,
356
+ },
316
357
"cannot decode map as slice" : {
317
358
[]byte ("a:2:{i:0;b:1;i:5;b:0;}" ),
318
359
[]interface {}{},
@@ -366,6 +407,16 @@ func TestUnmarshalAssociativeArray(t *testing.T) {
366
407
map [interface {}]interface {}{int64 (1 ): int64 (10 ), int64 (2 ): "foo" },
367
408
nil ,
368
409
},
410
+ "map[interface{}]interface{}: {'foo': 10, 'bar': 20, 'foobar': {'foo': 10, 'bar': 20}}" : {
411
+ []byte (`a:3:{s:3:"foo";i:10;s:3:"bar";i:20;s:6:"foobar";a:2:{s:3:"foo";i:10;s:3:"bar";i:20;}}` ),
412
+ map [interface {}]interface {}{"foo" : int64 (10 ), "bar" : int64 (20 ), "foobar" : map [interface {}]interface {}{"foo" : int64 (10 ), "bar" : int64 (20 )}},
413
+ nil ,
414
+ },
415
+ "map[interface{}]interface{}: {'foo': 10, 'bar': 20, 'foobar': {'foo': 10, 'bar': 20}, 'foobar1': {'foo': 10, 'bar': 20}}" : {
416
+ []byte (`a:4:{s:3:"foo";i:10;s:3:"bar";i:20;s:6:"foobar";a:2:{s:3:"foo";i:10;s:3:"bar";i:20;}s:7:"foobar1";a:2:{s:3:"foo";i:10;s:3:"bar";i:20;}}` ),
417
+ map [interface {}]interface {}{"foo" : int64 (10 ), "bar" : int64 (20 ), "foobar" : map [interface {}]interface {}{"foo" : int64 (10 ), "bar" : int64 (20 )}, "foobar1" : map [interface {}]interface {}{"foo" : int64 (10 ), "bar" : int64 (20 )}},
418
+ nil ,
419
+ },
369
420
"not an array" : {
370
421
[]byte ("N;" ),
371
422
map [interface {}]interface {}{},
@@ -542,7 +593,7 @@ func TestUnmarshalMultibyte(t *testing.T) {
542
593
}
543
594
}
544
595
545
- var escapeTests = map [string ]struct {
596
+ var escapeTests = map [string ]struct {
546
597
Unserialized , Serialized string
547
598
}{
548
599
"SingleQuote" : {
0 commit comments