@@ -47,6 +47,34 @@ func TestUnmarshalFeature(t *testing.T) {
47
47
}
48
48
}
49
49
50
+ func TestMarshalFeatureID (t * testing.T ) {
51
+ f := & Feature {
52
+ ID : "asdf" ,
53
+ }
54
+
55
+ data , err := f .MarshalJSON ()
56
+ if err != nil {
57
+ t .Fatalf ("should marshal, %v" , err )
58
+ }
59
+
60
+ if ! bytes .Equal (data , []byte (`{"id":"asdf","type":"Feature","geometry":null,"properties":null}` )) {
61
+ t .Errorf ("data not correct" )
62
+ t .Logf ("%v" , string (data ))
63
+ }
64
+
65
+ f .ID = 123
66
+ data , err = f .MarshalJSON ()
67
+ if err != nil {
68
+ t .Fatalf ("should marshal, %v" , err )
69
+
70
+ }
71
+
72
+ if ! bytes .Equal (data , []byte (`{"id":123,"type":"Feature","geometry":null,"properties":null}` )) {
73
+ t .Errorf ("data not correct" )
74
+ t .Logf ("%v" , string (data ))
75
+ }
76
+ }
77
+
50
78
func TestUnmarshalFeatureID (t * testing.T ) {
51
79
rawJSON := `
52
80
{ "type": "Feature",
@@ -59,8 +87,8 @@ func TestUnmarshalFeatureID(t *testing.T) {
59
87
t .Fatalf ("should unmarshal feature without issue, err %v" , err )
60
88
}
61
89
62
- if v , err := f .ID .Int64 (); v != 123 {
63
- t .Errorf ("should parse id as number, got %d %v " , v , err )
90
+ if v , ok := f .ID .( float64 ); ! ok || v != 123 {
91
+ t .Errorf ("should parse id as number, got %T %f " , f . ID , v )
64
92
}
65
93
66
94
rawJSON = `
@@ -74,7 +102,7 @@ func TestUnmarshalFeatureID(t *testing.T) {
74
102
t .Fatalf ("should unmarshal feature without issue, err %v" , err )
75
103
}
76
104
77
- if v := f .ID .String (); v != "abcd" {
78
- t .Errorf ("should parse id as string, got %s" , v )
105
+ if v , ok := f .ID .( string ); ! ok || v != "abcd" {
106
+ t .Errorf ("should parse id as string, got %T %s" , f . ID , v )
79
107
}
80
108
}
0 commit comments