How to use String method of types Package

Best Ginkgo code snippet using types.String

util_test.go

Source:util_test.go Github

copy

Full Screen

...198 want: false,199 }}...)200 // Test IgnoreUnknown.201 raw := protopack.Message{202 protopack.Tag{1, protopack.BytesType}, protopack.String("Hello, goodbye!"),203 }.Marshal()204 tests = append(tests, []test{{205 x: apply(&testpb.TestAllTypes{OptionalSint64: proto.Int64(5)}, setUnknown{raw}),206 y: &testpb.TestAllTypes{OptionalSint64: proto.Int64(5)},207 opts: cmp.Options{Transform()},208 want: false,209 }, {210 x: apply(&testpb.TestAllTypes{OptionalSint64: proto.Int64(5)}, setUnknown{raw}),211 y: &testpb.TestAllTypes{OptionalSint64: proto.Int64(5)},212 opts: cmp.Options{Transform(), IgnoreUnknown()},213 want: true,214 }, {215 x: apply(&testpb.TestAllTypes{OptionalSint64: proto.Int64(5)}, setUnknown{raw}),216 y: &testpb.TestAllTypes{OptionalSint64: proto.Int64(6)},217 opts: cmp.Options{Transform(), IgnoreUnknown()},218 want: false,219 }, {220 x: apply(&testpb.TestAllTypes{OptionalSint64: proto.Int64(5)}, setUnknown{raw}),221 y: apply(dynamicpb.NewMessage(allTypesDesc), setField{6, int64(5)}),222 opts: cmp.Options{Transform()},223 want: false,224 }, {225 x: apply(&testpb.TestAllTypes{OptionalSint64: proto.Int64(5)}, setUnknown{raw}),226 y: apply(dynamicpb.NewMessage(allTypesDesc), setField{6, int64(5)}),227 opts: cmp.Options{Transform(), IgnoreUnknown()},228 want: true,229 }}...)230 // Test IgnoreDefaultScalars.231 tests = append(tests, []test{{232 x: &testpb.TestAllTypes{233 DefaultInt32: proto.Int32(81),234 DefaultUint32: proto.Uint32(83),235 DefaultFloat: proto.Float32(91.5),236 DefaultBool: proto.Bool(true),237 DefaultBytes: []byte("world"),238 },239 y: &testpb.TestAllTypes{240 DefaultInt64: proto.Int64(82),241 DefaultUint64: proto.Uint64(84),242 DefaultDouble: proto.Float64(92e3),243 DefaultString: proto.String("hello"),244 DefaultForeignEnum: testpb.ForeignEnum_FOREIGN_BAR.Enum(),245 },246 opts: cmp.Options{Transform()},247 want: false,248 }, {249 x: &testpb.TestAllTypes{250 DefaultInt32: proto.Int32(81),251 DefaultUint32: proto.Uint32(83),252 DefaultFloat: proto.Float32(91.5),253 DefaultBool: proto.Bool(true),254 DefaultBytes: []byte("world"),255 },256 y: &testpb.TestAllTypes{257 DefaultInt64: proto.Int64(82),258 DefaultUint64: proto.Uint64(84),259 DefaultDouble: proto.Float64(92e3),260 DefaultString: proto.String("hello"),261 DefaultForeignEnum: testpb.ForeignEnum_FOREIGN_BAR.Enum(),262 },263 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},264 want: true,265 }, {266 x: &testpb.TestAllTypes{267 OptionalInt32: proto.Int32(81),268 OptionalUint32: proto.Uint32(83),269 OptionalFloat: proto.Float32(91.5),270 OptionalBool: proto.Bool(true),271 OptionalBytes: []byte("world"),272 },273 y: &testpb.TestAllTypes{274 OptionalInt64: proto.Int64(82),275 OptionalUint64: proto.Uint64(84),276 OptionalDouble: proto.Float64(92e3),277 OptionalString: proto.String("hello"),278 OptionalForeignEnum: testpb.ForeignEnum_FOREIGN_BAR.Enum(),279 },280 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},281 want: false,282 }, {283 x: &testpb.TestAllTypes{284 OptionalInt32: proto.Int32(0),285 OptionalUint32: proto.Uint32(0),286 OptionalFloat: proto.Float32(0),287 OptionalBool: proto.Bool(false),288 OptionalBytes: []byte(""),289 },290 y: &testpb.TestAllTypes{291 OptionalInt64: proto.Int64(0),292 OptionalUint64: proto.Uint64(0),293 OptionalDouble: proto.Float64(0),294 OptionalString: proto.String(""),295 OptionalForeignEnum: testpb.ForeignEnum_FOREIGN_FOO.Enum(),296 },297 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},298 want: true,299 }, {300 x: apply(new(testpb.TestAllExtensions),301 setExtension{testpb.E_DefaultInt32, int32(81)},302 setExtension{testpb.E_DefaultUint32, uint32(83)},303 setExtension{testpb.E_DefaultFloat, float32(91.5)},304 setExtension{testpb.E_DefaultBool, bool(true)},305 setExtension{testpb.E_DefaultBytes, []byte("world")}),306 y: apply(new(testpb.TestAllExtensions),307 setExtension{testpb.E_DefaultInt64, int64(82)},308 setExtension{testpb.E_DefaultUint64, uint64(84)},309 setExtension{testpb.E_DefaultDouble, float64(92e3)},310 setExtension{testpb.E_DefaultString, string("hello")}),311 opts: cmp.Options{Transform()},312 want: false,313 }, {314 x: apply(new(testpb.TestAllExtensions),315 setExtension{testpb.E_DefaultInt32, int32(81)},316 setExtension{testpb.E_DefaultUint32, uint32(83)},317 setExtension{testpb.E_DefaultFloat, float32(91.5)},318 setExtension{testpb.E_DefaultBool, bool(true)},319 setExtension{testpb.E_DefaultBytes, []byte("world")}),320 y: apply(new(testpb.TestAllExtensions),321 setExtension{testpb.E_DefaultInt64, int64(82)},322 setExtension{testpb.E_DefaultUint64, uint64(84)},323 setExtension{testpb.E_DefaultDouble, float64(92e3)},324 setExtension{testpb.E_DefaultString, string("hello")}),325 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},326 want: true,327 }, {328 x: apply(new(testpb.TestAllExtensions),329 setExtension{testpb.E_OptionalInt32, int32(0)},330 setExtension{testpb.E_OptionalUint32, uint32(0)},331 setExtension{testpb.E_OptionalFloat, float32(0)},332 setExtension{testpb.E_OptionalBool, bool(false)},333 setExtension{testpb.E_OptionalBytes, []byte("")}),334 y: apply(new(testpb.TestAllExtensions),335 setExtension{testpb.E_OptionalInt64, int64(0)},336 setExtension{testpb.E_OptionalUint64, uint64(0)},337 setExtension{testpb.E_OptionalDouble, float64(0)},338 setExtension{testpb.E_OptionalString, string("")}),339 opts: cmp.Options{Transform()},340 want: false,341 }, {342 x: apply(new(testpb.TestAllExtensions),343 setExtension{testpb.E_OptionalInt32, int32(0)},344 setExtension{testpb.E_OptionalUint32, uint32(0)},345 setExtension{testpb.E_OptionalFloat, float32(0)},346 setExtension{testpb.E_OptionalBool, bool(false)},347 setExtension{testpb.E_OptionalBytes, []byte("")}),348 y: apply(new(testpb.TestAllExtensions),349 setExtension{testpb.E_OptionalInt64, int64(0)},350 setExtension{testpb.E_OptionalUint64, uint64(0)},351 setExtension{testpb.E_OptionalDouble, float64(0)},352 setExtension{testpb.E_OptionalString, string("")}),353 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},354 want: true,355 }, {356 x: &testpb.TestAllTypes{357 DefaultFloat: proto.Float32(91.6),358 },359 y: &testpb.TestAllTypes{},360 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},361 want: false,362 }, {363 x: &testpb.TestAllTypes{364 OptionalForeignMessage: &testpb.ForeignMessage{},365 },366 y: &testpb.TestAllTypes{},367 opts: cmp.Options{Transform(), IgnoreDefaultScalars()},368 want: false,369 }}...)370 // Test IgnoreEmptyMessages.371 tests = append(tests, []test{{372 x: []*testpb.TestAllTypes{nil, {}, {OptionalInt32: proto.Int32(5)}},373 y: []*testpb.TestAllTypes{nil, {}, {OptionalInt32: proto.Int32(5)}},374 opts: cmp.Options{Transform()},375 want: true,376 }, {377 x: []*testpb.TestAllTypes{nil, {}, {OptionalInt32: proto.Int32(5)}},378 y: []*testpb.TestAllTypes{{OptionalInt32: proto.Int32(5)}},379 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},380 want: false,381 }, {382 x: &testpb.TestAllTypes{OptionalForeignMessage: &testpb.ForeignMessage{}},383 y: &testpb.TestAllTypes{OptionalForeignMessage: nil},384 opts: cmp.Options{Transform()},385 want: false,386 }, {387 x: &testpb.TestAllTypes{OptionalForeignMessage: &testpb.ForeignMessage{}},388 y: &testpb.TestAllTypes{OptionalForeignMessage: nil},389 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},390 want: true,391 }, {392 x: &testpb.TestAllTypes{OptionalForeignMessage: &testpb.ForeignMessage{C: proto.Int32(5)}},393 y: &testpb.TestAllTypes{OptionalForeignMessage: nil},394 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},395 want: false,396 }, {397 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{}},398 y: &testpb.TestAllTypes{RepeatedForeignMessage: nil},399 opts: cmp.Options{Transform()},400 want: true,401 }, {402 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {}}},403 y: &testpb.TestAllTypes{RepeatedForeignMessage: nil},404 opts: cmp.Options{Transform()},405 want: false,406 }, {407 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {}}},408 y: &testpb.TestAllTypes{RepeatedForeignMessage: nil},409 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},410 want: true,411 }, {412 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(5)}, {}}},413 y: &testpb.TestAllTypes{RepeatedForeignMessage: nil},414 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},415 want: false,416 }, {417 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(5)}, {}}},418 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {}, nil, {}, {C: proto.Int32(5)}, {}}},419 opts: cmp.Options{Transform()},420 want: false,421 }, {422 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(5)}, {}}},423 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {}, nil, {}, {C: proto.Int32(5)}, {}}},424 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},425 want: true,426 }, {427 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{}},428 y: &testpb.TestAllTypes{MapStringNestedMessage: nil},429 opts: cmp.Options{Transform()},430 want: true,431 }, {432 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": nil, "2": {}}},433 y: &testpb.TestAllTypes{MapStringNestedMessage: nil},434 opts: cmp.Options{Transform()},435 want: false,436 }, {437 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": nil, "2": {}}},438 y: &testpb.TestAllTypes{MapStringNestedMessage: nil},439 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},440 want: true,441 }, {442 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": nil, "2": {A: proto.Int32(5)}, "3": {}}},443 y: &testpb.TestAllTypes{MapStringNestedMessage: nil},444 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},445 want: false,446 }, {447 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": nil, "2": {A: proto.Int32(5)}, "3": {}}},448 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": {}, "1a": {}, "1b": nil, "2": {A: proto.Int32(5)}, "4": {}}},449 opts: cmp.Options{Transform()},450 want: false,451 }, {452 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": nil, "2": {A: proto.Int32(5)}, "3": {}}},453 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"1": {}, "1a": {}, "1b": nil, "2": {A: proto.Int32(5)}, "4": {}}},454 opts: cmp.Options{Transform(), IgnoreEmptyMessages()},455 want: true,456 }}...)457 // Test IgnoreEnums and IgnoreMessages.458 tests = append(tests, []test{{459 x: &testpb.TestAllTypes{460 OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)},461 RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}},462 MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"3": {A: proto.Int32(3)}},463 },464 y: &testpb.TestAllTypes{},465 opts: cmp.Options{Transform()},466 want: false,467 }, {468 x: &testpb.TestAllTypes{469 OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)},470 RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}},471 MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"3": {A: proto.Int32(3)}},472 },473 y: &testpb.TestAllTypes{},474 opts: cmp.Options{Transform(), IgnoreMessages(&testpb.TestAllTypes{})},475 want: true,476 }, {477 x: &testpb.TestAllTypes{478 OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum(),479 RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR},480 MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"baz": testpb.TestAllTypes_BAZ},481 },482 y: &testpb.TestAllTypes{},483 opts: cmp.Options{Transform()},484 want: false,485 }, {486 x: &testpb.TestAllTypes{487 OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum(),488 RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR},489 MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"baz": testpb.TestAllTypes_BAZ},490 },491 y: &testpb.TestAllTypes{},492 opts: cmp.Options{Transform(), IgnoreEnums(testpb.TestAllTypes_NestedEnum(0))},493 want: true,494 }, {495 x: &testpb.TestAllTypes{496 OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum(),497 RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR},498 MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"baz": testpb.TestAllTypes_BAZ},499 OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)},500 RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}},501 MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"3": {A: proto.Int32(3)}},502 },503 y: &testpb.TestAllTypes{},504 opts: cmp.Options{Transform(),505 IgnoreMessages(&testpb.TestAllExtensions{}),506 IgnoreEnums(testpb.ForeignEnum(0)),507 },508 want: false,509 }}...)510 // Test IgnoreFields and IgnoreOneofs.511 tests = append(tests, []test{{512 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(5)},513 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(6)},514 opts: cmp.Options{Transform()},515 want: false,516 }, {517 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(5)},518 y: &testpb.TestAllTypes{},519 opts: cmp.Options{Transform(),520 IgnoreFields(&testpb.TestAllTypes{}, "optional_int32")},521 want: true,522 }, {523 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(5)},524 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(6)},525 opts: cmp.Options{Transform(),526 IgnoreFields(&testpb.TestAllTypes{}, "optional_int32")},527 want: true,528 }, {529 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(5)},530 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(6)},531 opts: cmp.Options{Transform(),532 IgnoreFields(&testpb.TestAllTypes{}, "optional_int64")},533 want: false,534 }, {535 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{5}},536 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofString{"5"}},537 opts: cmp.Options{Transform()},538 want: false,539 }, {540 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{5}},541 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofString{"5"}},542 opts: cmp.Options{Transform(),543 IgnoreFields(&testpb.TestAllTypes{}, "oneof_uint32"),544 IgnoreFields(&testpb.TestAllTypes{}, "oneof_string")},545 want: true,546 }, {547 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{5}},548 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofString{"5"}},549 opts: cmp.Options{Transform(),550 IgnoreOneofs(&testpb.TestAllTypes{}, "oneof_field")},551 want: true,552 }, {553 x: apply(new(testpb.TestAllExtensions),554 setExtension{testpb.E_OptionalString, "hello"}),555 y: apply(new(testpb.TestAllExtensions),556 setExtension{testpb.E_OptionalString, "goodbye"}),557 opts: cmp.Options{Transform()},558 want: false,559 }, {560 x: apply(new(testpb.TestAllExtensions),561 setExtension{testpb.E_OptionalString, "hello"}),562 y: new(testpb.TestAllExtensions),563 opts: cmp.Options{Transform(),564 IgnoreDescriptors(testpb.E_OptionalString.TypeDescriptor())},565 want: true,566 }, {567 x: apply(new(testpb.TestAllExtensions),568 setExtension{testpb.E_OptionalString, "hello"}),569 y: apply(new(testpb.TestAllExtensions),570 setExtension{testpb.E_OptionalString, "goodbye"}),571 opts: cmp.Options{Transform(),572 IgnoreDescriptors(testpb.E_OptionalString.TypeDescriptor())},573 want: true,574 }, {575 x: apply(new(testpb.TestAllExtensions),576 setExtension{testpb.E_OptionalString, "hello"}),577 y: apply(new(testpb.TestAllExtensions),578 setExtension{testpb.E_OptionalString, "goodbye"}),579 opts: cmp.Options{Transform(),580 IgnoreDescriptors(testpb.E_OptionalInt32.TypeDescriptor())},581 want: false,582 }}...)583 // Test FilterEnum.584 tests = append(tests, []test{{585 x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()},586 y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()},587 opts: cmp.Options{Transform()},588 want: false,589 }, {590 x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()},591 y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()},592 opts: cmp.Options{593 Transform(),594 FilterEnum(testpb.ForeignEnum(0), cmp.Comparer(func(x, y interface{}) bool { return true })),595 },596 want: false, // mismatching filter type597 }, {598 x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()},599 y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()},600 opts: cmp.Options{601 Transform(),602 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y int) bool { return true })),603 },604 want: false, // matching filter type, but mismatching comparer type605 }, {606 x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()},607 y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()},608 opts: cmp.Options{609 Transform(),610 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y testpb.TestAllTypes_NestedEnum) bool { return true })),611 },612 want: false, // matching filter type, but mismatching comparer type613 }, {614 x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()},615 y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()},616 opts: cmp.Options{617 Transform(),618 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y interface{}) bool { return true })),619 },620 want: true,621 }, {622 x: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_FOO.Enum()},623 y: &testpb.TestAllTypes{OptionalNestedEnum: testpb.TestAllTypes_BAR.Enum()},624 opts: cmp.Options{625 Transform(),626 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y Enum) bool { return true })),627 },628 want: true,629 }, {630 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}},631 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}},632 opts: cmp.Options{Transform()},633 want: false,634 }, {635 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}},636 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}},637 opts: cmp.Options{638 Transform(),639 FilterEnum(testpb.ForeignEnum(0), cmp.Comparer(func(x, y interface{}) bool { return true })),640 },641 want: false, // mismatching filter type642 }, {643 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}},644 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}},645 opts: cmp.Options{646 Transform(),647 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y int) bool { return true })),648 },649 want: false, // matching filter type, but mismatching comparer type650 }, {651 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}},652 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}},653 opts: cmp.Options{654 Transform(),655 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y []testpb.TestAllTypes_NestedEnum) bool { return true })),656 },657 want: false, // matching filter type, but mismatching comparer type658 }, {659 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}},660 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}},661 opts: cmp.Options{662 Transform(),663 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y interface{}) bool { return true })),664 },665 want: true,666 }, {667 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO}},668 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR}},669 opts: cmp.Options{670 Transform(),671 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y []Enum) bool { return true })),672 },673 want: true,674 }, {675 x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_FOO}},676 y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_BAR}},677 opts: cmp.Options{Transform()},678 want: false,679 }, {680 x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_FOO}},681 y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_BAR}},682 opts: cmp.Options{683 Transform(),684 FilterEnum(testpb.ForeignEnum(0), cmp.Comparer(func(x, y interface{}) bool { return true })),685 },686 want: false, // mismatching filter type687 }, {688 x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_FOO}},689 y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_BAR}},690 opts: cmp.Options{691 Transform(),692 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y int) bool { return true })),693 },694 want: false, // matching filter type, but mismatching comparer type695 }, {696 x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_FOO}},697 y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_BAR}},698 opts: cmp.Options{699 Transform(),700 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y map[string]testpb.TestAllTypes_NestedEnum) bool { return true })),701 },702 want: false, // matching filter type, but mismatching comparer type703 }, {704 x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_FOO}},705 y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_BAR}},706 opts: cmp.Options{707 Transform(),708 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y interface{}) bool { return true })),709 },710 want: true,711 }, {712 x: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_FOO}},713 y: &testpb.TestAllTypes{MapStringNestedEnum: map[string]testpb.TestAllTypes_NestedEnum{"k": testpb.TestAllTypes_BAR}},714 opts: cmp.Options{715 Transform(),716 FilterEnum(testpb.TestAllTypes_NestedEnum(0), cmp.Comparer(func(x, y map[string]Enum) bool { return true })),717 },718 want: true,719 }}...)720 // Test FilterMessage.721 tests = append(tests, []test{{722 x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)}},723 y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(2)}},724 opts: cmp.Options{Transform()},725 want: false,726 }, {727 x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)}},728 y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(2)}},729 opts: cmp.Options{730 Transform(),731 FilterMessage(new(testpb.TestAllExtensions), cmp.Comparer(func(x, y interface{}) bool { return true })),732 },733 want: false, // mismatching filter type734 }, {735 x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)}},736 y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(2)}},737 opts: cmp.Options{738 Transform(),739 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y int) bool { return true })),740 },741 want: false, // matching filter type, but mismatching comparer type742 }, {743 x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)}},744 y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(2)}},745 opts: cmp.Options{746 Transform(),747 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y *testpb.TestAllTypes_NestedMessage) bool { return true })),748 },749 want: false, // matching filter type, but mismatching comparer type750 }, {751 x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)}},752 y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(2)}},753 opts: cmp.Options{754 Transform(),755 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y interface{}) bool { return true })),756 },757 want: true,758 }, {759 x: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(1)}},760 y: &testpb.TestAllTypes{OptionalNestedMessage: &testpb.TestAllTypes_NestedMessage{A: proto.Int32(2)}},761 opts: cmp.Options{762 Transform(),763 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y Message) bool { return true })),764 },765 want: true,766 }, {767 x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(1)}}},768 y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}}},769 opts: cmp.Options{Transform()},770 want: false,771 }, {772 x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(1)}}},773 y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}}},774 opts: cmp.Options{775 Transform(),776 FilterMessage(new(testpb.TestAllExtensions), cmp.Comparer(func(x, y interface{}) bool { return true })),777 },778 want: false, // mismatching filter type779 }, {780 x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(1)}}},781 y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}}},782 opts: cmp.Options{783 Transform(),784 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y int) bool { return true })),785 },786 want: false, // matching filter type, but mismatching comparer type787 }, {788 x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(1)}}},789 y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}}},790 opts: cmp.Options{791 Transform(),792 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y []*testpb.TestAllTypes_NestedMessage) bool { return true })),793 },794 want: false, // matching filter type, but mismatching comparer type795 }, {796 x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(1)}}},797 y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}}},798 opts: cmp.Options{799 Transform(),800 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y interface{}) bool { return true })),801 },802 want: true,803 }, {804 x: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(1)}}},805 y: &testpb.TestAllTypes{RepeatedNestedMessage: []*testpb.TestAllTypes_NestedMessage{{A: proto.Int32(2)}}},806 opts: cmp.Options{807 Transform(),808 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y []Message) bool { return true })),809 },810 want: true,811 }, {812 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(1)}}},813 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(2)}}},814 opts: cmp.Options{Transform()},815 want: false,816 }, {817 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(1)}}},818 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(2)}}},819 opts: cmp.Options{820 Transform(),821 FilterMessage(new(testpb.TestAllExtensions), cmp.Comparer(func(x, y interface{}) bool { return true })),822 },823 want: false, // mismatching filter type824 }, {825 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(1)}}},826 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(2)}}},827 opts: cmp.Options{828 Transform(),829 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y int) bool { return true })),830 },831 want: false, // matching filter type, but mismatching comparer type832 }, {833 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(1)}}},834 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(2)}}},835 opts: cmp.Options{836 Transform(),837 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y map[string]*testpb.TestAllTypes_NestedMessage) bool { return true })),838 },839 want: false, // matching filter type, but mismatching comparer type840 }, {841 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(1)}}},842 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(2)}}},843 opts: cmp.Options{844 Transform(),845 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y interface{}) bool { return true })),846 },847 want: true,848 }, {849 x: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(1)}}},850 y: &testpb.TestAllTypes{MapStringNestedMessage: map[string]*testpb.TestAllTypes_NestedMessage{"k": {A: proto.Int32(2)}}},851 opts: cmp.Options{852 Transform(),853 FilterMessage(new(testpb.TestAllTypes_NestedMessage), cmp.Comparer(func(x, y map[string]Message) bool { return true })),854 },855 want: true,856 }}...)857 // Test FilterField.858 tests = append(tests, []test{{859 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(1)},860 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)},861 opts: cmp.Options{Transform()},862 want: false,863 }, {864 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(1)},865 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)},866 opts: cmp.Options{867 Transform(),868 FilterField(new(testpb.TestAllTypes), "optional_int64", cmp.Comparer(func(x, y interface{}) bool { return true })),869 },870 want: false, // mismatching filter name871 }, {872 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(1)},873 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)},874 opts: cmp.Options{875 Transform(),876 FilterField(new(testpb.TestAllTypes), "optional_int32", cmp.Comparer(func(x, y int64) bool { return true })),877 },878 want: false, // matching filter name, but mismatching comparer type879 }, {880 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(1)},881 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)},882 opts: cmp.Options{883 Transform(),884 FilterField(new(testpb.TestAllTypes), "optional_int32", cmp.Comparer(func(x, y interface{}) bool { return true })),885 },886 want: true,887 }, {888 x: &testpb.TestAllTypes{OptionalInt32: proto.Int32(1)},889 y: &testpb.TestAllTypes{OptionalInt32: proto.Int32(2)},890 opts: cmp.Options{891 Transform(),892 FilterField(new(testpb.TestAllTypes), "optional_int32", cmp.Comparer(func(x, y int32) bool { return true })),893 },894 want: true,895 }, {896 x: &testpb.TestAllTypes{RepeatedInt32: []int32{1}},897 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2}},898 opts: cmp.Options{Transform()},899 want: false,900 }, {901 x: &testpb.TestAllTypes{RepeatedInt32: []int32{1}},902 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2}},903 opts: cmp.Options{904 Transform(),905 FilterField(new(testpb.TestAllTypes), "repeated_int64", cmp.Comparer(func(x, y interface{}) bool { return true })),906 },907 want: false, // mismatching filter name908 }, {909 x: &testpb.TestAllTypes{RepeatedInt32: []int32{1}},910 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2}},911 opts: cmp.Options{912 Transform(),913 FilterField(new(testpb.TestAllTypes), "repeated_int32", cmp.Comparer(func(x, y []int64) bool { return true })),914 },915 want: false, // matching filter name, but mismatching comparer type916 }, {917 x: &testpb.TestAllTypes{RepeatedInt32: []int32{1}},918 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2}},919 opts: cmp.Options{920 Transform(),921 FilterField(new(testpb.TestAllTypes), "repeated_int32", cmp.Comparer(func(x, y interface{}) bool { return true })),922 },923 want: true,924 }, {925 x: &testpb.TestAllTypes{RepeatedInt32: []int32{1}},926 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2}},927 opts: cmp.Options{928 Transform(),929 FilterField(new(testpb.TestAllTypes), "repeated_int32", cmp.Comparer(func(x, y []int32) bool { return true })),930 },931 want: true,932 }, {933 x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 1}},934 y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{2: 2}},935 opts: cmp.Options{Transform()},936 want: false,937 }, {938 x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 1}},939 y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{2: 2}},940 opts: cmp.Options{941 Transform(),942 FilterField(new(testpb.TestAllTypes), "map_int64_int64", cmp.Comparer(func(x, y interface{}) bool { return true })),943 },944 want: false, // mismatching filter name945 }, {946 x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 1}},947 y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{2: 2}},948 opts: cmp.Options{949 Transform(),950 FilterField(new(testpb.TestAllTypes), "map_int32_int32", cmp.Comparer(func(x, y map[int64]int64) bool { return true })),951 },952 want: false, // matching filter name, but mismatching comparer type953 }, {954 x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 1}},955 y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{2: 2}},956 opts: cmp.Options{957 Transform(),958 FilterField(new(testpb.TestAllTypes), "map_int32_int32", cmp.Comparer(func(x, y interface{}) bool { return true })),959 },960 want: true,961 }, {962 x: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{1: 1}},963 y: &testpb.TestAllTypes{MapInt32Int32: map[int32]int32{2: 2}},964 opts: cmp.Options{965 Transform(),966 FilterField(new(testpb.TestAllTypes), "map_int32_int32", cmp.Comparer(func(x, y map[int32]int32) bool { return true })),967 },968 want: true,969 }}...)970 // Test FilterOneof971 tests = append(tests, []test{{972 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1}},973 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{2}},974 opts: cmp.Options{Transform()},975 want: false,976 }, {977 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1}},978 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{2}},979 opts: cmp.Options{980 Transform(),981 FilterOneof(new(testpb.TestAllTypes), "oneof_optional", cmp.Comparer(func(x, y interface{}) bool { return true })),982 },983 want: false, // mismatching filter name984 }, {985 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1}},986 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{2}},987 opts: cmp.Options{988 Transform(),989 FilterOneof(new(testpb.TestAllTypes), "oneof_field", cmp.Comparer(func(x, y string) bool { return true })),990 },991 want: false, // matching filter name, but mismatching comparer type992 }, {993 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1}},994 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{2}},995 opts: cmp.Options{996 Transform(),997 FilterOneof(new(testpb.TestAllTypes), "oneof_field", cmp.Comparer(func(x, y uint32) bool { return true })),998 },999 want: true,1000 }, {1001 x: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{1}},1002 y: &testpb.TestAllTypes{OneofField: &testpb.TestAllTypes_OneofUint32{2}},1003 opts: cmp.Options{1004 Transform(),1005 FilterOneof(new(testpb.TestAllTypes), "oneof_field", cmp.Comparer(func(x, y interface{}) bool { return true })),1006 },1007 want: true,1008 }}...)1009 // Test SortRepeated.1010 type higherOrderType struct {1011 M *testpb.TestAllTypes1012 I32s []int321013 Es []testpb.TestAllTypes_NestedEnum1014 Ms []*testpb.ForeignMessage1015 }1016 tests = append(tests, []test{{1017 x: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1018 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1019 opts: cmp.Options{Transform()},1020 want: false,1021 }, {1022 x: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1023 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1024 opts: cmp.Options{1025 Transform(),1026 SortRepeated(func(x, y int32) bool { return x < y }),1027 },1028 want: true,1029 }, {1030 x: higherOrderType{1031 M: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1032 I32s: []int32{3, 2, 1, 2, 3, 3},1033 },1034 y: higherOrderType{1035 M: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1036 I32s: []int32{2, 3, 3, 2, 1, 3},1037 },1038 opts: cmp.Options{1039 Transform(),1040 SortRepeated(func(x, y int32) bool { return x < y }),1041 },1042 want: false, // sort does not apply to []int32 outside of a message1043 }, {1044 x: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1045 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1046 opts: cmp.Options{1047 Transform(),1048 SortRepeated(func(x, y int64) bool { return x < y }),1049 },1050 want: false, // wrong sort type: int32 != int641051 }, {1052 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1053 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1054 opts: cmp.Options{Transform()},1055 want: false,1056 }, {1057 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1058 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1059 opts: cmp.Options{1060 Transform(),1061 SortRepeated(func(x, y testpb.TestAllTypes_NestedEnum) bool { return x < y }),1062 },1063 want: true,1064 }, {1065 x: higherOrderType{1066 M: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1067 Es: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ},1068 },1069 y: higherOrderType{1070 M: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1071 Es: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ},1072 },1073 opts: cmp.Options{1074 Transform(),1075 SortRepeated(func(x, y testpb.TestAllTypes_NestedEnum) bool { return x < y }),1076 },1077 want: false, // sort does not apply to []testpb.TestAllTypes_NestedEnum outside of a message1078 }, {1079 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1080 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1081 opts: cmp.Options{1082 Transform(),1083 SortRepeated(func(x, y testpb.ForeignEnum) bool { return x < y }),1084 },1085 want: false, // wrong sort type: testpb.TestAllTypes_NestedEnum != testpb.ForeignEnum1086 }, {1087 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1088 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1089 opts: cmp.Options{Transform()},1090 want: false,1091 }, {1092 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1093 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1094 opts: cmp.Options{1095 Transform(),1096 SortRepeated(func(x, y *testpb.ForeignMessage) bool { return x.GetC() < y.GetC() }),1097 },1098 want: true,1099 }, {1100 x: higherOrderType{1101 M: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1102 Ms: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}},1103 },1104 y: higherOrderType{1105 M: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1106 Ms: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}},1107 },1108 opts: cmp.Options{1109 Transform(),1110 SortRepeated(func(x, y *testpb.ForeignMessage) bool { return x.GetC() < y.GetC() }),1111 },1112 want: false, // sort does not apply to []*testpb.ForeignMessage outside of a message1113 }, {1114 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1115 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1116 opts: cmp.Options{1117 Transform(),1118 SortRepeated(func(x, y *testpb.TestAllTypes_NestedMessage) bool { return x.GetA() < y.GetA() }),1119 },1120 want: false, // wrong sort type: *testpb.ForeignMessage != *testpb.TestAllTypes_NestedMessage1121 }, {1122 x: &testpb.TestAllTypes{1123 RepeatedInt32: []int32{-32, +32},1124 RepeatedSint32: []int32{-32, +32},1125 RepeatedSfixed32: []int32{-32, +32},1126 RepeatedInt64: []int64{-64, +64},1127 RepeatedSint64: []int64{-64, +64},1128 RepeatedSfixed64: []int64{-64, +64},1129 RepeatedUint32: []uint32{0, 32},1130 RepeatedFixed32: []uint32{0, 32},1131 RepeatedUint64: []uint64{0, 64},1132 RepeatedFixed64: []uint64{0, 64},1133 },1134 y: &testpb.TestAllTypes{1135 RepeatedInt32: []int32{+32, -32},1136 RepeatedSint32: []int32{+32, -32},1137 RepeatedSfixed32: []int32{+32, -32},1138 RepeatedInt64: []int64{+64, -64},1139 RepeatedSint64: []int64{+64, -64},1140 RepeatedSfixed64: []int64{+64, -64},1141 RepeatedUint32: []uint32{32, 0},1142 RepeatedFixed32: []uint32{32, 0},1143 RepeatedUint64: []uint64{64, 0},1144 RepeatedFixed64: []uint64{64, 0},1145 },1146 opts: cmp.Options{1147 Transform(),1148 SortRepeated(func(x, y int32) bool { return x < y }),1149 SortRepeated(func(x, y int64) bool { return x < y }),1150 SortRepeated(func(x, y uint32) bool { return x < y }),1151 SortRepeated(func(x, y uint64) bool { return x < y }),1152 },1153 want: true,1154 }}...)1155 // Test SortRepeatedFields.1156 tests = append(tests, []test{{1157 x: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1158 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1159 opts: cmp.Options{Transform()},1160 want: false,1161 }, {1162 x: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1163 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1164 opts: cmp.Options{1165 Transform(),1166 SortRepeatedFields(new(testpb.TestAllTypes), "repeated_int32"),1167 },1168 want: true,1169 }, {1170 x: &testpb.TestAllTypes{RepeatedInt32: []int32{3, 2, 1, 2, 3, 3}},1171 y: &testpb.TestAllTypes{RepeatedInt32: []int32{2, 3, 3, 2, 1, 3}},1172 opts: cmp.Options{1173 Transform(),1174 SortRepeatedFields(new(testpb.TestAllTypes), "repeated_int64"),1175 },1176 want: false, // wrong field: repeated_int32 != repeated_int641177 }, {1178 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1179 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1180 opts: cmp.Options{Transform()},1181 want: false,1182 }, {1183 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1184 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1185 opts: cmp.Options{1186 Transform(),1187 SortRepeatedFields(new(testpb.TestAllTypes), "repeated_nested_enum"),1188 },1189 want: true,1190 }, {1191 x: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAR, testpb.TestAllTypes_BAZ}},1192 y: &testpb.TestAllTypes{RepeatedNestedEnum: []testpb.TestAllTypes_NestedEnum{testpb.TestAllTypes_BAR, testpb.TestAllTypes_FOO, testpb.TestAllTypes_BAZ}},1193 opts: cmp.Options{1194 Transform(),1195 SortRepeatedFields(new(testpb.TestAllTypes), "repeated_foreign_enum"),1196 },1197 want: false, // wrong field: repeated_nested_enum != repeated_foreign_enum1198 }, {1199 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1200 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1201 opts: cmp.Options{Transform()},1202 want: false,1203 }, {1204 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1205 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1206 opts: cmp.Options{1207 Transform(),1208 SortRepeatedFields(new(testpb.TestAllTypes), "repeated_foreign_message"),1209 },1210 want: true,1211 }, {1212 x: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{{}, {C: proto.Int32(3)}, nil, {C: proto.Int32(3)}, {C: proto.Int32(5)}, {C: proto.Int32(4)}}},1213 y: &testpb.TestAllTypes{RepeatedForeignMessage: []*testpb.ForeignMessage{nil, {C: proto.Int32(3)}, {}, {C: proto.Int32(4)}, {C: proto.Int32(3)}, {C: proto.Int32(5)}}},1214 opts: cmp.Options{1215 Transform(),1216 SortRepeatedFields(new(testpb.TestAllTypes), "repeated_nested_message"),1217 },1218 want: false, // wrong field: repeated_foreign_message != repeated_nested_message1219 }, {1220 x: &testpb.TestAllTypes{1221 RepeatedBool: []bool{false, true},1222 RepeatedInt32: []int32{-32, +32},1223 RepeatedInt64: []int64{-64, +64},1224 RepeatedUint32: []uint32{0, 32},1225 RepeatedUint64: []uint64{0, 64},1226 RepeatedFloat: []float32{-32.32, +32.32},1227 RepeatedDouble: []float64{-64.64, +64.64},1228 RepeatedString: []string{"hello", "world"},1229 RepeatedBytes: [][]byte{[]byte("hello"), []byte("world")},1230 RepeatedForeignEnum: []testpb.ForeignEnum{testpb.ForeignEnum_FOREIGN_FOO, testpb.ForeignEnum_FOREIGN_BAR},1231 RepeatedForeignMessage: []*testpb.ForeignMessage{{C: proto.Int32(-1)}, {C: proto.Int32(+1)}},1232 },1233 y: &testpb.TestAllTypes{1234 RepeatedBool: []bool{true, false},1235 RepeatedInt32: []int32{+32, -32},1236 RepeatedInt64: []int64{+64, -64},1237 RepeatedUint32: []uint32{32, 0},1238 RepeatedUint64: []uint64{64, 0},1239 RepeatedFloat: []float32{+32.32, -32.32},1240 RepeatedDouble: []float64{+64.64, -64.64},1241 RepeatedString: []string{"world", "hello"},1242 RepeatedBytes: [][]byte{[]byte("world"), []byte("hello")},1243 RepeatedForeignEnum: []testpb.ForeignEnum{testpb.ForeignEnum_FOREIGN_BAR, testpb.ForeignEnum_FOREIGN_FOO},1244 RepeatedForeignMessage: []*testpb.ForeignMessage{{C: proto.Int32(+1)}, {C: proto.Int32(-1)}},1245 },1246 opts: cmp.Options{1247 Transform(),1248 SortRepeatedFields(new(testpb.TestAllTypes),1249 "repeated_bool",1250 "repeated_int32",1251 "repeated_int64",1252 "repeated_uint32",1253 "repeated_uint64",1254 "repeated_float",1255 "repeated_double",...

Full Screen

Full Screen

parser.go

Source:parser.go Github

copy

Full Screen

...16)17type parser struct {18 scanner scanner.Scanner19 tok rune // current token20 lit string // literal string; only valid for Ident, Int, String tokens21 pkgpath string // package path of imported package22 pkgname string // name of imported package23 pkg *types.Package // reference to imported package24 imports map[string]*types.Package // package path -> package object25 typeMap map[int]types.Type // type number -> type26 initdata InitData // package init priority data27}28func (p *parser) init(filename string, src io.Reader, imports map[string]*types.Package) {29 p.scanner.Init(src)30 p.scanner.Error = func(_ *scanner.Scanner, msg string) { p.error(msg) }31 p.scanner.Mode = scanner.ScanIdents | scanner.ScanInts | scanner.ScanFloats | scanner.ScanStrings | scanner.ScanComments | scanner.SkipComments32 p.scanner.Whitespace = 1<<'\t' | 1<<'\n' | 1<<' '33 p.scanner.Filename = filename // for good error messages34 p.next()35 p.imports = imports36 p.typeMap = make(map[int]types.Type)37}38type importError struct {39 pos scanner.Position40 err error41}42func (e importError) Error() string {43 return fmt.Sprintf("import error %s (byte offset = %d): %s", e.pos, e.pos.Offset, e.err)44}45func (p *parser) error(err interface{}) {46 if s, ok := err.(string); ok {47 err = errors.New(s)48 }49 // panic with a runtime.Error if err is not an error50 panic(importError{p.scanner.Pos(), err.(error)})51}52func (p *parser) errorf(format string, args ...interface{}) {53 p.error(fmt.Errorf(format, args...))54}55func (p *parser) expect(tok rune) string {56 lit := p.lit57 if p.tok != tok {58 p.errorf("expected %s, got %s (%s)", scanner.TokenString(tok), scanner.TokenString(p.tok), lit)59 }60 p.next()61 return lit62}63func (p *parser) expectKeyword(keyword string) {64 lit := p.expect(scanner.Ident)65 if lit != keyword {66 p.errorf("expected keyword %s, got %q", keyword, lit)67 }68}69func (p *parser) parseString() string {70 str, err := strconv.Unquote(p.expect(scanner.String))71 if err != nil {72 p.error(err)73 }74 return str75}76// unquotedString = { unquotedStringChar } .77// unquotedStringChar = <neither a whitespace nor a ';' char> .78func (p *parser) parseUnquotedString() string {79 if p.tok == scanner.EOF {80 p.error("unexpected EOF")81 }82 var buf bytes.Buffer83 buf.WriteString(p.scanner.TokenText())84 // This loop needs to examine each character before deciding whether to consume it. If we see a semicolon,85 // we need to let it be consumed by p.next().86 for ch := p.scanner.Peek(); ch != ';' && ch != scanner.EOF && p.scanner.Whitespace&(1<<uint(ch)) == 0; ch = p.scanner.Peek() {87 buf.WriteRune(ch)88 p.scanner.Next()89 }90 p.next()91 return buf.String()92}93func (p *parser) next() {94 p.tok = p.scanner.Scan()95 switch p.tok {96 case scanner.Ident, scanner.Int, scanner.Float, scanner.String, '·':97 p.lit = p.scanner.TokenText()98 default:99 p.lit = ""100 }101}102func (p *parser) parseQualifiedName() (path, name string) {103 return p.parseQualifiedNameStr(p.parseString())104}105func (p *parser) parseUnquotedQualifiedName() (path, name string) {106 return p.parseQualifiedNameStr(p.parseUnquotedString())107}108// qualifiedName = [ ["."] unquotedString "." ] unquotedString .109//110// The above production uses greedy matching.111func (p *parser) parseQualifiedNameStr(unquotedName string) (pkgpath, name string) {112 parts := strings.Split(unquotedName, ".")113 if parts[0] == "" {114 parts = parts[1:]115 }116 switch len(parts) {117 case 0:118 p.errorf("malformed qualified name: %q", unquotedName)119 case 1:120 // unqualified name121 pkgpath = p.pkgpath122 name = parts[0]123 default:124 // qualified name, which may contain periods125 pkgpath = strings.Join(parts[0:len(parts)-1], ".")126 name = parts[len(parts)-1]127 }128 return129}130// getPkg returns the package for a given path. If the package is131// not found but we have a package name, create the package and132// add it to the p.imports map.133//134func (p *parser) getPkg(pkgpath, name string) *types.Package {135 // package unsafe is not in the imports map - handle explicitly136 if pkgpath == "unsafe" {137 return types.Unsafe138 }139 pkg := p.imports[pkgpath]140 if pkg == nil && name != "" {141 pkg = types.NewPackage(pkgpath, name)142 p.imports[pkgpath] = pkg143 }144 return pkg145}146// parseExportedName is like parseQualifiedName, but147// the package path is resolved to an imported *types.Package.148//149// ExportedName = string [string] .150func (p *parser) parseExportedName() (pkg *types.Package, name string) {151 path, name := p.parseQualifiedName()152 var pkgname string153 if p.tok == scanner.String {154 pkgname = p.parseString()155 }156 pkg = p.getPkg(path, pkgname)157 if pkg == nil {158 p.errorf("package %s (path = %q) not found", name, path)159 }160 return161}162// Name = QualifiedName | "?" .163func (p *parser) parseName() string {164 if p.tok == '?' {165 // Anonymous.166 p.next()167 return ""168 }169 // The package path is redundant for us. Don't try to parse it.170 _, name := p.parseUnquotedQualifiedName()171 return name172}173func deref(typ types.Type) types.Type {174 if p, _ := typ.(*types.Pointer); p != nil {175 typ = p.Elem()176 }177 return typ178}179// Field = Name Type [string] .180func (p *parser) parseField(pkg *types.Package) (field *types.Var, tag string) {181 name := p.parseName()182 typ := p.parseType(pkg)183 anon := false184 if name == "" {185 anon = true186 switch typ := deref(typ).(type) {187 case *types.Basic:188 name = typ.Name()189 case *types.Named:190 name = typ.Obj().Name()191 default:192 p.error("anonymous field expected")193 }194 }195 field = types.NewField(token.NoPos, pkg, name, typ, anon)196 if p.tok == scanner.String {197 tag = p.parseString()198 }199 return200}201// Param = Name ["..."] Type .202func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bool) {203 name := p.parseName()204 if p.tok == '.' {205 p.next()206 p.expect('.')207 p.expect('.')208 isVariadic = true209 }210 typ := p.parseType(pkg)211 if isVariadic {212 typ = types.NewSlice(typ)213 }214 param = types.NewParam(token.NoPos, pkg, name, typ)215 return216}217// Var = Name Type .218func (p *parser) parseVar(pkg *types.Package) *types.Var {219 name := p.parseName()220 return types.NewVar(token.NoPos, pkg, name, p.parseType(pkg))221}222// ConstValue = string | "false" | "true" | ["-"] (int ["'"] | FloatOrComplex) .223// FloatOrComplex = float ["i" | ("+"|"-") float "i"] .224func (p *parser) parseConstValue() (val exact.Value, typ types.Type) {225 switch p.tok {226 case scanner.String:227 str := p.parseString()228 val = exact.MakeString(str)229 typ = types.Typ[types.UntypedString]230 return231 case scanner.Ident:232 b := false233 switch p.lit {234 case "false":235 case "true":236 b = true237 default:238 p.errorf("expected const value, got %s (%q)", scanner.TokenString(p.tok), p.lit)239 }240 p.next()241 val = exact.MakeBool(b)242 typ = types.Typ[types.UntypedBool]243 return244 }245 sign := ""246 if p.tok == '-' {247 p.next()248 sign = "-"249 }250 switch p.tok {251 case scanner.Int:252 val = exact.MakeFromLiteral(sign+p.lit, token.INT)253 if val == nil {254 p.error("could not parse integer literal")255 }256 p.next()257 if p.tok == '\'' {258 p.next()259 typ = types.Typ[types.UntypedRune]260 } else {261 typ = types.Typ[types.UntypedInt]262 }263 case scanner.Float:264 re := sign + p.lit265 p.next()266 var im string267 switch p.tok {268 case '+':269 p.next()270 im = p.expect(scanner.Float)271 case '-':272 p.next()273 im = "-" + p.expect(scanner.Float)274 case scanner.Ident:275 // re is in fact the imaginary component. Expect "i" below.276 im = re277 re = "0"278 default:279 val = exact.MakeFromLiteral(re, token.FLOAT)280 if val == nil {281 p.error("could not parse float literal")282 }283 typ = types.Typ[types.UntypedFloat]284 return285 }286 p.expectKeyword("i")287 reval := exact.MakeFromLiteral(re, token.FLOAT)288 if reval == nil {289 p.error("could not parse real component of complex literal")290 }291 imval := exact.MakeFromLiteral(im+"i", token.IMAG)292 if imval == nil {293 p.error("could not parse imag component of complex literal")294 }295 val = exact.BinaryOp(reval, token.ADD, imval)296 typ = types.Typ[types.UntypedComplex]297 default:298 p.errorf("expected const value, got %s (%q)", scanner.TokenString(p.tok), p.lit)299 }300 return301}302// Const = Name [Type] "=" ConstValue .303func (p *parser) parseConst(pkg *types.Package) *types.Const {304 name := p.parseName()305 var typ types.Type306 if p.tok == '<' {307 typ = p.parseType(pkg)308 }309 p.expect('=')310 val, vtyp := p.parseConstValue()311 if typ == nil {312 typ = vtyp313 }314 return types.NewConst(token.NoPos, pkg, name, typ, val)315}316// TypeName = ExportedName .317func (p *parser) parseTypeName() *types.TypeName {318 pkg, name := p.parseExportedName()319 scope := pkg.Scope()320 if obj := scope.Lookup(name); obj != nil {321 return obj.(*types.TypeName)322 }323 obj := types.NewTypeName(token.NoPos, pkg, name, nil)324 // a named type may be referred to before the underlying type325 // is known - set it up326 types.NewNamed(obj, nil, nil)327 scope.Insert(obj)328 return obj329}330// NamedType = TypeName Type { Method } .331// Method = "func" "(" Param ")" Name ParamList ResultList ";" .332func (p *parser) parseNamedType(n int) types.Type {333 obj := p.parseTypeName()334 pkg := obj.Pkg()335 typ := obj.Type()336 p.typeMap[n] = typ337 nt, ok := typ.(*types.Named)338 if !ok {339 // This can happen for unsafe.Pointer, which is a TypeName holding a Basic type.340 pt := p.parseType(pkg)341 if pt != typ {342 p.error("unexpected underlying type for non-named TypeName")343 }344 return typ345 }346 underlying := p.parseType(pkg)347 if nt.Underlying() == nil {348 nt.SetUnderlying(underlying.Underlying())349 }350 for p.tok == scanner.Ident {351 // collect associated methods352 p.expectKeyword("func")353 p.expect('(')354 receiver, _ := p.parseParam(pkg)355 p.expect(')')356 name := p.parseName()357 params, isVariadic := p.parseParamList(pkg)358 results := p.parseResultList(pkg)359 p.expect(';')360 sig := types.NewSignature(pkg.Scope(), receiver, params, results, isVariadic)361 nt.AddMethod(types.NewFunc(token.NoPos, pkg, name, sig))362 }363 return nt364}365func (p *parser) parseInt() int64 {366 lit := p.expect(scanner.Int)367 n, err := strconv.ParseInt(lit, 10, 0)368 if err != nil {369 p.error(err)370 }371 return n372}373// ArrayOrSliceType = "[" [ int ] "]" Type .374func (p *parser) parseArrayOrSliceType(pkg *types.Package) types.Type {375 p.expect('[')376 if p.tok == ']' {377 p.next()378 return types.NewSlice(p.parseType(pkg))379 }380 n := p.parseInt()381 p.expect(']')382 return types.NewArray(p.parseType(pkg), n)383}384// MapType = "map" "[" Type "]" Type .385func (p *parser) parseMapType(pkg *types.Package) types.Type {386 p.expectKeyword("map")387 p.expect('[')388 key := p.parseType(pkg)389 p.expect(']')390 elem := p.parseType(pkg)391 return types.NewMap(key, elem)392}393// ChanType = "chan" ["<-" | "-<"] Type .394func (p *parser) parseChanType(pkg *types.Package) types.Type {395 p.expectKeyword("chan")396 dir := types.SendRecv397 switch p.tok {398 case '-':399 p.next()400 p.expect('<')401 dir = types.SendOnly402 case '<':403 // don't consume '<' if it belongs to Type404 if p.scanner.Peek() == '-' {405 p.next()406 p.expect('-')407 dir = types.RecvOnly408 }409 }410 return types.NewChan(dir, p.parseType(pkg))411}412// StructType = "struct" "{" { Field } "}" .413func (p *parser) parseStructType(pkg *types.Package) types.Type {414 p.expectKeyword("struct")415 var fields []*types.Var416 var tags []string417 p.expect('{')418 for p.tok != '}' && p.tok != scanner.EOF {419 field, tag := p.parseField(pkg)420 p.expect(';')421 fields = append(fields, field)422 tags = append(tags, tag)423 }424 p.expect('}')425 return types.NewStruct(fields, tags)426}427// ParamList = "(" [ { Parameter "," } Parameter ] ")" .428func (p *parser) parseParamList(pkg *types.Package) (*types.Tuple, bool) {429 var list []*types.Var430 isVariadic := false431 p.expect('(')432 for p.tok != ')' && p.tok != scanner.EOF {433 if len(list) > 0 {434 p.expect(',')435 }436 par, variadic := p.parseParam(pkg)437 list = append(list, par)438 if variadic {439 if isVariadic {440 p.error("... not on final argument")441 }442 isVariadic = true443 }444 }445 p.expect(')')446 return types.NewTuple(list...), isVariadic447}448// ResultList = Type | ParamList .449func (p *parser) parseResultList(pkg *types.Package) *types.Tuple {450 switch p.tok {451 case '<':452 return types.NewTuple(types.NewParam(token.NoPos, pkg, "", p.parseType(pkg)))453 case '(':454 params, _ := p.parseParamList(pkg)455 return params456 default:457 return nil458 }459}460// FunctionType = ParamList ResultList .461func (p *parser) parseFunctionType(pkg *types.Package) *types.Signature {462 params, isVariadic := p.parseParamList(pkg)463 results := p.parseResultList(pkg)464 return types.NewSignature(pkg.Scope(), nil, params, results, isVariadic)465}466// Func = Name FunctionType .467func (p *parser) parseFunc(pkg *types.Package) *types.Func {468 name := p.parseName()469 if strings.ContainsRune(name, '$') {470 // This is a Type$equal or Type$hash function, which we don't want to parse,471 // except for the types.472 p.discardDirectiveWhileParsingTypes(pkg)473 return nil474 }475 return types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg))476}477// InterfaceType = "interface" "{" { ("?" Type | Func) ";" } "}" .478func (p *parser) parseInterfaceType(pkg *types.Package) types.Type {479 p.expectKeyword("interface")480 var methods []*types.Func481 var typs []*types.Named482 p.expect('{')483 for p.tok != '}' && p.tok != scanner.EOF {484 if p.tok == '?' {485 p.next()486 typs = append(typs, p.parseType(pkg).(*types.Named))487 } else {488 method := p.parseFunc(pkg)489 methods = append(methods, method)490 }491 p.expect(';')492 }493 p.expect('}')494 return types.NewInterface(methods, typs)495}496// PointerType = "*" ("any" | Type) .497func (p *parser) parsePointerType(pkg *types.Package) types.Type {498 p.expect('*')499 if p.tok == scanner.Ident {500 p.expectKeyword("any")501 return types.Typ[types.UnsafePointer]502 }503 return types.NewPointer(p.parseType(pkg))504}505// TypeDefinition = NamedType | MapType | ChanType | StructType | InterfaceType | PointerType | ArrayOrSliceType | FunctionType .506func (p *parser) parseTypeDefinition(pkg *types.Package, n int) types.Type {507 var t types.Type508 switch p.tok {509 case scanner.String:510 t = p.parseNamedType(n)511 case scanner.Ident:512 switch p.lit {513 case "map":514 t = p.parseMapType(pkg)515 case "chan":516 t = p.parseChanType(pkg)517 case "struct":518 t = p.parseStructType(pkg)519 case "interface":520 t = p.parseInterfaceType(pkg)521 }522 case '*':523 t = p.parsePointerType(pkg)524 case '[':525 t = p.parseArrayOrSliceType(pkg)526 case '(':527 t = p.parseFunctionType(pkg)528 }529 p.typeMap[n] = t530 return t531}532const (533 // From gofrontend/go/export.h534 // Note that these values are negative in the gofrontend and have been made positive535 // in the gccgoimporter.536 gccgoBuiltinINT8 = 1537 gccgoBuiltinINT16 = 2538 gccgoBuiltinINT32 = 3539 gccgoBuiltinINT64 = 4540 gccgoBuiltinUINT8 = 5541 gccgoBuiltinUINT16 = 6542 gccgoBuiltinUINT32 = 7543 gccgoBuiltinUINT64 = 8544 gccgoBuiltinFLOAT32 = 9545 gccgoBuiltinFLOAT64 = 10546 gccgoBuiltinINT = 11547 gccgoBuiltinUINT = 12548 gccgoBuiltinUINTPTR = 13549 gccgoBuiltinBOOL = 15550 gccgoBuiltinSTRING = 16551 gccgoBuiltinCOMPLEX64 = 17552 gccgoBuiltinCOMPLEX128 = 18553 gccgoBuiltinERROR = 19554 gccgoBuiltinBYTE = 20555 gccgoBuiltinRUNE = 21556)557func lookupBuiltinType(typ int) types.Type {558 return [...]types.Type{559 gccgoBuiltinINT8: types.Typ[types.Int8],560 gccgoBuiltinINT16: types.Typ[types.Int16],561 gccgoBuiltinINT32: types.Typ[types.Int32],562 gccgoBuiltinINT64: types.Typ[types.Int64],563 gccgoBuiltinUINT8: types.Typ[types.Uint8],564 gccgoBuiltinUINT16: types.Typ[types.Uint16],565 gccgoBuiltinUINT32: types.Typ[types.Uint32],566 gccgoBuiltinUINT64: types.Typ[types.Uint64],567 gccgoBuiltinFLOAT32: types.Typ[types.Float32],568 gccgoBuiltinFLOAT64: types.Typ[types.Float64],569 gccgoBuiltinINT: types.Typ[types.Int],570 gccgoBuiltinUINT: types.Typ[types.Uint],571 gccgoBuiltinUINTPTR: types.Typ[types.Uintptr],572 gccgoBuiltinBOOL: types.Typ[types.Bool],573 gccgoBuiltinSTRING: types.Typ[types.String],574 gccgoBuiltinCOMPLEX64: types.Typ[types.Complex64],575 gccgoBuiltinCOMPLEX128: types.Typ[types.Complex128],576 gccgoBuiltinERROR: types.Universe.Lookup("error").Type(),577 gccgoBuiltinBYTE: types.Typ[types.Byte],578 gccgoBuiltinRUNE: types.Typ[types.Rune],579 }[typ]580}581// Type = "<" "type" ( "-" int | int [ TypeDefinition ] ) ">" .582func (p *parser) parseType(pkg *types.Package) (t types.Type) {583 p.expect('<')584 p.expectKeyword("type")585 switch p.tok {586 case scanner.Int:587 n := p.parseInt()588 if p.tok == '>' {589 t = p.typeMap[int(n)]590 } else {591 t = p.parseTypeDefinition(pkg, int(n))592 }593 case '-':594 p.next()595 n := p.parseInt()596 t = lookupBuiltinType(int(n))597 default:598 p.errorf("expected type number, got %s (%q)", scanner.TokenString(p.tok), p.lit)599 return nil600 }601 p.expect('>')602 return603}604// PackageInit = unquotedString unquotedString int .605func (p *parser) parsePackageInit() PackageInit {606 name := p.parseUnquotedString()607 initfunc := p.parseUnquotedString()608 priority := int(p.parseInt())609 return PackageInit{Name: name, InitFunc: initfunc, Priority: priority}610}611// Throw away tokens until we see a ';'. If we see a '<', attempt to parse as a type.612func (p *parser) discardDirectiveWhileParsingTypes(pkg *types.Package) {613 for {614 switch p.tok {615 case ';':616 return617 case '<':618 p.parseType(p.pkg)619 case scanner.EOF:620 p.error("unexpected EOF")621 default:622 p.next()623 }624 }625}626// Create the package if we have parsed both the package path and package name.627func (p *parser) maybeCreatePackage() {628 if p.pkgname != "" && p.pkgpath != "" {629 p.pkg = p.getPkg(p.pkgpath, p.pkgname)630 }631}632// InitDataDirective = "v1" ";" |633// "priority" int ";" |634// "init" { PackageInit } ";" |635// "checksum" unquotedString ";" .636func (p *parser) parseInitDataDirective() {637 if p.tok != scanner.Ident {638 // unexpected token kind; panic639 p.expect(scanner.Ident)640 }641 switch p.lit {642 case "v1":643 p.next()644 p.expect(';')645 case "priority":646 p.next()647 p.initdata.Priority = int(p.parseInt())648 p.expect(';')649 case "init":650 p.next()651 for p.tok != ';' && p.tok != scanner.EOF {652 p.initdata.Inits = append(p.initdata.Inits, p.parsePackageInit())653 }654 p.expect(';')655 case "checksum":656 // Don't let the scanner try to parse the checksum as a number.657 defer func(mode uint) {658 p.scanner.Mode = mode659 }(p.scanner.Mode)660 p.scanner.Mode &^= scanner.ScanInts | scanner.ScanFloats661 p.next()662 p.parseUnquotedString()663 p.expect(';')664 default:665 p.errorf("unexpected identifier: %q", p.lit)666 }667}668// Directive = InitDataDirective |669// "package" unquotedString ";" |670// "pkgpath" unquotedString ";" |671// "import" unquotedString unquotedString string ";" |672// "func" Func ";" |673// "type" Type ";" |674// "var" Var ";" |675// "const" Const ";" .676func (p *parser) parseDirective() {677 if p.tok != scanner.Ident {678 // unexpected token kind; panic679 p.expect(scanner.Ident)680 }681 switch p.lit {682 case "v1", "priority", "init", "checksum":683 p.parseInitDataDirective()684 case "package":685 p.next()686 p.pkgname = p.parseUnquotedString()687 p.maybeCreatePackage()688 p.expect(';')689 case "pkgpath":690 p.next()691 p.pkgpath = p.parseUnquotedString()692 p.maybeCreatePackage()693 p.expect(';')694 case "import":695 p.next()696 pkgname := p.parseUnquotedString()697 pkgpath := p.parseUnquotedString()698 p.getPkg(pkgpath, pkgname)699 p.parseString()700 p.expect(';')701 case "func":702 p.next()703 fun := p.parseFunc(p.pkg)704 if fun != nil {705 p.pkg.Scope().Insert(fun)706 }707 p.expect(';')708 case "type":709 p.next()710 p.parseType(p.pkg)711 p.expect(';')712 case "var":713 p.next()...

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Person struct {3}4func (p Person) String() string {5 return fmt.Sprintf("%v (%v years)", p.name, p.age)6}7func main() {8 a := Person{"Arthur Dent", 42}9 z := Person{"Zaphod Beeblebrox", 9001}10 fmt.Println(a, z)11}12Arthur Dent (42 years) Zaphod Beeblebrox (9001 years)13import "fmt"14type Person struct {15}16func (p Person) String() string {17 return fmt.Sprintf("%v (%v years)", p.name, p.age)18}19func main() {20 a := Person{"Arthur Dent", 42}21 z := Person{"Zaphod Beeblebrox", 9001}22 fmt.Println(a, z)23}24Arthur Dent (42 years) Zaphod Beeblebrox (9001 years)25import "fmt"26type Person struct {27}28func (p Person) String() string {29 return fmt.Sprintf("%v (%v years)", p.name, p.age)30}31func main() {32 a := Person{"Arthur Dent", 42}33 z := Person{"Zaphod Beeblebrox", 9001}34 fmt.Println(a, z)35}36Arthur Dent (42 years) Zaphod Beeblebrox (9001 years)37import "fmt"38type Person struct {39}40func (p Person) String() string {41 return fmt.Sprintf("%v (%v years)", p.name, p.age)42}43func main() {44 a := Person{"Arthur Dent", 42}45 z := Person{"Zaphod Beeblebrox", 9001}46 fmt.Println(a, z)47}48Arthur Dent (42 years) Zaphod Beeblebrox (9001 years)49import "fmt

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import (2func (i MyInt) String() string {3 return strconv.Itoa(int(i))4}5func main() {6 fmt.Println(i)7}8import (9func (i MyInt) String() string {10 return strconv.Itoa(int(i))11}12func main() {13 fmt.Println(i + 5)14}15import (16func (i MyInt) String() string {17 return strconv.Itoa(int(i))18}19func main() {20 fmt.Println(i + 5)21 fmt.Printf("%T22}23import (24func (i MyInt) String() string {25 return strconv.Itoa(int(i))26}27func main() {28 fmt.Println(i + 5)29 fmt.Printf("%T30 fmt.Printf("%T31", i.String())32}33import (34func (i MyInt) String() string {35 return strconv.Itoa(int(i))36}37func main() {38 fmt.Println(i + 5)39 fmt.Printf("%T40 fmt.Printf("%T41", i.String())42 fmt.Println(i.String() + "5")43}44import (45func (i MyInt) String() string {46 return strconv.Itoa(int(i))47}48func main() {49 fmt.Println(i + 5)50 fmt.Printf("%T51 fmt.Printf("%T52", i.String())53 fmt.Println(i.String() + "5")54 fmt.Printf("%T55}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import "fmt"2type types struct {3}4func (t types) String() string {5 return fmt.Sprintf("%d %s", t.n, t.s)6}7func main() {8 t := types{7, "abc"}9 fmt.Println(t)10}11type Stringer interface {12 String() string13}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func (p Person) String() string {5 return fmt.Sprintf("First Name: %v, Last Name: %v, Age: %v", p.First, p.Last, p.Age)6}7func main() {8 p1 := Person{"James", "Bond", 20}9 fmt.Println(p1)10}11type Stringer interface {12 String() string13}14import (15type Person struct {16}17func (p Person) String() string {18 return fmt.Sprintf("First Name: %v, Last Name: %v, Age: %v", p.First, p.Last, p.Age)19}20func main() {21 p1 := Person{"James", "Bond", 20}22 fmt.Println(p1)23}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import "fmt"2func (str MyString) String() string {3 return "MyString is " + string(str)4}5func main() {6 str := MyString("hello")7 fmt.Println(str)8}9import "fmt"10func (str MyString) String() string {11 return "MyString is " + string(str)12}13func main() {14 str := MyString("hello")15 fmt.Println(str)16 fmt.Printf("%s", str)17}18import "fmt"19func (str MyString) String() string {20 return "MyString is " + string(str)21}22func main() {23 str := MyString("hello")24 fmt.Println(str)25 fmt.Printf("%s", str)26 fmt.Printf("%v", str)27}28import "fmt"29func (str MyString) String() string {30 return "MyString is " + string(str)31}32func main() {33 str := MyString("hello")34 fmt.Println(str)35 fmt.Printf("%s", str)36 fmt.Printf("%v", str)37 fmt.Printf("%q", str)38}39import "fmt"40func (str MyString) String() string {41 return "MyString is " + string(str)42}43func main() {44 str := MyString("hello")45 fmt.Println(str)46 fmt.Printf("%s", str)47 fmt.Printf("%v", str)48 fmt.Printf("%q", str)49 fmt.Printf("%x", str)50}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import (2func (p Path) String() string {3 return fmt.Sprintf("Path is %s", p)4}5func main() {6 p := Path{"usr", "local", "bin"}7 fmt.Println(p)8}9import (10func (p Path) String() string {11 return fmt.Sprintf("Path is %s", p)12}13func main() {14 p := Path{"usr", "local", "bin"}15 fmt.Println(p.String())16}17import (18func (p Path) String() string {19 return fmt.Sprintf("Path is %s", p)20}21func main() {22 p := Path{"usr", "local", "bin"}23 fmt.Printf("%s", p)24}25import (26func (p Path) String() string {27 return fmt.Sprintf("Path is %s", p)28}29func main() {30 p := Path{"usr", "local", "bin"}31 fmt.Printf("%v", p)32}33import (34func (p Path) String() string {35 return fmt.Sprintf("Path is %s", p)36}37func main() {38 p := Path{"usr", "local", "bin"}39 fmt.Printf("%+v", p)40}41import (42func (p Path) String() string {43 return fmt.Sprintf("Path is %s", p)44}45func main() {46 p := Path{"usr", "local", "bin"}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, world")4 fmt.Println(1)5 fmt.Println(1.2)6 fmt.Println(true)7 fmt.Println('a')8 fmt.Println("a")9}10import "fmt"11func main() {12 fmt.Printf("Hello, world13 fmt.Printf("%v14 fmt.Printf("%v15 fmt.Printf("%v16 fmt.Printf("%v17 fmt.Printf("%v18}19import "fmt"20func main() {21 fmt.Printf("%v22 fmt.Printf("%v23 fmt.Printf("%v24 fmt.Printf("%v25 fmt.Printf("%v26 fmt.Printf("%v27}28import "fmt"29func main() {30 fmt.Printf("%s31 fmt.Printf("%s32 fmt.Printf("%s33 fmt.Printf("%s34 fmt.Printf("%s35 fmt.Printf("%s36}37import "fmt"38func main() {39 fmt.Printf("%q40 fmt.Printf("%q41 fmt.Printf("%q42 fmt.Printf("%q43 fmt.Printf("%q44 fmt.Printf("%q45}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import (2type types struct {3}4func (t types) String() string {5 return fmt.Sprintf("Hi I am %s", t.name)6}7func main() {8 t := types{"Rahul"}9 fmt.Println(t)10}11import (12type types struct {13}14func (t *types) String() string {15 return fmt.Sprintf("Hi I am %s", t.name)16}17func main() {18 t := &types{"Rahul"}19 fmt.Println(t)20}21The String() method of the types class is used to print the value of the types

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful