Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 5 | package protojson_test |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 6 | |
| 7 | import ( |
Damien Neil | bc310b5 | 2019-04-11 11:46:55 -0700 | [diff] [blame] | 8 | "bytes" |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 9 | "math" |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 10 | "testing" |
| 11 | |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 12 | "github.com/google/go-cmp/cmp" |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 13 | "google.golang.org/protobuf/encoding/protojson" |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 14 | "google.golang.org/protobuf/internal/encoding/pack" |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 15 | pimpl "google.golang.org/protobuf/internal/impl" |
| 16 | "google.golang.org/protobuf/internal/scalar" |
| 17 | "google.golang.org/protobuf/proto" |
| 18 | preg "google.golang.org/protobuf/reflect/protoregistry" |
| 19 | "google.golang.org/protobuf/runtime/protoiface" |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 20 | |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 21 | "google.golang.org/protobuf/encoding/testprotos/pb2" |
| 22 | "google.golang.org/protobuf/encoding/testprotos/pb3" |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 23 | "google.golang.org/protobuf/types/known/anypb" |
| 24 | "google.golang.org/protobuf/types/known/durationpb" |
| 25 | "google.golang.org/protobuf/types/known/emptypb" |
| 26 | "google.golang.org/protobuf/types/known/fieldmaskpb" |
| 27 | "google.golang.org/protobuf/types/known/structpb" |
| 28 | "google.golang.org/protobuf/types/known/timestamppb" |
| 29 | "google.golang.org/protobuf/types/known/wrapperspb" |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 30 | ) |
| 31 | |
Joe Tsai | 378c132 | 2019-04-25 23:48:08 -0700 | [diff] [blame] | 32 | // TODO: Replace this with proto.SetExtension. |
Joe Tsai | 4fddeba | 2019-03-20 18:29:32 -0700 | [diff] [blame] | 33 | func setExtension(m proto.Message, xd *protoiface.ExtensionDescV1, val interface{}) { |
Joe Tsai | 378c132 | 2019-04-25 23:48:08 -0700 | [diff] [blame] | 34 | m.ProtoReflect().Set(xd.Type, xd.Type.ValueOf(val)) |
Herbie Ong | f83d5bb | 2019-03-14 00:01:27 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 37 | func TestMarshal(t *testing.T) { |
| 38 | tests := []struct { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 39 | desc string |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 40 | mo protojson.MarshalOptions |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 41 | input proto.Message |
| 42 | want string |
| 43 | wantErr bool // TODO: Verify error message substring. |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 44 | }{{ |
| 45 | desc: "proto2 optional scalars not set", |
| 46 | input: &pb2.Scalars{}, |
| 47 | want: "{}", |
| 48 | }, { |
| 49 | desc: "proto3 scalars not set", |
| 50 | input: &pb3.Scalars{}, |
| 51 | want: "{}", |
| 52 | }, { |
| 53 | desc: "proto2 optional scalars set to zero values", |
| 54 | input: &pb2.Scalars{ |
| 55 | OptBool: scalar.Bool(false), |
| 56 | OptInt32: scalar.Int32(0), |
| 57 | OptInt64: scalar.Int64(0), |
| 58 | OptUint32: scalar.Uint32(0), |
| 59 | OptUint64: scalar.Uint64(0), |
| 60 | OptSint32: scalar.Int32(0), |
| 61 | OptSint64: scalar.Int64(0), |
| 62 | OptFixed32: scalar.Uint32(0), |
| 63 | OptFixed64: scalar.Uint64(0), |
| 64 | OptSfixed32: scalar.Int32(0), |
| 65 | OptSfixed64: scalar.Int64(0), |
| 66 | OptFloat: scalar.Float32(0), |
| 67 | OptDouble: scalar.Float64(0), |
| 68 | OptBytes: []byte{}, |
| 69 | OptString: scalar.String(""), |
| 70 | }, |
| 71 | want: `{ |
| 72 | "optBool": false, |
| 73 | "optInt32": 0, |
| 74 | "optInt64": "0", |
| 75 | "optUint32": 0, |
| 76 | "optUint64": "0", |
| 77 | "optSint32": 0, |
| 78 | "optSint64": "0", |
| 79 | "optFixed32": 0, |
| 80 | "optFixed64": "0", |
| 81 | "optSfixed32": 0, |
| 82 | "optSfixed64": "0", |
| 83 | "optFloat": 0, |
| 84 | "optDouble": 0, |
| 85 | "optBytes": "", |
| 86 | "optString": "" |
| 87 | }`, |
| 88 | }, { |
| 89 | desc: "proto2 optional scalars set to some values", |
| 90 | input: &pb2.Scalars{ |
| 91 | OptBool: scalar.Bool(true), |
| 92 | OptInt32: scalar.Int32(0xff), |
| 93 | OptInt64: scalar.Int64(0xdeadbeef), |
| 94 | OptUint32: scalar.Uint32(47), |
| 95 | OptUint64: scalar.Uint64(0xdeadbeef), |
| 96 | OptSint32: scalar.Int32(-1001), |
| 97 | OptSint64: scalar.Int64(-0xffff), |
| 98 | OptFixed64: scalar.Uint64(64), |
| 99 | OptSfixed32: scalar.Int32(-32), |
| 100 | OptFloat: scalar.Float32(1.02), |
| 101 | OptDouble: scalar.Float64(1.234), |
Herbie Ong | 87608a7 | 2019-03-06 14:32:24 -0800 | [diff] [blame] | 102 | OptBytes: []byte("谷歌"), |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 103 | OptString: scalar.String("谷歌"), |
| 104 | }, |
| 105 | want: `{ |
| 106 | "optBool": true, |
| 107 | "optInt32": 255, |
| 108 | "optInt64": "3735928559", |
| 109 | "optUint32": 47, |
| 110 | "optUint64": "3735928559", |
| 111 | "optSint32": -1001, |
| 112 | "optSint64": "-65535", |
| 113 | "optFixed64": "64", |
| 114 | "optSfixed32": -32, |
| 115 | "optFloat": 1.02, |
| 116 | "optDouble": 1.234, |
| 117 | "optBytes": "6LC35q2M", |
| 118 | "optString": "谷歌" |
| 119 | }`, |
| 120 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 121 | desc: "string", |
| 122 | input: &pb3.Scalars{ |
| 123 | SString: "谷歌", |
| 124 | }, |
| 125 | want: `{ |
| 126 | "sString": "谷歌" |
| 127 | }`, |
| 128 | }, { |
| 129 | desc: "string with invalid UTF8", |
| 130 | input: &pb3.Scalars{ |
| 131 | SString: "abc\xff", |
| 132 | }, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 133 | wantErr: true, |
| 134 | }, { |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 135 | desc: "float nan", |
| 136 | input: &pb3.Scalars{ |
| 137 | SFloat: float32(math.NaN()), |
| 138 | }, |
| 139 | want: `{ |
| 140 | "sFloat": "NaN" |
| 141 | }`, |
| 142 | }, { |
| 143 | desc: "float positive infinity", |
| 144 | input: &pb3.Scalars{ |
| 145 | SFloat: float32(math.Inf(1)), |
| 146 | }, |
| 147 | want: `{ |
| 148 | "sFloat": "Infinity" |
| 149 | }`, |
| 150 | }, { |
| 151 | desc: "float negative infinity", |
| 152 | input: &pb3.Scalars{ |
| 153 | SFloat: float32(math.Inf(-1)), |
| 154 | }, |
| 155 | want: `{ |
| 156 | "sFloat": "-Infinity" |
| 157 | }`, |
| 158 | }, { |
| 159 | desc: "double nan", |
| 160 | input: &pb3.Scalars{ |
| 161 | SDouble: math.NaN(), |
| 162 | }, |
| 163 | want: `{ |
| 164 | "sDouble": "NaN" |
| 165 | }`, |
| 166 | }, { |
| 167 | desc: "double positive infinity", |
| 168 | input: &pb3.Scalars{ |
| 169 | SDouble: math.Inf(1), |
| 170 | }, |
| 171 | want: `{ |
| 172 | "sDouble": "Infinity" |
| 173 | }`, |
| 174 | }, { |
| 175 | desc: "double negative infinity", |
| 176 | input: &pb3.Scalars{ |
| 177 | SDouble: math.Inf(-1), |
| 178 | }, |
| 179 | want: `{ |
| 180 | "sDouble": "-Infinity" |
| 181 | }`, |
| 182 | }, { |
| 183 | desc: "proto2 enum not set", |
| 184 | input: &pb2.Enums{}, |
| 185 | want: "{}", |
| 186 | }, { |
| 187 | desc: "proto2 enum set to zero value", |
| 188 | input: &pb2.Enums{ |
Joe Tsai | 6dc168e | 2019-07-09 23:11:13 -0700 | [diff] [blame^] | 189 | OptEnum: pb2.Enum(0).Enum(), |
| 190 | OptNestedEnum: pb2.Enums_NestedEnum(0).Enum(), |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 191 | }, |
| 192 | want: `{ |
| 193 | "optEnum": 0, |
| 194 | "optNestedEnum": 0 |
| 195 | }`, |
| 196 | }, { |
| 197 | desc: "proto2 enum", |
| 198 | input: &pb2.Enums{ |
| 199 | OptEnum: pb2.Enum_ONE.Enum(), |
| 200 | OptNestedEnum: pb2.Enums_UNO.Enum(), |
| 201 | }, |
| 202 | want: `{ |
| 203 | "optEnum": "ONE", |
| 204 | "optNestedEnum": "UNO" |
| 205 | }`, |
| 206 | }, { |
| 207 | desc: "proto2 enum set to numeric values", |
| 208 | input: &pb2.Enums{ |
Joe Tsai | 6dc168e | 2019-07-09 23:11:13 -0700 | [diff] [blame^] | 209 | OptEnum: pb2.Enum(2).Enum(), |
| 210 | OptNestedEnum: pb2.Enums_NestedEnum(2).Enum(), |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 211 | }, |
| 212 | want: `{ |
| 213 | "optEnum": "TWO", |
| 214 | "optNestedEnum": "DOS" |
| 215 | }`, |
| 216 | }, { |
| 217 | desc: "proto2 enum set to unnamed numeric values", |
| 218 | input: &pb2.Enums{ |
Joe Tsai | 6dc168e | 2019-07-09 23:11:13 -0700 | [diff] [blame^] | 219 | OptEnum: pb2.Enum(101).Enum(), |
| 220 | OptNestedEnum: pb2.Enums_NestedEnum(-101).Enum(), |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 221 | }, |
| 222 | want: `{ |
| 223 | "optEnum": 101, |
| 224 | "optNestedEnum": -101 |
| 225 | }`, |
| 226 | }, { |
| 227 | desc: "proto3 enum not set", |
| 228 | input: &pb3.Enums{}, |
| 229 | want: "{}", |
| 230 | }, { |
| 231 | desc: "proto3 enum set to zero value", |
| 232 | input: &pb3.Enums{ |
| 233 | SEnum: pb3.Enum_ZERO, |
| 234 | SNestedEnum: pb3.Enums_CERO, |
| 235 | }, |
| 236 | want: "{}", |
| 237 | }, { |
| 238 | desc: "proto3 enum", |
| 239 | input: &pb3.Enums{ |
| 240 | SEnum: pb3.Enum_ONE, |
| 241 | SNestedEnum: pb3.Enums_UNO, |
| 242 | }, |
| 243 | want: `{ |
| 244 | "sEnum": "ONE", |
| 245 | "sNestedEnum": "UNO" |
| 246 | }`, |
| 247 | }, { |
| 248 | desc: "proto3 enum set to numeric values", |
| 249 | input: &pb3.Enums{ |
| 250 | SEnum: 2, |
| 251 | SNestedEnum: 2, |
| 252 | }, |
| 253 | want: `{ |
| 254 | "sEnum": "TWO", |
| 255 | "sNestedEnum": "DOS" |
| 256 | }`, |
| 257 | }, { |
| 258 | desc: "proto3 enum set to unnamed numeric values", |
| 259 | input: &pb3.Enums{ |
| 260 | SEnum: -47, |
| 261 | SNestedEnum: 47, |
| 262 | }, |
| 263 | want: `{ |
| 264 | "sEnum": -47, |
| 265 | "sNestedEnum": 47 |
| 266 | }`, |
| 267 | }, { |
| 268 | desc: "proto2 nested message not set", |
| 269 | input: &pb2.Nests{}, |
| 270 | want: "{}", |
| 271 | }, { |
| 272 | desc: "proto2 nested message set to empty", |
| 273 | input: &pb2.Nests{ |
| 274 | OptNested: &pb2.Nested{}, |
| 275 | Optgroup: &pb2.Nests_OptGroup{}, |
| 276 | }, |
| 277 | want: `{ |
| 278 | "optNested": {}, |
| 279 | "optgroup": {} |
| 280 | }`, |
| 281 | }, { |
| 282 | desc: "proto2 nested messages", |
| 283 | input: &pb2.Nests{ |
| 284 | OptNested: &pb2.Nested{ |
| 285 | OptString: scalar.String("nested message"), |
| 286 | OptNested: &pb2.Nested{ |
| 287 | OptString: scalar.String("another nested message"), |
| 288 | }, |
| 289 | }, |
| 290 | }, |
| 291 | want: `{ |
| 292 | "optNested": { |
| 293 | "optString": "nested message", |
| 294 | "optNested": { |
| 295 | "optString": "another nested message" |
| 296 | } |
| 297 | } |
| 298 | }`, |
| 299 | }, { |
| 300 | desc: "proto2 groups", |
| 301 | input: &pb2.Nests{ |
| 302 | Optgroup: &pb2.Nests_OptGroup{ |
| 303 | OptString: scalar.String("inside a group"), |
| 304 | OptNested: &pb2.Nested{ |
| 305 | OptString: scalar.String("nested message inside a group"), |
| 306 | }, |
| 307 | Optnestedgroup: &pb2.Nests_OptGroup_OptNestedGroup{ |
| 308 | OptFixed32: scalar.Uint32(47), |
| 309 | }, |
| 310 | }, |
| 311 | }, |
| 312 | want: `{ |
| 313 | "optgroup": { |
| 314 | "optString": "inside a group", |
| 315 | "optNested": { |
| 316 | "optString": "nested message inside a group" |
| 317 | }, |
| 318 | "optnestedgroup": { |
| 319 | "optFixed32": 47 |
| 320 | } |
| 321 | } |
| 322 | }`, |
| 323 | }, { |
| 324 | desc: "proto3 nested message not set", |
| 325 | input: &pb3.Nests{}, |
| 326 | want: "{}", |
| 327 | }, { |
| 328 | desc: "proto3 nested message set to empty", |
| 329 | input: &pb3.Nests{ |
| 330 | SNested: &pb3.Nested{}, |
| 331 | }, |
| 332 | want: `{ |
| 333 | "sNested": {} |
| 334 | }`, |
| 335 | }, { |
| 336 | desc: "proto3 nested message", |
| 337 | input: &pb3.Nests{ |
| 338 | SNested: &pb3.Nested{ |
| 339 | SString: "nested message", |
| 340 | SNested: &pb3.Nested{ |
| 341 | SString: "another nested message", |
| 342 | }, |
| 343 | }, |
| 344 | }, |
| 345 | want: `{ |
| 346 | "sNested": { |
| 347 | "sString": "nested message", |
| 348 | "sNested": { |
| 349 | "sString": "another nested message" |
| 350 | } |
| 351 | } |
| 352 | }`, |
| 353 | }, { |
| 354 | desc: "oneof not set", |
| 355 | input: &pb3.Oneofs{}, |
| 356 | want: "{}", |
| 357 | }, { |
| 358 | desc: "oneof set to empty string", |
| 359 | input: &pb3.Oneofs{ |
| 360 | Union: &pb3.Oneofs_OneofString{}, |
| 361 | }, |
| 362 | want: `{ |
| 363 | "oneofString": "" |
| 364 | }`, |
| 365 | }, { |
| 366 | desc: "oneof set to string", |
| 367 | input: &pb3.Oneofs{ |
| 368 | Union: &pb3.Oneofs_OneofString{ |
| 369 | OneofString: "hello", |
| 370 | }, |
| 371 | }, |
| 372 | want: `{ |
| 373 | "oneofString": "hello" |
| 374 | }`, |
| 375 | }, { |
| 376 | desc: "oneof set to enum", |
| 377 | input: &pb3.Oneofs{ |
| 378 | Union: &pb3.Oneofs_OneofEnum{ |
| 379 | OneofEnum: pb3.Enum_ZERO, |
| 380 | }, |
| 381 | }, |
| 382 | want: `{ |
| 383 | "oneofEnum": "ZERO" |
| 384 | }`, |
| 385 | }, { |
| 386 | desc: "oneof set to empty message", |
| 387 | input: &pb3.Oneofs{ |
| 388 | Union: &pb3.Oneofs_OneofNested{ |
| 389 | OneofNested: &pb3.Nested{}, |
| 390 | }, |
| 391 | }, |
| 392 | want: `{ |
| 393 | "oneofNested": {} |
| 394 | }`, |
| 395 | }, { |
| 396 | desc: "oneof set to message", |
| 397 | input: &pb3.Oneofs{ |
| 398 | Union: &pb3.Oneofs_OneofNested{ |
| 399 | OneofNested: &pb3.Nested{ |
| 400 | SString: "nested message", |
| 401 | }, |
| 402 | }, |
| 403 | }, |
| 404 | want: `{ |
| 405 | "oneofNested": { |
| 406 | "sString": "nested message" |
| 407 | } |
| 408 | }`, |
| 409 | }, { |
| 410 | desc: "repeated fields not set", |
| 411 | input: &pb2.Repeats{}, |
| 412 | want: "{}", |
| 413 | }, { |
| 414 | desc: "repeated fields set to empty slices", |
| 415 | input: &pb2.Repeats{ |
| 416 | RptBool: []bool{}, |
| 417 | RptInt32: []int32{}, |
| 418 | RptInt64: []int64{}, |
| 419 | RptUint32: []uint32{}, |
| 420 | RptUint64: []uint64{}, |
| 421 | RptFloat: []float32{}, |
| 422 | RptDouble: []float64{}, |
| 423 | RptBytes: [][]byte{}, |
| 424 | }, |
| 425 | want: "{}", |
| 426 | }, { |
| 427 | desc: "repeated fields set to some values", |
| 428 | input: &pb2.Repeats{ |
| 429 | RptBool: []bool{true, false, true, true}, |
| 430 | RptInt32: []int32{1, 6, 0, 0}, |
| 431 | RptInt64: []int64{-64, 47}, |
| 432 | RptUint32: []uint32{0xff, 0xffff}, |
| 433 | RptUint64: []uint64{0xdeadbeef}, |
| 434 | RptFloat: []float32{float32(math.NaN()), float32(math.Inf(1)), float32(math.Inf(-1)), 1.034}, |
| 435 | RptDouble: []float64{math.NaN(), math.Inf(1), math.Inf(-1), 1.23e-308}, |
| 436 | RptString: []string{"hello", "世界"}, |
| 437 | RptBytes: [][]byte{ |
| 438 | []byte("hello"), |
| 439 | []byte("\xe4\xb8\x96\xe7\x95\x8c"), |
| 440 | }, |
| 441 | }, |
| 442 | want: `{ |
| 443 | "rptBool": [ |
| 444 | true, |
| 445 | false, |
| 446 | true, |
| 447 | true |
| 448 | ], |
| 449 | "rptInt32": [ |
| 450 | 1, |
| 451 | 6, |
| 452 | 0, |
| 453 | 0 |
| 454 | ], |
| 455 | "rptInt64": [ |
| 456 | "-64", |
| 457 | "47" |
| 458 | ], |
| 459 | "rptUint32": [ |
| 460 | 255, |
| 461 | 65535 |
| 462 | ], |
| 463 | "rptUint64": [ |
| 464 | "3735928559" |
| 465 | ], |
| 466 | "rptFloat": [ |
| 467 | "NaN", |
| 468 | "Infinity", |
| 469 | "-Infinity", |
| 470 | 1.034 |
| 471 | ], |
| 472 | "rptDouble": [ |
| 473 | "NaN", |
| 474 | "Infinity", |
| 475 | "-Infinity", |
| 476 | 1.23e-308 |
| 477 | ], |
| 478 | "rptString": [ |
| 479 | "hello", |
| 480 | "世界" |
| 481 | ], |
| 482 | "rptBytes": [ |
| 483 | "aGVsbG8=", |
| 484 | "5LiW55WM" |
| 485 | ] |
| 486 | }`, |
| 487 | }, { |
| 488 | desc: "repeated enums", |
| 489 | input: &pb2.Enums{ |
| 490 | RptEnum: []pb2.Enum{pb2.Enum_ONE, 2, pb2.Enum_TEN, 42}, |
| 491 | RptNestedEnum: []pb2.Enums_NestedEnum{2, 47, 10}, |
| 492 | }, |
| 493 | want: `{ |
| 494 | "rptEnum": [ |
| 495 | "ONE", |
| 496 | "TWO", |
| 497 | "TEN", |
| 498 | 42 |
| 499 | ], |
| 500 | "rptNestedEnum": [ |
| 501 | "DOS", |
| 502 | 47, |
| 503 | "DIEZ" |
| 504 | ] |
| 505 | }`, |
| 506 | }, { |
| 507 | desc: "repeated messages set to empty", |
| 508 | input: &pb2.Nests{ |
| 509 | RptNested: []*pb2.Nested{}, |
| 510 | Rptgroup: []*pb2.Nests_RptGroup{}, |
| 511 | }, |
| 512 | want: "{}", |
| 513 | }, { |
| 514 | desc: "repeated messages", |
| 515 | input: &pb2.Nests{ |
| 516 | RptNested: []*pb2.Nested{ |
| 517 | { |
| 518 | OptString: scalar.String("repeat nested one"), |
| 519 | }, |
| 520 | { |
| 521 | OptString: scalar.String("repeat nested two"), |
| 522 | OptNested: &pb2.Nested{ |
| 523 | OptString: scalar.String("inside repeat nested two"), |
| 524 | }, |
| 525 | }, |
| 526 | {}, |
| 527 | }, |
| 528 | }, |
| 529 | want: `{ |
| 530 | "rptNested": [ |
| 531 | { |
| 532 | "optString": "repeat nested one" |
| 533 | }, |
| 534 | { |
| 535 | "optString": "repeat nested two", |
| 536 | "optNested": { |
| 537 | "optString": "inside repeat nested two" |
| 538 | } |
| 539 | }, |
| 540 | {} |
| 541 | ] |
| 542 | }`, |
| 543 | }, { |
| 544 | desc: "repeated messages contains nil value", |
| 545 | input: &pb2.Nests{ |
| 546 | RptNested: []*pb2.Nested{nil, {}}, |
| 547 | }, |
| 548 | want: `{ |
| 549 | "rptNested": [ |
| 550 | {}, |
| 551 | {} |
| 552 | ] |
| 553 | }`, |
| 554 | }, { |
| 555 | desc: "repeated groups", |
| 556 | input: &pb2.Nests{ |
| 557 | Rptgroup: []*pb2.Nests_RptGroup{ |
| 558 | { |
| 559 | RptString: []string{"hello", "world"}, |
| 560 | }, |
| 561 | {}, |
| 562 | nil, |
| 563 | }, |
| 564 | }, |
| 565 | want: `{ |
| 566 | "rptgroup": [ |
| 567 | { |
| 568 | "rptString": [ |
| 569 | "hello", |
| 570 | "world" |
| 571 | ] |
| 572 | }, |
| 573 | {}, |
| 574 | {} |
| 575 | ] |
| 576 | }`, |
| 577 | }, { |
| 578 | desc: "map fields not set", |
| 579 | input: &pb3.Maps{}, |
| 580 | want: "{}", |
| 581 | }, { |
| 582 | desc: "map fields set to empty", |
| 583 | input: &pb3.Maps{ |
| 584 | Int32ToStr: map[int32]string{}, |
| 585 | BoolToUint32: map[bool]uint32{}, |
| 586 | Uint64ToEnum: map[uint64]pb3.Enum{}, |
| 587 | StrToNested: map[string]*pb3.Nested{}, |
| 588 | StrToOneofs: map[string]*pb3.Oneofs{}, |
| 589 | }, |
| 590 | want: "{}", |
| 591 | }, { |
| 592 | desc: "map fields 1", |
| 593 | input: &pb3.Maps{ |
| 594 | BoolToUint32: map[bool]uint32{ |
| 595 | true: 42, |
| 596 | false: 101, |
| 597 | }, |
| 598 | }, |
| 599 | want: `{ |
| 600 | "boolToUint32": { |
| 601 | "false": 101, |
| 602 | "true": 42 |
| 603 | } |
| 604 | }`, |
| 605 | }, { |
| 606 | desc: "map fields 2", |
| 607 | input: &pb3.Maps{ |
| 608 | Int32ToStr: map[int32]string{ |
| 609 | -101: "-101", |
| 610 | 0xff: "0xff", |
| 611 | 0: "zero", |
| 612 | }, |
| 613 | }, |
| 614 | want: `{ |
| 615 | "int32ToStr": { |
| 616 | "-101": "-101", |
| 617 | "0": "zero", |
| 618 | "255": "0xff" |
| 619 | } |
| 620 | }`, |
| 621 | }, { |
| 622 | desc: "map fields 3", |
| 623 | input: &pb3.Maps{ |
| 624 | Uint64ToEnum: map[uint64]pb3.Enum{ |
| 625 | 1: pb3.Enum_ONE, |
| 626 | 2: pb3.Enum_TWO, |
| 627 | 10: pb3.Enum_TEN, |
| 628 | 47: 47, |
| 629 | }, |
| 630 | }, |
| 631 | want: `{ |
| 632 | "uint64ToEnum": { |
| 633 | "1": "ONE", |
| 634 | "2": "TWO", |
| 635 | "10": "TEN", |
| 636 | "47": 47 |
| 637 | } |
| 638 | }`, |
| 639 | }, { |
| 640 | desc: "map fields 4", |
| 641 | input: &pb3.Maps{ |
| 642 | StrToNested: map[string]*pb3.Nested{ |
| 643 | "nested": &pb3.Nested{ |
| 644 | SString: "nested in a map", |
| 645 | }, |
| 646 | }, |
| 647 | }, |
| 648 | want: `{ |
| 649 | "strToNested": { |
| 650 | "nested": { |
| 651 | "sString": "nested in a map" |
| 652 | } |
| 653 | } |
| 654 | }`, |
| 655 | }, { |
| 656 | desc: "map fields 5", |
| 657 | input: &pb3.Maps{ |
| 658 | StrToOneofs: map[string]*pb3.Oneofs{ |
| 659 | "string": &pb3.Oneofs{ |
| 660 | Union: &pb3.Oneofs_OneofString{ |
| 661 | OneofString: "hello", |
| 662 | }, |
| 663 | }, |
| 664 | "nested": &pb3.Oneofs{ |
| 665 | Union: &pb3.Oneofs_OneofNested{ |
| 666 | OneofNested: &pb3.Nested{ |
| 667 | SString: "nested oneof in map field value", |
| 668 | }, |
| 669 | }, |
| 670 | }, |
| 671 | }, |
| 672 | }, |
| 673 | want: `{ |
| 674 | "strToOneofs": { |
| 675 | "nested": { |
| 676 | "oneofNested": { |
| 677 | "sString": "nested oneof in map field value" |
| 678 | } |
| 679 | }, |
| 680 | "string": { |
| 681 | "oneofString": "hello" |
| 682 | } |
| 683 | } |
| 684 | }`, |
| 685 | }, { |
| 686 | desc: "map field contains nil value", |
| 687 | input: &pb3.Maps{ |
| 688 | StrToNested: map[string]*pb3.Nested{ |
| 689 | "nil": nil, |
| 690 | }, |
| 691 | }, |
| 692 | want: `{ |
| 693 | "strToNested": { |
| 694 | "nil": {} |
| 695 | } |
| 696 | }`, |
| 697 | }, { |
Herbie Ong | 329be5b | 2019-03-27 14:47:59 -0700 | [diff] [blame] | 698 | desc: "required fields not set", |
| 699 | input: &pb2.Requireds{}, |
| 700 | want: `{}`, |
| 701 | wantErr: true, |
| 702 | }, { |
| 703 | desc: "required fields partially set", |
| 704 | input: &pb2.Requireds{ |
| 705 | ReqBool: scalar.Bool(false), |
| 706 | ReqSfixed64: scalar.Int64(0), |
| 707 | ReqDouble: scalar.Float64(1.23), |
| 708 | ReqString: scalar.String("hello"), |
| 709 | ReqEnum: pb2.Enum_ONE.Enum(), |
| 710 | }, |
| 711 | want: `{ |
| 712 | "reqBool": false, |
| 713 | "reqSfixed64": "0", |
| 714 | "reqDouble": 1.23, |
| 715 | "reqString": "hello", |
| 716 | "reqEnum": "ONE" |
| 717 | }`, |
| 718 | wantErr: true, |
| 719 | }, { |
| 720 | desc: "required fields not set with AllowPartial", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 721 | mo: protojson.MarshalOptions{AllowPartial: true}, |
Herbie Ong | 329be5b | 2019-03-27 14:47:59 -0700 | [diff] [blame] | 722 | input: &pb2.Requireds{ |
| 723 | ReqBool: scalar.Bool(false), |
| 724 | ReqSfixed64: scalar.Int64(0), |
| 725 | ReqDouble: scalar.Float64(1.23), |
| 726 | ReqString: scalar.String("hello"), |
| 727 | ReqEnum: pb2.Enum_ONE.Enum(), |
| 728 | }, |
| 729 | want: `{ |
| 730 | "reqBool": false, |
| 731 | "reqSfixed64": "0", |
| 732 | "reqDouble": 1.23, |
| 733 | "reqString": "hello", |
| 734 | "reqEnum": "ONE" |
| 735 | }`, |
| 736 | }, { |
| 737 | desc: "required fields all set", |
| 738 | input: &pb2.Requireds{ |
| 739 | ReqBool: scalar.Bool(false), |
| 740 | ReqSfixed64: scalar.Int64(0), |
| 741 | ReqDouble: scalar.Float64(1.23), |
| 742 | ReqString: scalar.String("hello"), |
| 743 | ReqEnum: pb2.Enum_ONE.Enum(), |
| 744 | ReqNested: &pb2.Nested{}, |
| 745 | }, |
| 746 | want: `{ |
| 747 | "reqBool": false, |
| 748 | "reqSfixed64": "0", |
| 749 | "reqDouble": 1.23, |
| 750 | "reqString": "hello", |
| 751 | "reqEnum": "ONE", |
| 752 | "reqNested": {} |
| 753 | }`, |
| 754 | }, { |
| 755 | desc: "indirect required field", |
| 756 | input: &pb2.IndirectRequired{ |
| 757 | OptNested: &pb2.NestedWithRequired{}, |
| 758 | }, |
| 759 | want: `{ |
| 760 | "optNested": {} |
| 761 | }`, |
| 762 | wantErr: true, |
| 763 | }, { |
| 764 | desc: "indirect required field with AllowPartial", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 765 | mo: protojson.MarshalOptions{AllowPartial: true}, |
Herbie Ong | 329be5b | 2019-03-27 14:47:59 -0700 | [diff] [blame] | 766 | input: &pb2.IndirectRequired{ |
| 767 | OptNested: &pb2.NestedWithRequired{}, |
| 768 | }, |
| 769 | want: `{ |
| 770 | "optNested": {} |
| 771 | }`, |
| 772 | }, { |
| 773 | desc: "indirect required field in empty repeated", |
| 774 | input: &pb2.IndirectRequired{ |
| 775 | RptNested: []*pb2.NestedWithRequired{}, |
| 776 | }, |
| 777 | want: `{}`, |
| 778 | }, { |
| 779 | desc: "indirect required field in repeated", |
| 780 | input: &pb2.IndirectRequired{ |
| 781 | RptNested: []*pb2.NestedWithRequired{ |
| 782 | &pb2.NestedWithRequired{}, |
| 783 | }, |
| 784 | }, |
| 785 | want: `{ |
| 786 | "rptNested": [ |
| 787 | {} |
| 788 | ] |
| 789 | }`, |
| 790 | wantErr: true, |
| 791 | }, { |
| 792 | desc: "indirect required field in repeated with AllowPartial", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 793 | mo: protojson.MarshalOptions{AllowPartial: true}, |
Herbie Ong | 329be5b | 2019-03-27 14:47:59 -0700 | [diff] [blame] | 794 | input: &pb2.IndirectRequired{ |
| 795 | RptNested: []*pb2.NestedWithRequired{ |
| 796 | &pb2.NestedWithRequired{}, |
| 797 | }, |
| 798 | }, |
| 799 | want: `{ |
| 800 | "rptNested": [ |
| 801 | {} |
| 802 | ] |
| 803 | }`, |
| 804 | }, { |
| 805 | desc: "indirect required field in empty map", |
| 806 | input: &pb2.IndirectRequired{ |
| 807 | StrToNested: map[string]*pb2.NestedWithRequired{}, |
| 808 | }, |
| 809 | want: "{}", |
| 810 | }, { |
| 811 | desc: "indirect required field in map", |
| 812 | input: &pb2.IndirectRequired{ |
| 813 | StrToNested: map[string]*pb2.NestedWithRequired{ |
| 814 | "fail": &pb2.NestedWithRequired{}, |
| 815 | }, |
| 816 | }, |
| 817 | want: `{ |
| 818 | "strToNested": { |
| 819 | "fail": {} |
| 820 | } |
| 821 | }`, |
| 822 | wantErr: true, |
| 823 | }, { |
| 824 | desc: "indirect required field in map with AllowPartial", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 825 | mo: protojson.MarshalOptions{AllowPartial: true}, |
Herbie Ong | 329be5b | 2019-03-27 14:47:59 -0700 | [diff] [blame] | 826 | input: &pb2.IndirectRequired{ |
| 827 | StrToNested: map[string]*pb2.NestedWithRequired{ |
| 828 | "fail": &pb2.NestedWithRequired{}, |
| 829 | }, |
| 830 | }, |
| 831 | want: `{ |
| 832 | "strToNested": { |
| 833 | "fail": {} |
| 834 | } |
| 835 | }`, |
| 836 | }, { |
| 837 | desc: "indirect required field in oneof", |
| 838 | input: &pb2.IndirectRequired{ |
| 839 | Union: &pb2.IndirectRequired_OneofNested{ |
| 840 | OneofNested: &pb2.NestedWithRequired{}, |
| 841 | }, |
| 842 | }, |
| 843 | want: `{ |
| 844 | "oneofNested": {} |
| 845 | }`, |
| 846 | wantErr: true, |
| 847 | }, { |
| 848 | desc: "indirect required field in oneof with AllowPartial", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 849 | mo: protojson.MarshalOptions{AllowPartial: true}, |
Herbie Ong | 329be5b | 2019-03-27 14:47:59 -0700 | [diff] [blame] | 850 | input: &pb2.IndirectRequired{ |
| 851 | Union: &pb2.IndirectRequired_OneofNested{ |
| 852 | OneofNested: &pb2.NestedWithRequired{}, |
| 853 | }, |
| 854 | }, |
| 855 | want: `{ |
| 856 | "oneofNested": {} |
| 857 | }`, |
| 858 | }, { |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 859 | desc: "unknown fields are ignored", |
Joe Tsai | 28216c7 | 2019-06-22 13:20:09 -0700 | [diff] [blame] | 860 | input: func() proto.Message { |
| 861 | m := &pb2.Scalars{ |
| 862 | OptString: scalar.String("no unknowns"), |
| 863 | } |
| 864 | m.ProtoReflect().SetUnknown(pack.Message{ |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 865 | pack.Tag{101, pack.BytesType}, pack.String("hello world"), |
Joe Tsai | 28216c7 | 2019-06-22 13:20:09 -0700 | [diff] [blame] | 866 | }.Marshal()) |
| 867 | return m |
| 868 | }(), |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 869 | want: `{ |
| 870 | "optString": "no unknowns" |
| 871 | }`, |
| 872 | }, { |
| 873 | desc: "json_name", |
| 874 | input: &pb3.JSONNames{ |
| 875 | SString: "json_name", |
| 876 | }, |
| 877 | want: `{ |
| 878 | "foo_bar": "json_name" |
| 879 | }`, |
Herbie Ong | f83d5bb | 2019-03-14 00:01:27 -0700 | [diff] [blame] | 880 | }, { |
| 881 | desc: "extensions of non-repeated fields", |
| 882 | input: func() proto.Message { |
| 883 | m := &pb2.Extensions{ |
| 884 | OptString: scalar.String("non-extension field"), |
| 885 | OptBool: scalar.Bool(true), |
| 886 | OptInt32: scalar.Int32(42), |
| 887 | } |
| 888 | setExtension(m, pb2.E_OptExtBool, true) |
| 889 | setExtension(m, pb2.E_OptExtString, "extension field") |
| 890 | setExtension(m, pb2.E_OptExtEnum, pb2.Enum_TEN) |
| 891 | setExtension(m, pb2.E_OptExtNested, &pb2.Nested{ |
| 892 | OptString: scalar.String("nested in an extension"), |
| 893 | OptNested: &pb2.Nested{ |
| 894 | OptString: scalar.String("another nested in an extension"), |
| 895 | }, |
| 896 | }) |
| 897 | return m |
| 898 | }(), |
| 899 | want: `{ |
| 900 | "optString": "non-extension field", |
| 901 | "optBool": true, |
| 902 | "optInt32": 42, |
| 903 | "[pb2.opt_ext_bool]": true, |
| 904 | "[pb2.opt_ext_enum]": "TEN", |
| 905 | "[pb2.opt_ext_nested]": { |
| 906 | "optString": "nested in an extension", |
| 907 | "optNested": { |
| 908 | "optString": "another nested in an extension" |
| 909 | } |
| 910 | }, |
| 911 | "[pb2.opt_ext_string]": "extension field" |
| 912 | }`, |
| 913 | }, { |
Herbie Ong | f83d5bb | 2019-03-14 00:01:27 -0700 | [diff] [blame] | 914 | desc: "extensions of repeated fields", |
| 915 | input: func() proto.Message { |
| 916 | m := &pb2.Extensions{} |
| 917 | setExtension(m, pb2.E_RptExtEnum, &[]pb2.Enum{pb2.Enum_TEN, 101, pb2.Enum_ONE}) |
| 918 | setExtension(m, pb2.E_RptExtFixed32, &[]uint32{42, 47}) |
| 919 | setExtension(m, pb2.E_RptExtNested, &[]*pb2.Nested{ |
| 920 | &pb2.Nested{OptString: scalar.String("one")}, |
| 921 | &pb2.Nested{OptString: scalar.String("two")}, |
| 922 | &pb2.Nested{OptString: scalar.String("three")}, |
| 923 | }) |
| 924 | return m |
| 925 | }(), |
| 926 | want: `{ |
| 927 | "[pb2.rpt_ext_enum]": [ |
| 928 | "TEN", |
| 929 | 101, |
| 930 | "ONE" |
| 931 | ], |
| 932 | "[pb2.rpt_ext_fixed32]": [ |
| 933 | 42, |
| 934 | 47 |
| 935 | ], |
| 936 | "[pb2.rpt_ext_nested]": [ |
| 937 | { |
| 938 | "optString": "one" |
| 939 | }, |
| 940 | { |
| 941 | "optString": "two" |
| 942 | }, |
| 943 | { |
| 944 | "optString": "three" |
| 945 | } |
| 946 | ] |
| 947 | }`, |
| 948 | }, { |
| 949 | desc: "extensions of non-repeated fields in another message", |
| 950 | input: func() proto.Message { |
| 951 | m := &pb2.Extensions{} |
| 952 | setExtension(m, pb2.E_ExtensionsContainer_OptExtBool, true) |
| 953 | setExtension(m, pb2.E_ExtensionsContainer_OptExtString, "extension field") |
| 954 | setExtension(m, pb2.E_ExtensionsContainer_OptExtEnum, pb2.Enum_TEN) |
| 955 | setExtension(m, pb2.E_ExtensionsContainer_OptExtNested, &pb2.Nested{ |
| 956 | OptString: scalar.String("nested in an extension"), |
| 957 | OptNested: &pb2.Nested{ |
| 958 | OptString: scalar.String("another nested in an extension"), |
| 959 | }, |
| 960 | }) |
| 961 | return m |
| 962 | }(), |
| 963 | want: `{ |
| 964 | "[pb2.ExtensionsContainer.opt_ext_bool]": true, |
| 965 | "[pb2.ExtensionsContainer.opt_ext_enum]": "TEN", |
| 966 | "[pb2.ExtensionsContainer.opt_ext_nested]": { |
| 967 | "optString": "nested in an extension", |
| 968 | "optNested": { |
| 969 | "optString": "another nested in an extension" |
| 970 | } |
| 971 | }, |
| 972 | "[pb2.ExtensionsContainer.opt_ext_string]": "extension field" |
| 973 | }`, |
| 974 | }, { |
| 975 | desc: "extensions of repeated fields in another message", |
| 976 | input: func() proto.Message { |
| 977 | m := &pb2.Extensions{ |
| 978 | OptString: scalar.String("non-extension field"), |
| 979 | OptBool: scalar.Bool(true), |
| 980 | OptInt32: scalar.Int32(42), |
| 981 | } |
| 982 | setExtension(m, pb2.E_ExtensionsContainer_RptExtEnum, &[]pb2.Enum{pb2.Enum_TEN, 101, pb2.Enum_ONE}) |
| 983 | setExtension(m, pb2.E_ExtensionsContainer_RptExtString, &[]string{"hello", "world"}) |
| 984 | setExtension(m, pb2.E_ExtensionsContainer_RptExtNested, &[]*pb2.Nested{ |
| 985 | &pb2.Nested{OptString: scalar.String("one")}, |
| 986 | &pb2.Nested{OptString: scalar.String("two")}, |
| 987 | &pb2.Nested{OptString: scalar.String("three")}, |
| 988 | }) |
| 989 | return m |
| 990 | }(), |
| 991 | want: `{ |
| 992 | "optString": "non-extension field", |
| 993 | "optBool": true, |
| 994 | "optInt32": 42, |
| 995 | "[pb2.ExtensionsContainer.rpt_ext_enum]": [ |
| 996 | "TEN", |
| 997 | 101, |
| 998 | "ONE" |
| 999 | ], |
| 1000 | "[pb2.ExtensionsContainer.rpt_ext_nested]": [ |
| 1001 | { |
| 1002 | "optString": "one" |
| 1003 | }, |
| 1004 | { |
| 1005 | "optString": "two" |
| 1006 | }, |
| 1007 | { |
| 1008 | "optString": "three" |
| 1009 | } |
| 1010 | ], |
| 1011 | "[pb2.ExtensionsContainer.rpt_ext_string]": [ |
| 1012 | "hello", |
| 1013 | "world" |
| 1014 | ] |
| 1015 | }`, |
| 1016 | }, { |
| 1017 | desc: "MessageSet", |
| 1018 | input: func() proto.Message { |
| 1019 | m := &pb2.MessageSet{} |
| 1020 | setExtension(m, pb2.E_MessageSetExtension_MessageSetExtension, &pb2.MessageSetExtension{ |
| 1021 | OptString: scalar.String("a messageset extension"), |
| 1022 | }) |
| 1023 | setExtension(m, pb2.E_MessageSetExtension_NotMessageSetExtension, &pb2.MessageSetExtension{ |
| 1024 | OptString: scalar.String("not a messageset extension"), |
| 1025 | }) |
| 1026 | setExtension(m, pb2.E_MessageSetExtension_ExtNested, &pb2.Nested{ |
| 1027 | OptString: scalar.String("just a regular extension"), |
| 1028 | }) |
| 1029 | return m |
| 1030 | }(), |
| 1031 | want: `{ |
| 1032 | "[pb2.MessageSetExtension]": { |
| 1033 | "optString": "a messageset extension" |
| 1034 | }, |
| 1035 | "[pb2.MessageSetExtension.ext_nested]": { |
| 1036 | "optString": "just a regular extension" |
| 1037 | }, |
| 1038 | "[pb2.MessageSetExtension.not_message_set_extension]": { |
| 1039 | "optString": "not a messageset extension" |
| 1040 | } |
| 1041 | }`, |
| 1042 | }, { |
| 1043 | desc: "not real MessageSet 1", |
| 1044 | input: func() proto.Message { |
| 1045 | m := &pb2.FakeMessageSet{} |
| 1046 | setExtension(m, pb2.E_FakeMessageSetExtension_MessageSetExtension, &pb2.FakeMessageSetExtension{ |
| 1047 | OptString: scalar.String("not a messageset extension"), |
| 1048 | }) |
| 1049 | return m |
| 1050 | }(), |
| 1051 | want: `{ |
| 1052 | "[pb2.FakeMessageSetExtension.message_set_extension]": { |
| 1053 | "optString": "not a messageset extension" |
| 1054 | } |
| 1055 | }`, |
| 1056 | }, { |
| 1057 | desc: "not real MessageSet 2", |
| 1058 | input: func() proto.Message { |
| 1059 | m := &pb2.MessageSet{} |
| 1060 | setExtension(m, pb2.E_MessageSetExtension, &pb2.FakeMessageSetExtension{ |
| 1061 | OptString: scalar.String("another not a messageset extension"), |
| 1062 | }) |
| 1063 | return m |
| 1064 | }(), |
| 1065 | want: `{ |
| 1066 | "[pb2.message_set_extension]": { |
| 1067 | "optString": "another not a messageset extension" |
| 1068 | } |
| 1069 | }`, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1070 | }, { |
| 1071 | desc: "BoolValue empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1072 | input: &wrapperspb.BoolValue{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1073 | want: `false`, |
| 1074 | }, { |
| 1075 | desc: "BoolValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1076 | input: &wrapperspb.BoolValue{Value: true}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1077 | want: `true`, |
| 1078 | }, { |
| 1079 | desc: "Int32Value empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1080 | input: &wrapperspb.Int32Value{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1081 | want: `0`, |
| 1082 | }, { |
| 1083 | desc: "Int32Value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1084 | input: &wrapperspb.Int32Value{Value: 42}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1085 | want: `42`, |
| 1086 | }, { |
| 1087 | desc: "Int64Value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1088 | input: &wrapperspb.Int64Value{Value: 42}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1089 | want: `"42"`, |
| 1090 | }, { |
| 1091 | desc: "UInt32Value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1092 | input: &wrapperspb.UInt32Value{Value: 42}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1093 | want: `42`, |
| 1094 | }, { |
| 1095 | desc: "UInt64Value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1096 | input: &wrapperspb.UInt64Value{Value: 42}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1097 | want: `"42"`, |
| 1098 | }, { |
| 1099 | desc: "FloatValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1100 | input: &wrapperspb.FloatValue{Value: 1.02}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1101 | want: `1.02`, |
| 1102 | }, { |
Herbie Ong | e63c4c4 | 2019-03-22 22:20:22 -0700 | [diff] [blame] | 1103 | desc: "FloatValue Infinity", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1104 | input: &wrapperspb.FloatValue{Value: float32(math.Inf(-1))}, |
Herbie Ong | e63c4c4 | 2019-03-22 22:20:22 -0700 | [diff] [blame] | 1105 | want: `"-Infinity"`, |
| 1106 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1107 | desc: "DoubleValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1108 | input: &wrapperspb.DoubleValue{Value: 1.02}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1109 | want: `1.02`, |
| 1110 | }, { |
Herbie Ong | e63c4c4 | 2019-03-22 22:20:22 -0700 | [diff] [blame] | 1111 | desc: "DoubleValue NaN", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1112 | input: &wrapperspb.DoubleValue{Value: math.NaN()}, |
Herbie Ong | e63c4c4 | 2019-03-22 22:20:22 -0700 | [diff] [blame] | 1113 | want: `"NaN"`, |
| 1114 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1115 | desc: "StringValue empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1116 | input: &wrapperspb.StringValue{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1117 | want: `""`, |
| 1118 | }, { |
| 1119 | desc: "StringValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1120 | input: &wrapperspb.StringValue{Value: "谷歌"}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1121 | want: `"谷歌"`, |
| 1122 | }, { |
| 1123 | desc: "StringValue with invalid UTF8 error", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1124 | input: &wrapperspb.StringValue{Value: "abc\xff"}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1125 | wantErr: true, |
| 1126 | }, { |
| 1127 | desc: "StringValue field with invalid UTF8 error", |
| 1128 | input: &pb2.KnownTypes{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1129 | OptString: &wrapperspb.StringValue{Value: "abc\xff"}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1130 | }, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1131 | wantErr: true, |
| 1132 | }, { |
| 1133 | desc: "BytesValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1134 | input: &wrapperspb.BytesValue{Value: []byte("hello")}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1135 | want: `"aGVsbG8="`, |
| 1136 | }, { |
| 1137 | desc: "Empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1138 | input: &emptypb.Empty{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1139 | want: `{}`, |
| 1140 | }, { |
Herbie Ong | 300b9fe | 2019-03-29 15:42:20 -0700 | [diff] [blame] | 1141 | desc: "NullValue field", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1142 | input: &pb2.KnownTypes{OptNull: new(structpb.NullValue)}, |
Herbie Ong | 300b9fe | 2019-03-29 15:42:20 -0700 | [diff] [blame] | 1143 | want: `{ |
| 1144 | "optNull": null |
| 1145 | }`, |
| 1146 | }, { |
Herbie Ong | 1c7462c | 2019-03-22 17:56:55 -0700 | [diff] [blame] | 1147 | desc: "Value empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1148 | input: &structpb.Value{}, |
Herbie Ong | 1c7462c | 2019-03-22 17:56:55 -0700 | [diff] [blame] | 1149 | wantErr: true, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1150 | }, { |
| 1151 | desc: "Value empty field", |
| 1152 | input: &pb2.KnownTypes{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1153 | OptValue: &structpb.Value{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1154 | }, |
Herbie Ong | 1c7462c | 2019-03-22 17:56:55 -0700 | [diff] [blame] | 1155 | wantErr: true, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1156 | }, { |
| 1157 | desc: "Value contains NullValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1158 | input: &structpb.Value{Kind: &structpb.Value_NullValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1159 | want: `null`, |
| 1160 | }, { |
| 1161 | desc: "Value contains BoolValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1162 | input: &structpb.Value{Kind: &structpb.Value_BoolValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1163 | want: `false`, |
| 1164 | }, { |
| 1165 | desc: "Value contains NumberValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1166 | input: &structpb.Value{Kind: &structpb.Value_NumberValue{1.02}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1167 | want: `1.02`, |
| 1168 | }, { |
| 1169 | desc: "Value contains StringValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1170 | input: &structpb.Value{Kind: &structpb.Value_StringValue{"hello"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1171 | want: `"hello"`, |
| 1172 | }, { |
| 1173 | desc: "Value contains StringValue with invalid UTF8", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1174 | input: &structpb.Value{Kind: &structpb.Value_StringValue{"\xff"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1175 | wantErr: true, |
| 1176 | }, { |
| 1177 | desc: "Value contains Struct", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1178 | input: &structpb.Value{ |
| 1179 | Kind: &structpb.Value_StructValue{ |
| 1180 | &structpb.Struct{ |
| 1181 | Fields: map[string]*structpb.Value{ |
| 1182 | "null": {Kind: &structpb.Value_NullValue{}}, |
| 1183 | "number": {Kind: &structpb.Value_NumberValue{}}, |
| 1184 | "string": {Kind: &structpb.Value_StringValue{}}, |
| 1185 | "struct": {Kind: &structpb.Value_StructValue{}}, |
| 1186 | "list": {Kind: &structpb.Value_ListValue{}}, |
| 1187 | "bool": {Kind: &structpb.Value_BoolValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1188 | }, |
| 1189 | }, |
| 1190 | }, |
| 1191 | }, |
| 1192 | want: `{ |
| 1193 | "bool": false, |
| 1194 | "list": [], |
| 1195 | "null": null, |
| 1196 | "number": 0, |
| 1197 | "string": "", |
| 1198 | "struct": {} |
| 1199 | }`, |
| 1200 | }, { |
| 1201 | desc: "Value contains ListValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1202 | input: &structpb.Value{ |
| 1203 | Kind: &structpb.Value_ListValue{ |
| 1204 | &structpb.ListValue{ |
| 1205 | Values: []*structpb.Value{ |
| 1206 | {Kind: &structpb.Value_BoolValue{}}, |
| 1207 | {Kind: &structpb.Value_NullValue{}}, |
| 1208 | {Kind: &structpb.Value_NumberValue{}}, |
| 1209 | {Kind: &structpb.Value_StringValue{}}, |
| 1210 | {Kind: &structpb.Value_StructValue{}}, |
| 1211 | {Kind: &structpb.Value_ListValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1212 | }, |
| 1213 | }, |
| 1214 | }, |
| 1215 | }, |
| 1216 | want: `[ |
| 1217 | false, |
| 1218 | null, |
| 1219 | 0, |
| 1220 | "", |
| 1221 | {}, |
| 1222 | [] |
| 1223 | ]`, |
| 1224 | }, { |
| 1225 | desc: "Struct with nil map", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1226 | input: &structpb.Struct{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1227 | want: `{}`, |
| 1228 | }, { |
| 1229 | desc: "Struct with empty map", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1230 | input: &structpb.Struct{ |
| 1231 | Fields: map[string]*structpb.Value{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1232 | }, |
| 1233 | want: `{}`, |
| 1234 | }, { |
| 1235 | desc: "Struct", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1236 | input: &structpb.Struct{ |
| 1237 | Fields: map[string]*structpb.Value{ |
| 1238 | "bool": {Kind: &structpb.Value_BoolValue{true}}, |
| 1239 | "null": {Kind: &structpb.Value_NullValue{}}, |
| 1240 | "number": {Kind: &structpb.Value_NumberValue{3.1415}}, |
| 1241 | "string": {Kind: &structpb.Value_StringValue{"hello"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1242 | "struct": { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1243 | Kind: &structpb.Value_StructValue{ |
| 1244 | &structpb.Struct{ |
| 1245 | Fields: map[string]*structpb.Value{ |
| 1246 | "string": {Kind: &structpb.Value_StringValue{"world"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1247 | }, |
| 1248 | }, |
| 1249 | }, |
| 1250 | }, |
| 1251 | "list": { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1252 | Kind: &structpb.Value_ListValue{ |
| 1253 | &structpb.ListValue{ |
| 1254 | Values: []*structpb.Value{ |
| 1255 | {Kind: &structpb.Value_BoolValue{}}, |
| 1256 | {Kind: &structpb.Value_NullValue{}}, |
| 1257 | {Kind: &structpb.Value_NumberValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1258 | }, |
| 1259 | }, |
| 1260 | }, |
| 1261 | }, |
| 1262 | }, |
| 1263 | }, |
| 1264 | want: `{ |
| 1265 | "bool": true, |
| 1266 | "list": [ |
| 1267 | false, |
| 1268 | null, |
| 1269 | 0 |
| 1270 | ], |
| 1271 | "null": null, |
| 1272 | "number": 3.1415, |
| 1273 | "string": "hello", |
| 1274 | "struct": { |
| 1275 | "string": "world" |
| 1276 | } |
| 1277 | }`, |
| 1278 | }, { |
| 1279 | desc: "Struct message with invalid UTF8 string", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1280 | input: &structpb.Struct{ |
| 1281 | Fields: map[string]*structpb.Value{ |
| 1282 | "string": {Kind: &structpb.Value_StringValue{"\xff"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1283 | }, |
| 1284 | }, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1285 | wantErr: true, |
| 1286 | }, { |
| 1287 | desc: "ListValue with nil values", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1288 | input: &structpb.ListValue{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1289 | want: `[]`, |
| 1290 | }, { |
| 1291 | desc: "ListValue with empty values", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1292 | input: &structpb.ListValue{ |
| 1293 | Values: []*structpb.Value{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1294 | }, |
| 1295 | want: `[]`, |
| 1296 | }, { |
| 1297 | desc: "ListValue", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1298 | input: &structpb.ListValue{ |
| 1299 | Values: []*structpb.Value{ |
| 1300 | {Kind: &structpb.Value_BoolValue{true}}, |
| 1301 | {Kind: &structpb.Value_NullValue{}}, |
| 1302 | {Kind: &structpb.Value_NumberValue{3.1415}}, |
| 1303 | {Kind: &structpb.Value_StringValue{"hello"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1304 | { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1305 | Kind: &structpb.Value_ListValue{ |
| 1306 | &structpb.ListValue{ |
| 1307 | Values: []*structpb.Value{ |
| 1308 | {Kind: &structpb.Value_BoolValue{}}, |
| 1309 | {Kind: &structpb.Value_NullValue{}}, |
| 1310 | {Kind: &structpb.Value_NumberValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1311 | }, |
| 1312 | }, |
| 1313 | }, |
| 1314 | }, |
| 1315 | { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1316 | Kind: &structpb.Value_StructValue{ |
| 1317 | &structpb.Struct{ |
| 1318 | Fields: map[string]*structpb.Value{ |
| 1319 | "string": {Kind: &structpb.Value_StringValue{"world"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1320 | }, |
| 1321 | }, |
| 1322 | }, |
| 1323 | }, |
| 1324 | }, |
| 1325 | }, |
| 1326 | want: `[ |
| 1327 | true, |
| 1328 | null, |
| 1329 | 3.1415, |
| 1330 | "hello", |
| 1331 | [ |
| 1332 | false, |
| 1333 | null, |
| 1334 | 0 |
| 1335 | ], |
| 1336 | { |
| 1337 | "string": "world" |
| 1338 | } |
| 1339 | ]`, |
| 1340 | }, { |
| 1341 | desc: "ListValue with invalid UTF8 string", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1342 | input: &structpb.ListValue{ |
| 1343 | Values: []*structpb.Value{ |
| 1344 | {Kind: &structpb.Value_StringValue{"\xff"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1345 | }, |
| 1346 | }, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1347 | wantErr: true, |
| 1348 | }, { |
| 1349 | desc: "Duration empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1350 | input: &durationpb.Duration{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1351 | want: `"0s"`, |
| 1352 | }, { |
| 1353 | desc: "Duration with secs", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1354 | input: &durationpb.Duration{Seconds: 3}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1355 | want: `"3s"`, |
| 1356 | }, { |
| 1357 | desc: "Duration with -secs", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1358 | input: &durationpb.Duration{Seconds: -3}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1359 | want: `"-3s"`, |
| 1360 | }, { |
| 1361 | desc: "Duration with nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1362 | input: &durationpb.Duration{Nanos: 1e6}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1363 | want: `"0.001s"`, |
| 1364 | }, { |
| 1365 | desc: "Duration with -nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1366 | input: &durationpb.Duration{Nanos: -1e6}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1367 | want: `"-0.001s"`, |
| 1368 | }, { |
| 1369 | desc: "Duration with large secs", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1370 | input: &durationpb.Duration{Seconds: 1e10, Nanos: 1}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1371 | want: `"10000000000.000000001s"`, |
| 1372 | }, { |
| 1373 | desc: "Duration with 6-digit nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1374 | input: &durationpb.Duration{Nanos: 1e4}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1375 | want: `"0.000010s"`, |
| 1376 | }, { |
| 1377 | desc: "Duration with 3-digit nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1378 | input: &durationpb.Duration{Nanos: 1e6}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1379 | want: `"0.001s"`, |
| 1380 | }, { |
| 1381 | desc: "Duration with -secs -nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1382 | input: &durationpb.Duration{Seconds: -123, Nanos: -450}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1383 | want: `"-123.000000450s"`, |
| 1384 | }, { |
Herbie Ong | ad9c125 | 2019-04-24 20:51:28 -0700 | [diff] [blame] | 1385 | desc: "Duration max value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1386 | input: &durationpb.Duration{Seconds: 315576000000, Nanos: 999999999}, |
Herbie Ong | ad9c125 | 2019-04-24 20:51:28 -0700 | [diff] [blame] | 1387 | want: `"315576000000.999999999s"`, |
| 1388 | }, { |
| 1389 | desc: "Duration min value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1390 | input: &durationpb.Duration{Seconds: -315576000000, Nanos: -999999999}, |
Herbie Ong | ad9c125 | 2019-04-24 20:51:28 -0700 | [diff] [blame] | 1391 | want: `"-315576000000.999999999s"`, |
| 1392 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1393 | desc: "Duration with +secs -nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1394 | input: &durationpb.Duration{Seconds: 1, Nanos: -1}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1395 | wantErr: true, |
| 1396 | }, { |
| 1397 | desc: "Duration with -secs +nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1398 | input: &durationpb.Duration{Seconds: -1, Nanos: 1}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1399 | wantErr: true, |
| 1400 | }, { |
| 1401 | desc: "Duration with +secs out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1402 | input: &durationpb.Duration{Seconds: 315576000001}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1403 | wantErr: true, |
| 1404 | }, { |
| 1405 | desc: "Duration with -secs out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1406 | input: &durationpb.Duration{Seconds: -315576000001}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1407 | wantErr: true, |
| 1408 | }, { |
| 1409 | desc: "Duration with +nanos out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1410 | input: &durationpb.Duration{Seconds: 0, Nanos: 1e9}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1411 | wantErr: true, |
| 1412 | }, { |
| 1413 | desc: "Duration with -nanos out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1414 | input: &durationpb.Duration{Seconds: 0, Nanos: -1e9}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1415 | wantErr: true, |
| 1416 | }, { |
| 1417 | desc: "Timestamp zero", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1418 | input: ×tamppb.Timestamp{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1419 | want: `"1970-01-01T00:00:00Z"`, |
| 1420 | }, { |
| 1421 | desc: "Timestamp", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1422 | input: ×tamppb.Timestamp{Seconds: 1553036601}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1423 | want: `"2019-03-19T23:03:21Z"`, |
| 1424 | }, { |
| 1425 | desc: "Timestamp with nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1426 | input: ×tamppb.Timestamp{Seconds: 1553036601, Nanos: 1}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1427 | want: `"2019-03-19T23:03:21.000000001Z"`, |
| 1428 | }, { |
| 1429 | desc: "Timestamp with 6-digit nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1430 | input: ×tamppb.Timestamp{Nanos: 1e3}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1431 | want: `"1970-01-01T00:00:00.000001Z"`, |
| 1432 | }, { |
| 1433 | desc: "Timestamp with 3-digit nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1434 | input: ×tamppb.Timestamp{Nanos: 1e7}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1435 | want: `"1970-01-01T00:00:00.010Z"`, |
| 1436 | }, { |
Herbie Ong | ad9c125 | 2019-04-24 20:51:28 -0700 | [diff] [blame] | 1437 | desc: "Timestamp max value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1438 | input: ×tamppb.Timestamp{Seconds: 253402300799, Nanos: 999999999}, |
Herbie Ong | ad9c125 | 2019-04-24 20:51:28 -0700 | [diff] [blame] | 1439 | want: `"9999-12-31T23:59:59.999999999Z"`, |
| 1440 | }, { |
| 1441 | desc: "Timestamp min value", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1442 | input: ×tamppb.Timestamp{Seconds: -62135596800}, |
Herbie Ong | ad9c125 | 2019-04-24 20:51:28 -0700 | [diff] [blame] | 1443 | want: `"0001-01-01T00:00:00Z"`, |
| 1444 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1445 | desc: "Timestamp with +secs out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1446 | input: ×tamppb.Timestamp{Seconds: 253402300800}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1447 | wantErr: true, |
| 1448 | }, { |
| 1449 | desc: "Timestamp with -secs out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1450 | input: ×tamppb.Timestamp{Seconds: -62135596801}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1451 | wantErr: true, |
| 1452 | }, { |
| 1453 | desc: "Timestamp with -nanos", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1454 | input: ×tamppb.Timestamp{Nanos: -1}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1455 | wantErr: true, |
| 1456 | }, { |
| 1457 | desc: "Timestamp with +nanos out of range", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1458 | input: ×tamppb.Timestamp{Nanos: 1e9}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1459 | wantErr: true, |
| 1460 | }, { |
| 1461 | desc: "FieldMask empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1462 | input: &fieldmaskpb.FieldMask{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1463 | want: `""`, |
| 1464 | }, { |
| 1465 | desc: "FieldMask", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1466 | input: &fieldmaskpb.FieldMask{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1467 | Paths: []string{ |
| 1468 | "foo", |
| 1469 | "foo_bar", |
| 1470 | "foo.bar_qux", |
| 1471 | "_foo", |
| 1472 | }, |
| 1473 | }, |
| 1474 | want: `"foo,fooBar,foo.barQux,Foo"`, |
| 1475 | }, { |
| 1476 | desc: "FieldMask error 1", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1477 | input: &fieldmaskpb.FieldMask{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1478 | Paths: []string{"foo_"}, |
| 1479 | }, |
| 1480 | wantErr: true, |
| 1481 | }, { |
| 1482 | desc: "FieldMask error 2", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1483 | input: &fieldmaskpb.FieldMask{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1484 | Paths: []string{"foo__bar"}, |
| 1485 | }, |
| 1486 | wantErr: true, |
| 1487 | }, { |
| 1488 | desc: "Any empty", |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1489 | input: &anypb.Any{}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1490 | want: `{}`, |
| 1491 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1492 | desc: "Any with non-custom message", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1493 | mo: protojson.MarshalOptions{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1494 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1495 | }, |
| 1496 | input: func() proto.Message { |
| 1497 | m := &pb2.Nested{ |
| 1498 | OptString: scalar.String("embedded inside Any"), |
| 1499 | OptNested: &pb2.Nested{ |
| 1500 | OptString: scalar.String("inception"), |
| 1501 | }, |
| 1502 | } |
| 1503 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1504 | if err != nil { |
| 1505 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1506 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1507 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1508 | TypeUrl: "foo/pb2.Nested", |
| 1509 | Value: b, |
| 1510 | } |
| 1511 | }(), |
| 1512 | want: `{ |
| 1513 | "@type": "foo/pb2.Nested", |
| 1514 | "optString": "embedded inside Any", |
| 1515 | "optNested": { |
| 1516 | "optString": "inception" |
| 1517 | } |
| 1518 | }`, |
| 1519 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1520 | desc: "Any with empty embedded message", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1521 | mo: protojson.MarshalOptions{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1522 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1523 | }, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1524 | input: &anypb.Any{TypeUrl: "foo/pb2.Nested"}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1525 | want: `{ |
| 1526 | "@type": "foo/pb2.Nested" |
| 1527 | }`, |
| 1528 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1529 | desc: "Any without registered type", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1530 | mo: protojson.MarshalOptions{Resolver: preg.NewTypes()}, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1531 | input: &anypb.Any{TypeUrl: "foo/pb2.Nested"}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1532 | wantErr: true, |
| 1533 | }, { |
Damien Neil | 0c9f0a9 | 2019-06-19 10:41:09 -0700 | [diff] [blame] | 1534 | desc: "Any with missing required", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1535 | mo: protojson.MarshalOptions{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1536 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1537 | }, |
| 1538 | input: func() proto.Message { |
| 1539 | m := &pb2.PartialRequired{ |
| 1540 | OptString: scalar.String("embedded inside Any"), |
| 1541 | } |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 1542 | b, err := proto.MarshalOptions{ |
| 1543 | AllowPartial: true, |
| 1544 | Deterministic: true, |
| 1545 | }.Marshal(m) |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1546 | if err != nil { |
| 1547 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1548 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1549 | return &anypb.Any{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1550 | TypeUrl: string(m.ProtoReflect().Descriptor().FullName()), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1551 | Value: b, |
| 1552 | } |
| 1553 | }(), |
| 1554 | want: `{ |
| 1555 | "@type": "pb2.PartialRequired", |
| 1556 | "optString": "embedded inside Any" |
| 1557 | }`, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1558 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1559 | desc: "Any with partial required and AllowPartial", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1560 | mo: protojson.MarshalOptions{ |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1561 | AllowPartial: true, |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1562 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.PartialRequired{})), |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1563 | }, |
| 1564 | input: func() proto.Message { |
| 1565 | m := &pb2.PartialRequired{ |
| 1566 | OptString: scalar.String("embedded inside Any"), |
| 1567 | } |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 1568 | b, err := proto.MarshalOptions{ |
| 1569 | AllowPartial: true, |
| 1570 | Deterministic: true, |
| 1571 | }.Marshal(m) |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1572 | if err != nil { |
| 1573 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1574 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1575 | return &anypb.Any{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1576 | TypeUrl: string(m.ProtoReflect().Descriptor().FullName()), |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1577 | Value: b, |
| 1578 | } |
| 1579 | }(), |
| 1580 | want: `{ |
| 1581 | "@type": "pb2.PartialRequired", |
| 1582 | "optString": "embedded inside Any" |
| 1583 | }`, |
| 1584 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1585 | desc: "Any with invalid UTF8", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1586 | mo: protojson.MarshalOptions{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1587 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1588 | }, |
| 1589 | input: func() proto.Message { |
| 1590 | m := &pb2.Nested{ |
| 1591 | OptString: scalar.String("abc\xff"), |
| 1592 | } |
| 1593 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1594 | if err != nil { |
| 1595 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1596 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1597 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1598 | TypeUrl: "foo/pb2.Nested", |
| 1599 | Value: b, |
| 1600 | } |
| 1601 | }(), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1602 | wantErr: true, |
| 1603 | }, { |
| 1604 | desc: "Any with invalid value", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1605 | mo: protojson.MarshalOptions{ |
Joe Tsai | 0fc49f8 | 2019-05-01 12:29:25 -0700 | [diff] [blame] | 1606 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&pb2.Nested{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1607 | }, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1608 | input: &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1609 | TypeUrl: "foo/pb2.Nested", |
Joe Tsai | 6dc168e | 2019-07-09 23:11:13 -0700 | [diff] [blame^] | 1610 | Value: []byte("\x80"), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1611 | }, |
| 1612 | wantErr: true, |
| 1613 | }, { |
| 1614 | desc: "Any with BoolValue", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1615 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1616 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&wrapperspb.BoolValue{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1617 | }, |
| 1618 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1619 | m := &wrapperspb.BoolValue{Value: true} |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1620 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1621 | if err != nil { |
| 1622 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1623 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1624 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1625 | TypeUrl: "type.googleapis.com/google.protobuf.BoolValue", |
| 1626 | Value: b, |
| 1627 | } |
| 1628 | }(), |
| 1629 | want: `{ |
| 1630 | "@type": "type.googleapis.com/google.protobuf.BoolValue", |
| 1631 | "value": true |
| 1632 | }`, |
| 1633 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1634 | desc: "Any with Empty", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1635 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1636 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&emptypb.Empty{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1637 | }, |
| 1638 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1639 | m := &emptypb.Empty{} |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1640 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1641 | if err != nil { |
| 1642 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1643 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1644 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1645 | TypeUrl: "type.googleapis.com/google.protobuf.Empty", |
| 1646 | Value: b, |
| 1647 | } |
| 1648 | }(), |
| 1649 | want: `{ |
Herbie Ong | 82014a5 | 2019-03-27 15:21:43 -0700 | [diff] [blame] | 1650 | "@type": "type.googleapis.com/google.protobuf.Empty", |
| 1651 | "value": {} |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1652 | }`, |
| 1653 | }, { |
| 1654 | desc: "Any with StringValue containing invalid UTF8", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1655 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1656 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&wrapperspb.StringValue{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1657 | }, |
| 1658 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1659 | m := &wrapperspb.StringValue{Value: "abcd"} |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1660 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1661 | if err != nil { |
| 1662 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1663 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1664 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1665 | TypeUrl: "google.protobuf.StringValue", |
Damien Neil | bc310b5 | 2019-04-11 11:46:55 -0700 | [diff] [blame] | 1666 | Value: bytes.Replace(b, []byte("abcd"), []byte("abc\xff"), -1), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1667 | } |
| 1668 | }(), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1669 | wantErr: true, |
| 1670 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1671 | desc: "Any with Int64Value", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1672 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1673 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&wrapperspb.Int64Value{})), |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1674 | }, |
| 1675 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1676 | m := &wrapperspb.Int64Value{Value: 42} |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1677 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1678 | if err != nil { |
| 1679 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1680 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1681 | return &anypb.Any{ |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1682 | TypeUrl: "google.protobuf.Int64Value", |
| 1683 | Value: b, |
| 1684 | } |
| 1685 | }(), |
| 1686 | want: `{ |
| 1687 | "@type": "google.protobuf.Int64Value", |
| 1688 | "value": "42" |
| 1689 | }`, |
| 1690 | }, { |
| 1691 | desc: "Any with Duration", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1692 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1693 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&durationpb.Duration{})), |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1694 | }, |
| 1695 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1696 | m := &durationpb.Duration{} |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1697 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1698 | if err != nil { |
| 1699 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1700 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1701 | return &anypb.Any{ |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1702 | TypeUrl: "type.googleapis.com/google.protobuf.Duration", |
| 1703 | Value: b, |
| 1704 | } |
| 1705 | }(), |
| 1706 | want: `{ |
| 1707 | "@type": "type.googleapis.com/google.protobuf.Duration", |
| 1708 | "value": "0s" |
| 1709 | }`, |
| 1710 | }, { |
| 1711 | desc: "Any with empty Value", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1712 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1713 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&structpb.Value{})), |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1714 | }, |
| 1715 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1716 | m := &structpb.Value{} |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1717 | b, err := proto.Marshal(m) |
| 1718 | if err != nil { |
| 1719 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1720 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1721 | return &anypb.Any{ |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1722 | TypeUrl: "type.googleapis.com/google.protobuf.Value", |
| 1723 | Value: b, |
| 1724 | } |
| 1725 | }(), |
| 1726 | wantErr: true, |
| 1727 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1728 | desc: "Any with Value of StringValue", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1729 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1730 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&structpb.Value{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1731 | }, |
| 1732 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1733 | m := &structpb.Value{Kind: &structpb.Value_StringValue{"abcd"}} |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1734 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1735 | if err != nil { |
| 1736 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1737 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1738 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1739 | TypeUrl: "type.googleapis.com/google.protobuf.Value", |
Damien Neil | bc310b5 | 2019-04-11 11:46:55 -0700 | [diff] [blame] | 1740 | Value: bytes.Replace(b, []byte("abcd"), []byte("abc\xff"), -1), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1741 | } |
| 1742 | }(), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1743 | wantErr: true, |
| 1744 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1745 | desc: "Any with Value of NullValue", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1746 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1747 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&structpb.Value{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1748 | }, |
| 1749 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1750 | m := &structpb.Value{Kind: &structpb.Value_NullValue{}} |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1751 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1752 | if err != nil { |
| 1753 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1754 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1755 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1756 | TypeUrl: "type.googleapis.com/google.protobuf.Value", |
| 1757 | Value: b, |
| 1758 | } |
| 1759 | }(), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1760 | want: `{ |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1761 | "@type": "type.googleapis.com/google.protobuf.Value", |
| 1762 | "value": null |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1763 | }`, |
| 1764 | }, { |
| 1765 | desc: "Any with Struct", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1766 | mo: protojson.MarshalOptions{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1767 | Resolver: preg.NewTypes( |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1768 | pimpl.Export{}.MessageTypeOf(&structpb.Struct{}), |
| 1769 | pimpl.Export{}.MessageTypeOf(&structpb.Value{}), |
| 1770 | pimpl.Export{}.MessageTypeOf(&wrapperspb.BoolValue{}), |
| 1771 | pimpl.Export{}.EnumTypeOf(structpb.NullValue_NULL_VALUE), |
| 1772 | pimpl.Export{}.MessageTypeOf(&wrapperspb.StringValue{}), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1773 | ), |
| 1774 | }, |
| 1775 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1776 | m := &structpb.Struct{ |
| 1777 | Fields: map[string]*structpb.Value{ |
| 1778 | "bool": {Kind: &structpb.Value_BoolValue{true}}, |
| 1779 | "null": {Kind: &structpb.Value_NullValue{}}, |
| 1780 | "string": {Kind: &structpb.Value_StringValue{"hello"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1781 | "struct": { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1782 | Kind: &structpb.Value_StructValue{ |
| 1783 | &structpb.Struct{ |
| 1784 | Fields: map[string]*structpb.Value{ |
| 1785 | "string": {Kind: &structpb.Value_StringValue{"world"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1786 | }, |
| 1787 | }, |
| 1788 | }, |
| 1789 | }, |
| 1790 | }, |
| 1791 | } |
| 1792 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1793 | if err != nil { |
| 1794 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1795 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1796 | return &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1797 | TypeUrl: "google.protobuf.Struct", |
| 1798 | Value: b, |
| 1799 | } |
| 1800 | }(), |
| 1801 | want: `{ |
| 1802 | "@type": "google.protobuf.Struct", |
| 1803 | "value": { |
| 1804 | "bool": true, |
| 1805 | "null": null, |
| 1806 | "string": "hello", |
| 1807 | "struct": { |
| 1808 | "string": "world" |
| 1809 | } |
| 1810 | } |
| 1811 | }`, |
| 1812 | }, { |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1813 | desc: "Any with missing type_url", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1814 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1815 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&wrapperspb.BoolValue{})), |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1816 | }, |
| 1817 | input: func() proto.Message { |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1818 | m := &wrapperspb.BoolValue{Value: true} |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1819 | b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) |
| 1820 | if err != nil { |
| 1821 | t.Fatalf("error in binary marshaling message for Any.value: %v", err) |
| 1822 | } |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1823 | return &anypb.Any{ |
Herbie Ong | 8ac9dd2 | 2019-03-27 12:20:50 -0700 | [diff] [blame] | 1824 | Value: b, |
| 1825 | } |
| 1826 | }(), |
| 1827 | wantErr: true, |
| 1828 | }, { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1829 | desc: "well known types as field values", |
Damien Neil | 5c5b531 | 2019-05-14 12:44:37 -0700 | [diff] [blame] | 1830 | mo: protojson.MarshalOptions{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1831 | Resolver: preg.NewTypes(pimpl.Export{}.MessageTypeOf(&emptypb.Empty{})), |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1832 | }, |
| 1833 | input: &pb2.KnownTypes{ |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1834 | OptBool: &wrapperspb.BoolValue{Value: false}, |
| 1835 | OptInt32: &wrapperspb.Int32Value{Value: 42}, |
| 1836 | OptInt64: &wrapperspb.Int64Value{Value: 42}, |
| 1837 | OptUint32: &wrapperspb.UInt32Value{Value: 42}, |
| 1838 | OptUint64: &wrapperspb.UInt64Value{Value: 42}, |
| 1839 | OptFloat: &wrapperspb.FloatValue{Value: 1.23}, |
| 1840 | OptDouble: &wrapperspb.DoubleValue{Value: 3.1415}, |
| 1841 | OptString: &wrapperspb.StringValue{Value: "hello"}, |
| 1842 | OptBytes: &wrapperspb.BytesValue{Value: []byte("hello")}, |
| 1843 | OptDuration: &durationpb.Duration{Seconds: 123}, |
| 1844 | OptTimestamp: ×tamppb.Timestamp{Seconds: 1553036601}, |
| 1845 | OptStruct: &structpb.Struct{ |
| 1846 | Fields: map[string]*structpb.Value{ |
| 1847 | "string": {Kind: &structpb.Value_StringValue{"hello"}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1848 | }, |
| 1849 | }, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1850 | OptList: &structpb.ListValue{ |
| 1851 | Values: []*structpb.Value{ |
| 1852 | {Kind: &structpb.Value_NullValue{}}, |
| 1853 | {Kind: &structpb.Value_StringValue{}}, |
| 1854 | {Kind: &structpb.Value_StructValue{}}, |
| 1855 | {Kind: &structpb.Value_ListValue{}}, |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1856 | }, |
| 1857 | }, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1858 | OptValue: &structpb.Value{ |
| 1859 | Kind: &structpb.Value_StringValue{"world"}, |
Herbie Ong | 1c7462c | 2019-03-22 17:56:55 -0700 | [diff] [blame] | 1860 | }, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1861 | OptEmpty: &emptypb.Empty{}, |
| 1862 | OptAny: &anypb.Any{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1863 | TypeUrl: "google.protobuf.Empty", |
| 1864 | }, |
Joe Tsai | a95b29f | 2019-05-16 12:47:20 -0700 | [diff] [blame] | 1865 | OptFieldmask: &fieldmaskpb.FieldMask{ |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1866 | Paths: []string{"foo_bar", "bar_foo"}, |
| 1867 | }, |
| 1868 | }, |
| 1869 | want: `{ |
| 1870 | "optBool": false, |
| 1871 | "optInt32": 42, |
| 1872 | "optInt64": "42", |
| 1873 | "optUint32": 42, |
| 1874 | "optUint64": "42", |
| 1875 | "optFloat": 1.23, |
| 1876 | "optDouble": 3.1415, |
| 1877 | "optString": "hello", |
| 1878 | "optBytes": "aGVsbG8=", |
| 1879 | "optDuration": "123s", |
| 1880 | "optTimestamp": "2019-03-19T23:03:21Z", |
| 1881 | "optStruct": { |
| 1882 | "string": "hello" |
| 1883 | }, |
| 1884 | "optList": [ |
| 1885 | null, |
| 1886 | "", |
| 1887 | {}, |
| 1888 | [] |
| 1889 | ], |
Herbie Ong | 1c7462c | 2019-03-22 17:56:55 -0700 | [diff] [blame] | 1890 | "optValue": "world", |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1891 | "optEmpty": {}, |
| 1892 | "optAny": { |
Herbie Ong | 82014a5 | 2019-03-27 15:21:43 -0700 | [diff] [blame] | 1893 | "@type": "google.protobuf.Empty", |
| 1894 | "value": {} |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1895 | }, |
| 1896 | "optFieldmask": "fooBar,barFoo" |
| 1897 | }`, |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 1898 | }} |
| 1899 | |
| 1900 | for _, tt := range tests { |
| 1901 | tt := tt |
| 1902 | t.Run(tt.desc, func(t *testing.T) { |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1903 | // Use 2-space indentation on all MarshalOptions. |
| 1904 | tt.mo.Indent = " " |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 1905 | b, err := tt.mo.Marshal(tt.input) |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1906 | if err != nil && !tt.wantErr { |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 1907 | t.Errorf("Marshal() returned error: %v\n", err) |
| 1908 | } |
Herbie Ong | 0b0f403 | 2019-03-18 19:06:15 -0700 | [diff] [blame] | 1909 | if err == nil && tt.wantErr { |
| 1910 | t.Errorf("Marshal() got nil error, want error\n") |
| 1911 | } |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 1912 | got := string(b) |
| 1913 | if got != tt.want { |
| 1914 | t.Errorf("Marshal()\n<got>\n%v\n<want>\n%v\n", got, tt.want) |
Joe Tsai | 6dc168e | 2019-07-09 23:11:13 -0700 | [diff] [blame^] | 1915 | if diff := cmp.Diff(tt.want, got); diff != "" { |
Herbie Ong | 7b828bc | 2019-02-08 19:56:24 -0800 | [diff] [blame] | 1916 | t.Errorf("Marshal() diff -want +got\n%v\n", diff) |
| 1917 | } |
| 1918 | } |
| 1919 | }) |
| 1920 | } |
| 1921 | } |