| 515 | } |
| 516 | |
| 517 | func TestEqual(t *testing.T) { |
| 518 | type myType string |
| 519 | |
| 520 | mockT := new(testing.T) |
| 521 | var m map[string]interface{} |
| 522 | |
| 523 | cases := []struct { |
| 524 | expected interface{} |
| 525 | actual interface{} |
| 526 | result bool |
| 527 | remark string |
| 528 | }{ |
| 529 | {"Hello World", "Hello World", true, ""}, |
| 530 | {123, 123, true, ""}, |
| 531 | {123.5, 123.5, true, ""}, |
| 532 | {[]byte("Hello World"), []byte("Hello World"), true, ""}, |
| 533 | {nil, nil, true, ""}, |
| 534 | {int32(123), int32(123), true, ""}, |
| 535 | {uint64(123), uint64(123), true, ""}, |
| 536 | {myType("1"), myType("1"), true, ""}, |
| 537 | {&struct{}{}, &struct{}{}, true, "pointer equality is based on equality of underlying value"}, |
| 538 | |
| 539 | // Not expected to be equal |
| 540 | {m["bar"], "something", false, ""}, |
| 541 | {myType("1"), myType("2"), false, ""}, |
| 542 | |
| 543 | // A case that might be confusing, especially with numeric literals |
| 544 | {10, uint(10), false, ""}, |
| 545 | } |
| 546 | |
| 547 | for _, c := range cases { |
| 548 | t.Run(fmt.Sprintf("Equal(%#v, %#v)", c.expected, c.actual), func(t *testing.T) { |
| 549 | res := Equal(mockT, c.expected, c.actual) |
| 550 | |
| 551 | if res != c.result { |
| 552 | t.Errorf("Equal(%#v, %#v) should return %#v: %s", c.expected, c.actual, c.result, c.remark) |
| 553 | } |
| 554 | }) |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | func ptr(i int) *int { |
| 559 | return &i |