|
| 1 | +package f_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/pellared/fluentassert/f" |
| 7 | +) |
| 8 | + |
| 9 | +func TestComparable(t *testing.T) { |
| 10 | + type A struct { |
| 11 | + Str string |
| 12 | + Bool bool |
| 13 | + } |
| 14 | + |
| 15 | + t.Run("Equal", func(t *testing.T) { |
| 16 | + t.Run("Passed", func(t *testing.T) { |
| 17 | + want := A{Str: "string", Bool: true} |
| 18 | + got := A{Str: "string", Bool: true} |
| 19 | + msg := f.Comparable(got).Equal(want) |
| 20 | + assertPassed(t, msg) |
| 21 | + }) |
| 22 | + t.Run("Failed", func(t *testing.T) { |
| 23 | + want := A{Str: "string", Bool: true} |
| 24 | + got := A{Str: "wrong", Bool: true} |
| 25 | + msg := f.Comparable(got).Equal(want) |
| 26 | + assertFailed(t, msg, "the objects are not equal") |
| 27 | + }) |
| 28 | + t.Run("nil", func(t *testing.T) { |
| 29 | + var got *A |
| 30 | + msg := f.Comparable(got).Equal(nil) |
| 31 | + assertPassed(t, msg) |
| 32 | + }) |
| 33 | + }) |
| 34 | + |
| 35 | + t.Run("NotEqual", func(t *testing.T) { |
| 36 | + t.Run("Passed", func(t *testing.T) { |
| 37 | + want := A{Str: "string", Bool: true} |
| 38 | + got := A{Str: "wrong", Bool: true} |
| 39 | + msg := f.Comparable(got).NotEqual(want) |
| 40 | + assertPassed(t, msg) |
| 41 | + }) |
| 42 | + t.Run("Failed", func(t *testing.T) { |
| 43 | + want := A{Str: "string", Bool: true} |
| 44 | + got := A{Str: "string", Bool: true} |
| 45 | + msg := f.Comparable(got).NotEqual(want) |
| 46 | + assertFailed(t, msg, "the objects are equal") |
| 47 | + }) |
| 48 | + t.Run("nil", func(t *testing.T) { |
| 49 | + var got *A |
| 50 | + msg := f.Comparable(got).NotEqual(nil) |
| 51 | + assertFailed(t, msg, "the objects are equal") |
| 52 | + }) |
| 53 | + }) |
| 54 | + |
| 55 | + t.Run("has assertions from Obj", func(t *testing.T) { |
| 56 | + want := A{} |
| 57 | + got := f.Comparable(want).FluentObj.Got // type embedding done properly |
| 58 | + assertEqual(t, got, want) |
| 59 | + }) |
| 60 | +} |
0 commit comments