Skip to content

Commit

Permalink
Add NotSameType
Browse files Browse the repository at this point in the history
  • Loading branch information
bayashi committed Sep 23, 2023
1 parent 96e5e1f commit ae5ea38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions not_same.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,18 @@ func (a *TestingA) NotSameNumber(t *testing.T, testNames ...string) *TestingA {

return a
}

// NotSameType method verifies that each pair of values are NOT same type.
// Not care about actual value of these. Just verify the type.
func (a *TestingA) NotSameType(t *testing.T, testNames ...string) *TestingA {
invalidCallForSame(a)
a.name = a.naming(testNames...)
a.t = t
a.t.Helper()

if !objectsAreSameType(a.expect.RawValue(), a.got.RawValue()) {
return a
}

return a.fail(reportForNotSameType(a))
}
11 changes: 11 additions & 0 deletions not_same_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ func TestNotSameNumber(t *testing.T) {
// actually.Got("0").Expect("0").NotSameNumber(t)
// actually.Got(1).Expect(float64(1.0000000000000001)).NotSameNumber(t)
}

func TestNotSameType(t *testing.T) {
actually.Got(nil).Expect(0).NotSameType(t)
actually.Got("1").Expect(1).NotSameType(t)
actually.Got(t).Expect(&testing.B{}).NotSameType(t)

// fail
// actually.Got(nil).Expect(nil).NotSameType(t)
// actually.Got(true).Expect(false).NotSameType(t) // both are same boolean
// actually.Got(&testing.T{}).Expect(t).NotSameType(t)
}

0 comments on commit ae5ea38

Please sign in to comment.