Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Update counter-example numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Jun 2, 2024
1 parent 03c8f46 commit a3fe290
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/errors/invariants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ func TestInvariants(t *testing.T) {

// Is implies HasType and As for errors with data
if Is(err, errorOfInterest) {
// This is false, see Counter-example 5
// This is false, see Counter-example 2
//require.False(t, Is(err, errorWithOtherData))
require.False(t, Is(err, withPayloadStructError{}))
require.True(t, HasType[withPayloadStructError](err))
var check withPayloadStructError
require.True(t, As(err, &check))
// This can be false, see Counter-example 6
// This can be false, see Counter-example 3
//require.Equal(t, errorOfInterest, check)
}

// HasType implies As for errors with data
if HasType[withPayloadStructError](err) {
// This can be false, see Counter-example 3
// This can be false, see Counter-example 1
//require.True(t, Is(err, errorOfInterest))
var check withPayloadStructError
require.True(t, As(err, &check))
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestInvariants(t *testing.T) {

// Is implies HasType and As for errors with data
if Is(err, errorOfInterest) {
// This is false, see Counter-example 5
// This is false, see Counter-example 2
//require.False(t, Is(err, errorWithOtherData))
require.False(t, Is(err, &withPayloadPtrError{}))
require.True(t, HasType[*withPayloadPtrError](err))
Expand All @@ -155,13 +155,13 @@ func TestInvariants(t *testing.T) {
})
var check *withPayloadPtrError
require.True(t, As(err, &check))
// This can be false, see Counter-example 6
// This can be false, see Counter-example 3
//require.Equal(t, *errorOfInterest, *check)
}

// HasType implies As for errors with data
if HasType[*withPayloadPtrError](err) {
//This can be false, see Counter-example 3
//This can be false, see Counter-example 1
//require.True(t, Is(err, errorOfInterest))
require.Panics(t, func() {
var check withPayloadPtrError
Expand All @@ -183,19 +183,19 @@ func TestInvariants(t *testing.T) {
})

t.Run("Counter-examples", func(t *testing.T) {
// Counter-example 3. HasType does not imply Is
// Counter-example 1. HasType does not imply Is
{
err := error(withPayloadStructError{data: 3})
require.True(t, HasType[withPayloadStructError](err))
require.False(t, Is(err, withPayloadStructError{data: 1}))
}
// Counter-example 5. Is can return true for distinct values
// Counter-example 2. Is can return true for distinct values
{
err := Append(withPayloadStructError{data: 3}, withPayloadStructError{data: 1})
require.True(t, Is(err, withPayloadStructError{data: 3}))
require.True(t, Is(err, withPayloadStructError{data: 1}))
}
// Counter-example 6. As can return a different value than the one passed to Is
// Counter-example 3. As can return a different value than the one passed to Is
{
err := Append(withPayloadStructError{data: 3}, withPayloadStructError{data: 1})
var check withPayloadStructError
Expand Down

0 comments on commit a3fe290

Please sign in to comment.