| 1 |
package soap |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"math" |
| 6 |
"net/url" |
| 7 |
"testing" |
| 8 |
"time" |
| 9 |
) |
| 10 |
|
| 11 |
type convTest interface { |
| 12 |
Marshal() (string, error) |
| 13 |
Unmarshal(string) (interface{}, error) |
| 14 |
Equal(result interface{}) bool |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
type duper interface { |
| 20 |
Dupe(tag string) []convTest |
| 21 |
} |
| 22 |
|
| 23 |
type testCase struct { |
| 24 |
value convTest |
| 25 |
str string |
| 26 |
wantMarshalErr bool |
| 27 |
wantUnmarshalErr bool |
| 28 |
noMarshal bool |
| 29 |
noUnMarshal bool |
| 30 |
tag string |
| 31 |
} |
| 32 |
|
| 33 |
type Ui1Test uint8 |
| 34 |
|
| 35 |
func (v Ui1Test) Marshal() (string, error) { |
| 36 |
return MarshalUi1(uint8(v)) |
| 37 |
} |
| 38 |
func (v Ui1Test) Unmarshal(s string) (interface{}, error) { |
| 39 |
return UnmarshalUi1(s) |
| 40 |
} |
| 41 |
func (v Ui1Test) Equal(result interface{}) bool { |
| 42 |
return uint8(v) == result.(uint8) |
| 43 |
} |
| 44 |
func (v Ui1Test) Dupe(tag string) []convTest { |
| 45 |
if tag == "dupe" { |
| 46 |
return []convTest{ |
| 47 |
Ui2Test(v), |
| 48 |
Ui4Test(v), |
| 49 |
} |
| 50 |
} |
| 51 |
return nil |
| 52 |
} |
| 53 |
|
| 54 |
type Ui2Test uint16 |
| 55 |
|
| 56 |
func (v Ui2Test) Marshal() (string, error) { |
| 57 |
return MarshalUi2(uint16(v)) |
| 58 |
} |
| 59 |
func (v Ui2Test) Unmarshal(s string) (interface{}, error) { |
| 60 |
return UnmarshalUi2(s) |
| 61 |
} |
| 62 |
func (v Ui2Test) Equal(result interface{}) bool { |
| 63 |
return uint16(v) == result.(uint16) |
| 64 |
} |
| 65 |
|
| 66 |
type Ui4Test uint32 |
| 67 |
|
| 68 |
func (v Ui4Test) Marshal() (string, error) { |
| 69 |
return MarshalUi4(uint32(v)) |
| 70 |
} |
| 71 |
func (v Ui4Test) Unmarshal(s string) (interface{}, error) { |
| 72 |
return UnmarshalUi4(s) |
| 73 |
} |
| 74 |
func (v Ui4Test) Equal(result interface{}) bool { |
| 75 |
return uint32(v) == result.(uint32) |
| 76 |
} |
| 77 |
|
| 78 |
type I1Test int8 |
| 79 |
|
| 80 |
func (v I1Test) Marshal() (string, error) { |
| 81 |
return MarshalI1(int8(v)) |
| 82 |
} |
| 83 |
func (v I1Test) Unmarshal(s string) (interface{}, error) { |
| 84 |
return UnmarshalI1(s) |
| 85 |
} |
| 86 |
func (v I1Test) Equal(result interface{}) bool { |
| 87 |
return int8(v) == result.(int8) |
| 88 |
} |
| 89 |
func (v I1Test) Dupe(tag string) []convTest { |
| 90 |
if tag == "dupe" { |
| 91 |
return []convTest{ |
| 92 |
I2Test(v), |
| 93 |
I4Test(v), |
| 94 |
} |
| 95 |
} |
| 96 |
return nil |
| 97 |
} |
| 98 |
|
| 99 |
type I2Test int16 |
| 100 |
|
| 101 |
func (v I2Test) Marshal() (string, error) { |
| 102 |
return MarshalI2(int16(v)) |
| 103 |
} |
| 104 |
func (v I2Test) Unmarshal(s string) (interface{}, error) { |
| 105 |
return UnmarshalI2(s) |
| 106 |
} |
| 107 |
func (v I2Test) Equal(result interface{}) bool { |
| 108 |
return int16(v) == result.(int16) |
| 109 |
} |
| 110 |
|
| 111 |
type I4Test int32 |
| 112 |
|
| 113 |
func (v I4Test) Marshal() (string, error) { |
| 114 |
return MarshalI4(int32(v)) |
| 115 |
} |
| 116 |
func (v I4Test) Unmarshal(s string) (interface{}, error) { |
| 117 |
return UnmarshalI4(s) |
| 118 |
} |
| 119 |
func (v I4Test) Equal(result interface{}) bool { |
| 120 |
return int32(v) == result.(int32) |
| 121 |
} |
| 122 |
|
| 123 |
type IntTest int64 |
| 124 |
|
| 125 |
func (v IntTest) Marshal() (string, error) { |
| 126 |
return MarshalInt(int64(v)) |
| 127 |
} |
| 128 |
func (v IntTest) Unmarshal(s string) (interface{}, error) { |
| 129 |
return UnmarshalInt(s) |
| 130 |
} |
| 131 |
func (v IntTest) Equal(result interface{}) bool { |
| 132 |
return int64(v) == result.(int64) |
| 133 |
} |
| 134 |
|
| 135 |
type Fixed14_4Test float64 |
| 136 |
|
| 137 |
func (v Fixed14_4Test) Marshal() (string, error) { |
| 138 |
return MarshalFixed14_4(float64(v)) |
| 139 |
} |
| 140 |
func (v Fixed14_4Test) Unmarshal(s string) (interface{}, error) { |
| 141 |
return UnmarshalFixed14_4(s) |
| 142 |
} |
| 143 |
func (v Fixed14_4Test) Equal(result interface{}) bool { |
| 144 |
return math.Abs(float64(v)-result.(float64)) < 0.001 |
| 145 |
} |
| 146 |
|
| 147 |
type CharTest rune |
| 148 |
|
| 149 |
func (v CharTest) Marshal() (string, error) { |
| 150 |
return MarshalChar(rune(v)) |
| 151 |
} |
| 152 |
func (v CharTest) Unmarshal(s string) (interface{}, error) { |
| 153 |
return UnmarshalChar(s) |
| 154 |
} |
| 155 |
func (v CharTest) Equal(result interface{}) bool { |
| 156 |
return rune(v) == result.(rune) |
| 157 |
} |
| 158 |
|
| 159 |
type DateTest struct{ time.Time } |
| 160 |
|
| 161 |
func (v DateTest) Marshal() (string, error) { |
| 162 |
return MarshalDate(time.Time(v.Time)) |
| 163 |
} |
| 164 |
func (v DateTest) Unmarshal(s string) (interface{}, error) { |
| 165 |
return UnmarshalDate(s) |
| 166 |
} |
| 167 |
func (v DateTest) Equal(result interface{}) bool { |
| 168 |
return v.Time.Equal(result.(time.Time)) |
| 169 |
} |
| 170 |
func (v DateTest) Dupe(tag string) []convTest { |
| 171 |
if tag != "no:dateTime" { |
| 172 |
return []convTest{DateTimeTest{v.Time}} |
| 173 |
} |
| 174 |
return nil |
| 175 |
} |
| 176 |
|
| 177 |
type TimeOfDayTest struct { |
| 178 |
TimeOfDay |
| 179 |
} |
| 180 |
|
| 181 |
func (v TimeOfDayTest) Marshal() (string, error) { |
| 182 |
return MarshalTimeOfDay(v.TimeOfDay) |
| 183 |
} |
| 184 |
func (v TimeOfDayTest) Unmarshal(s string) (interface{}, error) { |
| 185 |
return UnmarshalTimeOfDay(s) |
| 186 |
} |
| 187 |
func (v TimeOfDayTest) Equal(result interface{}) bool { |
| 188 |
return v.TimeOfDay == result.(TimeOfDay) |
| 189 |
} |
| 190 |
func (v TimeOfDayTest) Dupe(tag string) []convTest { |
| 191 |
if tag != "no:time.tz" { |
| 192 |
return []convTest{TimeOfDayTzTest{v.TimeOfDay}} |
| 193 |
} |
| 194 |
return nil |
| 195 |
} |
| 196 |
|
| 197 |
type TimeOfDayTzTest struct { |
| 198 |
TimeOfDay |
| 199 |
} |
| 200 |
|
| 201 |
func (v TimeOfDayTzTest) Marshal() (string, error) { |
| 202 |
return MarshalTimeOfDayTz(v.TimeOfDay) |
| 203 |
} |
| 204 |
func (v TimeOfDayTzTest) Unmarshal(s string) (interface{}, error) { |
| 205 |
return UnmarshalTimeOfDayTz(s) |
| 206 |
} |
| 207 |
func (v TimeOfDayTzTest) Equal(result interface{}) bool { |
| 208 |
return v.TimeOfDay == result.(TimeOfDay) |
| 209 |
} |
| 210 |
|
| 211 |
type DateTimeTest struct{ time.Time } |
| 212 |
|
| 213 |
func (v DateTimeTest) Marshal() (string, error) { |
| 214 |
return MarshalDateTime(time.Time(v.Time)) |
| 215 |
} |
| 216 |
func (v DateTimeTest) Unmarshal(s string) (interface{}, error) { |
| 217 |
return UnmarshalDateTime(s) |
| 218 |
} |
| 219 |
func (v DateTimeTest) Equal(result interface{}) bool { |
| 220 |
return v.Time.Equal(result.(time.Time)) |
| 221 |
} |
| 222 |
func (v DateTimeTest) Dupe(tag string) []convTest { |
| 223 |
if tag != "no:dateTime.tz" { |
| 224 |
return []convTest{DateTimeTzTest{v.Time}} |
| 225 |
} |
| 226 |
return nil |
| 227 |
} |
| 228 |
|
| 229 |
type DateTimeTzTest struct{ time.Time } |
| 230 |
|
| 231 |
func (v DateTimeTzTest) Marshal() (string, error) { |
| 232 |
return MarshalDateTimeTz(time.Time(v.Time)) |
| 233 |
} |
| 234 |
func (v DateTimeTzTest) Unmarshal(s string) (interface{}, error) { |
| 235 |
return UnmarshalDateTimeTz(s) |
| 236 |
} |
| 237 |
func (v DateTimeTzTest) Equal(result interface{}) bool { |
| 238 |
return v.Time.Equal(result.(time.Time)) |
| 239 |
} |
| 240 |
|
| 241 |
type BooleanTest bool |
| 242 |
|
| 243 |
func (v BooleanTest) Marshal() (string, error) { |
| 244 |
return MarshalBoolean(bool(v)) |
| 245 |
} |
| 246 |
func (v BooleanTest) Unmarshal(s string) (interface{}, error) { |
| 247 |
return UnmarshalBoolean(s) |
| 248 |
} |
| 249 |
func (v BooleanTest) Equal(result interface{}) bool { |
| 250 |
return bool(v) == result.(bool) |
| 251 |
} |
| 252 |
|
| 253 |
type BinBase64Test []byte |
| 254 |
|
| 255 |
func (v BinBase64Test) Marshal() (string, error) { |
| 256 |
return MarshalBinBase64([]byte(v)) |
| 257 |
} |
| 258 |
func (v BinBase64Test) Unmarshal(s string) (interface{}, error) { |
| 259 |
return UnmarshalBinBase64(s) |
| 260 |
} |
| 261 |
func (v BinBase64Test) Equal(result interface{}) bool { |
| 262 |
return bytes.Equal([]byte(v), result.([]byte)) |
| 263 |
} |
| 264 |
|
| 265 |
type BinHexTest []byte |
| 266 |
|
| 267 |
func (v BinHexTest) Marshal() (string, error) { |
| 268 |
return MarshalBinHex([]byte(v)) |
| 269 |
} |
| 270 |
func (v BinHexTest) Unmarshal(s string) (interface{}, error) { |
| 271 |
return UnmarshalBinHex(s) |
| 272 |
} |
| 273 |
func (v BinHexTest) Equal(result interface{}) bool { |
| 274 |
return bytes.Equal([]byte(v), result.([]byte)) |
| 275 |
} |
| 276 |
|
| 277 |
type URITest struct{ URL *url.URL } |
| 278 |
|
| 279 |
func (v URITest) Marshal() (string, error) { |
| 280 |
return MarshalURI(v.URL) |
| 281 |
} |
| 282 |
func (v URITest) Unmarshal(s string) (interface{}, error) { |
| 283 |
return UnmarshalURI(s) |
| 284 |
} |
| 285 |
func (v URITest) Equal(result interface{}) bool { |
| 286 |
return v.URL.String() == result.(*url.URL).String() |
| 287 |
} |
| 288 |
|
| 289 |
func Test(t *testing.T) { |
| 290 |
const time010203 time.Duration = (1*3600 + 2*60 + 3) * time.Second |
| 291 |
const time0102 time.Duration = (1*3600 + 2*60) * time.Second |
| 292 |
const time01 time.Duration = (1 * 3600) * time.Second |
| 293 |
const time235959 time.Duration = (23*3600 + 59*60 + 59) * time.Second |
| 294 |
|
| 295 |
|
| 296 |
localLoc = time.FixedZone("Fake/Local", 6*3600) |
| 297 |
defer func() { |
| 298 |
localLoc = time.Local |
| 299 |
}() |
| 300 |
|
| 301 |
tests := []testCase{ |
| 302 |
|
| 303 |
{str: "", value: Ui1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 304 |
{str: " ", value: Ui1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 305 |
{str: "abc", value: Ui1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 306 |
{str: "-1", value: Ui1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 307 |
{str: "0", value: Ui1Test(0), tag: "dupe"}, |
| 308 |
{str: "1", value: Ui1Test(1), tag: "dupe"}, |
| 309 |
{str: "255", value: Ui1Test(255), tag: "dupe"}, |
| 310 |
{str: "256", value: Ui1Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 311 |
|
| 312 |
|
| 313 |
{str: "65535", value: Ui2Test(65535)}, |
| 314 |
{str: "65536", value: Ui2Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 315 |
|
| 316 |
|
| 317 |
{str: "4294967295", value: Ui4Test(4294967295)}, |
| 318 |
{str: "4294967296", value: Ui4Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 319 |
|
| 320 |
|
| 321 |
{str: "", value: I1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 322 |
{str: " ", value: I1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 323 |
{str: "abc", value: I1Test(0), wantUnmarshalErr: true, noMarshal: true, tag: "dupe"}, |
| 324 |
{str: "0", value: I1Test(0), tag: "dupe"}, |
| 325 |
{str: "-1", value: I1Test(-1), tag: "dupe"}, |
| 326 |
{str: "127", value: I1Test(127), tag: "dupe"}, |
| 327 |
{str: "-128", value: I1Test(-128), tag: "dupe"}, |
| 328 |
{str: "128", value: I1Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 329 |
{str: "-129", value: I1Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 330 |
|
| 331 |
|
| 332 |
{str: "32767", value: I2Test(32767)}, |
| 333 |
{str: "-32768", value: I2Test(-32768)}, |
| 334 |
{str: "32768", value: I2Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 335 |
{str: "-32769", value: I2Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 336 |
|
| 337 |
|
| 338 |
{str: "2147483647", value: I4Test(2147483647)}, |
| 339 |
{str: "-2147483648", value: I4Test(-2147483648)}, |
| 340 |
{str: "2147483648", value: I4Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 341 |
{str: "-2147483649", value: I4Test(0), wantUnmarshalErr: true, noMarshal: true}, |
| 342 |
|
| 343 |
|
| 344 |
{str: "9223372036854775807", value: IntTest(9223372036854775807)}, |
| 345 |
{str: "-9223372036854775808", value: IntTest(-9223372036854775808)}, |
| 346 |
{str: "9223372036854775808", value: IntTest(0), wantUnmarshalErr: true, noMarshal: true}, |
| 347 |
{str: "-9223372036854775809", value: IntTest(0), wantUnmarshalErr: true, noMarshal: true}, |
| 348 |
|
| 349 |
|
| 350 |
{str: "0.0000", value: Fixed14_4Test(0)}, |
| 351 |
{str: "1.0000", value: Fixed14_4Test(1)}, |
| 352 |
{str: "1.2346", value: Fixed14_4Test(1.23456)}, |
| 353 |
{str: "-1.0000", value: Fixed14_4Test(-1)}, |
| 354 |
{str: "-1.2346", value: Fixed14_4Test(-1.23456)}, |
| 355 |
{str: "10000000000000.0000", value: Fixed14_4Test(1e13)}, |
| 356 |
{str: "100000000000000.0000", value: Fixed14_4Test(1e14), wantMarshalErr: true, wantUnmarshalErr: true}, |
| 357 |
{str: "-10000000000000.0000", value: Fixed14_4Test(-1e13)}, |
| 358 |
{str: "-100000000000000.0000", value: Fixed14_4Test(-1e14), wantMarshalErr: true, wantUnmarshalErr: true}, |
| 359 |
|
| 360 |
|
| 361 |
{str: "a", value: CharTest('a')}, |
| 362 |
{str: "z", value: CharTest('z')}, |
| 363 |
{str: "\u1234", value: CharTest(0x1234)}, |
| 364 |
{str: "aa", value: CharTest(0), wantMarshalErr: true, wantUnmarshalErr: true}, |
| 365 |
{str: "", value: CharTest(0), wantMarshalErr: true, wantUnmarshalErr: true}, |
| 366 |
|
| 367 |
|
| 368 |
{str: "2013-10-08", value: DateTest{time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc)}, tag: "no:dateTime"}, |
| 369 |
{str: "20131008", value: DateTest{time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc)}, noMarshal: true, tag: "no:dateTime"}, |
| 370 |
{str: "2013-10-08T10:30:50", value: DateTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime"}, |
| 371 |
{str: "2013-10-08T10:30:50Z", value: DateTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime"}, |
| 372 |
{str: "", value: DateTest{}, wantMarshalErr: true, wantUnmarshalErr: true, noMarshal: true}, |
| 373 |
{str: "-1", value: DateTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 374 |
|
| 375 |
|
| 376 |
{str: "00:00:00", value: TimeOfDayTest{TimeOfDay{FromMidnight: 0}}}, |
| 377 |
{str: "000000", value: TimeOfDayTest{TimeOfDay{FromMidnight: 0}}, noMarshal: true}, |
| 378 |
{str: "24:00:00", value: TimeOfDayTest{TimeOfDay{FromMidnight: 24 * time.Hour}}, noMarshal: true}, |
| 379 |
{str: "24:01:00", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 380 |
{str: "24:00:01", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 381 |
{str: "25:00:00", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 382 |
{str: "00:60:00", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 383 |
{str: "00:00:60", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 384 |
{str: "01:02:03", value: TimeOfDayTest{TimeOfDay{FromMidnight: time010203}}}, |
| 385 |
{str: "010203", value: TimeOfDayTest{TimeOfDay{FromMidnight: time010203}}, noMarshal: true}, |
| 386 |
{str: "23:59:59", value: TimeOfDayTest{TimeOfDay{FromMidnight: time235959}}}, |
| 387 |
{str: "235959", value: TimeOfDayTest{TimeOfDay{FromMidnight: time235959}}, noMarshal: true}, |
| 388 |
{str: "01:02", value: TimeOfDayTest{TimeOfDay{FromMidnight: time0102}}, noMarshal: true}, |
| 389 |
{str: "0102", value: TimeOfDayTest{TimeOfDay{FromMidnight: time0102}}, noMarshal: true}, |
| 390 |
{str: "01", value: TimeOfDayTest{TimeOfDay{FromMidnight: time01}}, noMarshal: true}, |
| 391 |
{str: "foo 01:02:03", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 392 |
{str: "foo\n01:02:03", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 393 |
{str: "01:02:03 foo", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 394 |
{str: "01:02:03\nfoo", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 395 |
{str: "01:02:03Z", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 396 |
{str: "01:02:03+01", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 397 |
{str: "01:02:03+01:23", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 398 |
{str: "01:02:03+0123", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 399 |
{str: "01:02:03-01", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 400 |
{str: "01:02:03-01:23", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 401 |
{str: "01:02:03-0123", value: TimeOfDayTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:time.tz"}, |
| 402 |
|
| 403 |
|
| 404 |
{str: "24:00:01", value: TimeOfDayTzTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 405 |
{str: "01Z", value: TimeOfDayTzTest{TimeOfDay{time01, true, 0}}, noMarshal: true}, |
| 406 |
{str: "01:02:03Z", value: TimeOfDayTzTest{TimeOfDay{time010203, true, 0}}}, |
| 407 |
{str: "01+01", value: TimeOfDayTzTest{TimeOfDay{time01, true, 3600}}, noMarshal: true}, |
| 408 |
{str: "01:02:03+01", value: TimeOfDayTzTest{TimeOfDay{time010203, true, 3600}}, noMarshal: true}, |
| 409 |
{str: "01:02:03+01:23", value: TimeOfDayTzTest{TimeOfDay{time010203, true, 3600 + 23*60}}}, |
| 410 |
{str: "01:02:03+0123", value: TimeOfDayTzTest{TimeOfDay{time010203, true, 3600 + 23*60}}, noMarshal: true}, |
| 411 |
{str: "01:02:03-01", value: TimeOfDayTzTest{TimeOfDay{time010203, true, -3600}}, noMarshal: true}, |
| 412 |
{str: "01:02:03-01:23", value: TimeOfDayTzTest{TimeOfDay{time010203, true, -(3600 + 23*60)}}}, |
| 413 |
{str: "01:02:03-0123", value: TimeOfDayTzTest{TimeOfDay{time010203, true, -(3600 + 23*60)}}, noMarshal: true}, |
| 414 |
|
| 415 |
|
| 416 |
{str: "2013-10-08T00:00:00", value: DateTimeTest{time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc)}, tag: "no:dateTime.tz"}, |
| 417 |
{str: "20131008", value: DateTimeTest{time.Date(2013, 10, 8, 0, 0, 0, 0, localLoc)}, noMarshal: true}, |
| 418 |
{str: "2013-10-08T10:30:50", value: DateTimeTest{time.Date(2013, 10, 8, 10, 30, 50, 0, localLoc)}, tag: "no:dateTime.tz"}, |
| 419 |
{str: "2013-10-08T10:30:50T", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true}, |
| 420 |
{str: "2013-10-08T10:30:50+01", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime.tz"}, |
| 421 |
{str: "2013-10-08T10:30:50+01:23", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime.tz"}, |
| 422 |
{str: "2013-10-08T10:30:50+0123", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime.tz"}, |
| 423 |
{str: "2013-10-08T10:30:50-01", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime.tz"}, |
| 424 |
{str: "2013-10-08T10:30:50-01:23", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime.tz"}, |
| 425 |
{str: "2013-10-08T10:30:50-0123", value: DateTimeTest{}, wantUnmarshalErr: true, noMarshal: true, tag: "no:dateTime.tz"}, |
| 426 |
|
| 427 |
|
| 428 |
{str: "2013-10-08T10:30:50", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, localLoc)}, noMarshal: true}, |
| 429 |
{str: "2013-10-08T10:30:50+01", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, time.FixedZone("+01:00", 3600))}, noMarshal: true}, |
| 430 |
{str: "2013-10-08T10:30:50+01:23", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, time.FixedZone("+01:23", 3600+23*60))}}, |
| 431 |
{str: "2013-10-08T10:30:50+0123", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, time.FixedZone("+01:23", 3600+23*60))}, noMarshal: true}, |
| 432 |
{str: "2013-10-08T10:30:50-01", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, time.FixedZone("-01:00", -3600))}, noMarshal: true}, |
| 433 |
{str: "2013-10-08T10:30:50-01:23", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, time.FixedZone("-01:23", -(3600+23*60)))}}, |
| 434 |
{str: "2013-10-08T10:30:50-0123", value: DateTimeTzTest{time.Date(2013, 10, 8, 10, 30, 50, 0, time.FixedZone("-01:23", -(3600+23*60)))}, noMarshal: true}, |
| 435 |
|
| 436 |
|
| 437 |
{str: "0", value: BooleanTest(false)}, |
| 438 |
{str: "1", value: BooleanTest(true)}, |
| 439 |
{str: "false", value: BooleanTest(false), noMarshal: true}, |
| 440 |
{str: "true", value: BooleanTest(true), noMarshal: true}, |
| 441 |
{str: "no", value: BooleanTest(false), noMarshal: true}, |
| 442 |
{str: "yes", value: BooleanTest(true), noMarshal: true}, |
| 443 |
{str: "", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true}, |
| 444 |
{str: "other", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true}, |
| 445 |
{str: "2", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true}, |
| 446 |
{str: "-1", value: BooleanTest(false), noMarshal: true, wantUnmarshalErr: true}, |
| 447 |
|
| 448 |
|
| 449 |
{str: "", value: BinBase64Test{}}, |
| 450 |
{str: "YQ==", value: BinBase64Test("a")}, |
| 451 |
{str: "TG9uZ2VyIFN0cmluZy4=", value: BinBase64Test("Longer String.")}, |
| 452 |
{str: "TG9uZ2VyIEFsaWduZWQu", value: BinBase64Test("Longer Aligned.")}, |
| 453 |
|
| 454 |
|
| 455 |
{str: "", value: BinHexTest{}}, |
| 456 |
{str: "61", value: BinHexTest("a")}, |
| 457 |
{str: "4c6f6e67657220537472696e672e", value: BinHexTest("Longer String.")}, |
| 458 |
{str: "4C6F6E67657220537472696E672E", value: BinHexTest("Longer String."), noMarshal: true}, |
| 459 |
|
| 460 |
|
| 461 |
{str: "http://example.com/path", value: URITest{&url.URL{Scheme: "http", Host: "example.com", Path: "/path"}}}, |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
var extras []testCase |
| 466 |
for i := range tests { |
| 467 |
if duper, ok := tests[i].value.(duper); ok { |
| 468 |
dupes := duper.Dupe(tests[i].tag) |
| 469 |
for _, duped := range dupes { |
| 470 |
dupedCase := testCase(tests[i]) |
| 471 |
dupedCase.value = duped |
| 472 |
extras = append(extras, dupedCase) |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
tests = append(tests, extras...) |
| 477 |
|
| 478 |
for _, test := range tests { |
| 479 |
if test.noMarshal { |
| 480 |
} else if resultStr, err := test.value.Marshal(); err != nil && !test.wantMarshalErr { |
| 481 |
t.Errorf("For %T marshal %v, want %q, got error: %v", test.value, test.value, test.str, err) |
| 482 |
} else if err == nil && test.wantMarshalErr { |
| 483 |
t.Errorf("For %T marshal %v, want error, got %q", test.value, test.value, resultStr) |
| 484 |
} else if err == nil && resultStr != test.str { |
| 485 |
t.Errorf("For %T marshal %v, want %q, got %q", test.value, test.value, test.str, resultStr) |
| 486 |
} |
| 487 |
|
| 488 |
if test.noUnMarshal { |
| 489 |
} else if resultValue, err := test.value.Unmarshal(test.str); err != nil && !test.wantUnmarshalErr { |
| 490 |
t.Errorf("For %T unmarshal %q, want %v, got error: %v", test.value, test.str, test.value, err) |
| 491 |
} else if err == nil && test.wantUnmarshalErr { |
| 492 |
t.Errorf("For %T unmarshal %q, want error, got %v", test.value, test.str, resultValue) |
| 493 |
} else if err == nil && !test.value.Equal(resultValue) { |
| 494 |
t.Errorf("For %T unmarshal %q, want %v, got %v", test.value, test.str, test.value, resultValue) |
| 495 |
} |
| 496 |
} |
| 497 |
} |