| 710 | } |
| 711 | |
| 712 | func TestAsyncCallStateMatches(t *testing.T) { |
| 713 | mk := func(fn, ov string, args ...ref.Val) *asyncCallState { |
| 714 | return newAsyncCallState(1, fn, ov, args, nil) |
| 715 | } |
| 716 | base := mk("fn", "ov", types.Int(1), types.String("a")) |
| 717 | tests := []struct { |
| 718 | name string |
| 719 | other *asyncCallState |
| 720 | want bool |
| 721 | }{ |
| 722 | {"identical", mk("fn", "ov", types.Int(1), types.String("a")), true}, |
| 723 | {"diff function", mk("other", "ov", types.Int(1), types.String("a")), false}, |
| 724 | {"diff overload", mk("fn", "other", types.Int(1), types.String("a")), false}, |
| 725 | {"diff arg value", mk("fn", "ov", types.Int(2), types.String("a")), false}, |
| 726 | {"diff arity", mk("fn", "ov", types.Int(1)), false}, |
| 727 | } |
| 728 | for _, tc := range tests { |
| 729 | t.Run(tc.name, func(t *testing.T) { |
| 730 | if got := base.matches(1, tc.other.function, tc.other.overload, tc.other.argVals); got != tc.want { |
| 731 | t.Errorf("matches() = %v, wanted %v", got, tc.want) |
| 732 | } |
| 733 | }) |
| 734 | } |
| 735 | t.Run("nil receiver", func(t *testing.T) { |
| 736 | var nilState *asyncCallState |
| 737 | if nilState.matches(1, base.function, base.overload, base.argVals) { |
| 738 | t.Error("nil.matches() returned true") |
| 739 | } |
| 740 | }) |
| 741 | t.Run("NaN equivalence", func(t *testing.T) { |
| 742 | s1 := mk("fn", "ov", types.Double(math.NaN())) |
| 743 | s2 := mk("fn", "ov", types.Double(math.NaN())) |
| 744 | s3 := mk("fn", "ov", types.Double(1.23)) |
| 745 | |
| 746 | tests := []struct { |
| 747 | name string |
| 748 | state *asyncCallState |
| 749 | other *asyncCallState |
| 750 | want bool |
| 751 | }{ |
| 752 | {"NaN vs NaN", s1, s2, true}, |
| 753 | {"NaN vs non-NaN", s1, s3, false}, |
| 754 | {"non-NaN vs NaN", s3, s1, false}, |
| 755 | } |
| 756 | for _, tc := range tests { |
| 757 | t.Run(tc.name, func(t *testing.T) { |
| 758 | if got := tc.state.matches(1, tc.other.function, tc.other.overload, tc.other.argVals); got != tc.want { |
| 759 | t.Errorf("matches() = %v, wanted %v", got, tc.want) |
| 760 | } |
| 761 | }) |
| 762 | } |
| 763 | }) |
| 764 | } |
| 765 | |
| 766 | func TestExecutionFrameChildSharesAsyncContext(t *testing.T) { |
| 767 | ctx, cancel := context.WithCancel(context.Background()) |