| 209 | } |
| 210 | |
| 211 | func TestStringJSON(t *testing.T) { |
| 212 | input := []struct { |
| 213 | plain string |
| 214 | value String |
| 215 | }{ |
| 216 | { |
| 217 | plain: `[123.456,"test"]`, |
| 218 | value: String{ |
| 219 | Timestamp: 123456, |
| 220 | Value: "test", |
| 221 | }, |
| 222 | }, |
| 223 | { |
| 224 | plain: `[123123.456,"台北"]`, |
| 225 | value: String{ |
| 226 | Timestamp: 123123456, |
| 227 | Value: "台北", |
| 228 | }, |
| 229 | }, |
| 230 | } |
| 231 | |
| 232 | for _, test := range input { |
| 233 | b, err := json.Marshal(test.value) |
| 234 | if err != nil { |
| 235 | t.Error(err) |
| 236 | continue |
| 237 | } |
| 238 | |
| 239 | if string(b) != test.plain { |
| 240 | t.Errorf("encoding error: expected %q, got %q", test.plain, b) |
| 241 | continue |
| 242 | } |
| 243 | |
| 244 | var sv String |
| 245 | err = json.Unmarshal(b, &sv) |
| 246 | if err != nil { |
| 247 | t.Error(err) |
| 248 | continue |
| 249 | } |
| 250 | |
| 251 | if sv != test.value { |
| 252 | t.Errorf("decoding error: expected %v, got %v", test.value, sv) |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | func TestVectorSort(t *testing.T) { |
| 258 | input := Vector{ |