Skip to content

Commit 0797be7

Browse files
committed
Add more test case
1 parent fd29f98 commit 0797be7

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

gophpserialize_test.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
package gophpserialize
22

33
import (
4-
"testing"
4+
"testing"
55
)
66

7+
func TestUnmarshalString(t *testing.T) {
8+
data := `a:8:{s:4:"type";s:12:"package-coin";s:6:"useBag";i:0;s:3:"gid";s:5:"20000";s:3:"num";i:1;s:3:"rid";i:105698894;s:4:"from";s:9:"800005631";s:2:"to";s:9:"800240177";s:6:"_use_g";i:10;}`
9+
10+
obj := Unmarshal([]byte(data)).(map[string]interface{})
11+
12+
if obj["type"] != "package-coin" {
13+
t.Error("Unmarshal failed")
14+
}
15+
16+
if obj["rid"] != 105698894 {
17+
t.Error("Unmarshal failed")
18+
}
19+
}
20+
721
func TestUnmarshal(t *testing.T) {
822
data := `a:3:{s:5:"apple";i:1;s:6:"orange";i:2;s:5:"grape";i:3;}`
923

@@ -21,9 +35,9 @@ func TestUnmarshal(t *testing.T) {
2135

2236
data = `a:1:{s:7:"catalog";a:3:{i:2;a:4:{s:5:"width";s:3:"236";s:6:"height";s:3:"345";s:7:"quality";s:2:"90";s:13:"image_formats";s:3:"jpg";}i:1;a:4:{s:5:"width";s:3:"160";s:6:"height";s:3:"160";s:7:"quality";s:2:"80";s:13:"image_formats";s:3:"jpg";}i:3;a:4:{s:5:"width";s:3:"160";s:6:"height";s:3:"160";s:7:"quality";s:2:"80";s:13:"image_formats";s:3:"jpg";}}`
2337
obj = Unmarshal([]byte(data)).(map[string]interface{})
24-
if _, hasV := obj["catalog"].(map[string]interface{})["0"]; hasV ==true {
25-
t.Error("Unmarshal failed")
26-
}
38+
if _, hasV := obj["catalog"].(map[string]interface{})["0"]; hasV == true {
39+
t.Error("Unmarshal failed")
40+
}
2741
}
2842

2943
func TestPhpToJson(t *testing.T) {

0 commit comments

Comments
 (0)