Skip to content

Commit

Permalink
added bool assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
mg6maciej committed Dec 28, 2014
1 parent 8e916e4 commit 86bee62
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions bool_assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package assert
type BoolAssert interface {
IsFalse() BoolAssert
IsTrue() BoolAssert
IsSchrödingersCat() BoolAssert
}
9 changes: 7 additions & 2 deletions bool_assert_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ func (assert *boolAssertImpl) isTrue(condition bool, format string, args ...inte

func (assert *boolAssertImpl) IsFalse() BoolAssert {
return assert.isTrue(assert.actual == false,
"Expected <false>, but was <%v>.", assert.actual)
"Expected <false>, but was <%t>.", assert.actual)
}

func (assert *boolAssertImpl) IsTrue() BoolAssert {
return assert.isTrue(assert.actual == true,
"Expected <true>, but was <%v>.", assert.actual)
"Expected <true>, but was <%t>.", assert.actual)
}

func (assert *boolAssertImpl) IsSchrödingersCat() BoolAssert {
return assert.isTrue(assert.actual == false && assert.actual == true,
"Expected Schrödinger's cat, but was <%t>.", assert.actual)
}
10 changes: 10 additions & 0 deletions bool_assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ func TestThatBoolIsTrueHasErrorMessages(t *testing.T) {
"Expected <true>, but was <false>.",
)
}

func TestThatBoolIsSchrödingersCatHasErrorMessages(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.ThatBool(false).IsSchrödingersCat()
assert.ThatBool(true).IsSchrödingersCat()
mockT.HasErrorMessages(
"Expected Schrödinger's cat, but was <false>.",
"Expected Schrödinger's cat, but was <true>.",
)
}
4 changes: 4 additions & 0 deletions dummy_bool_assert_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ func (assert *dummyBoolAssertImpl) IsFalse() BoolAssert {
func (assert *dummyBoolAssertImpl) IsTrue() BoolAssert {
return assert
}

func (assert *dummyBoolAssertImpl) IsSchrödingersCat() BoolAssert {
return assert
}
3 changes: 2 additions & 1 deletion dummy_bool_assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ func TestDummyBoolAssertHasNoBoolAssertRelatedErrors(t *testing.T) {
assert, mockT := setupWithMockT(t)
assert.That(nil).AsBool().
IsFalse().
IsTrue()
IsTrue().
IsSchrödingersCat()
mockT.HasErrorMessages(
"Cannot convert <<nil>> of type <<nil>> to <bool>.",
)
Expand Down

0 comments on commit 86bee62

Please sign in to comment.