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