Skip to content

Commit

Permalink
Merge remote-tracking branch 'cppforlife/singleton_matchers'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Milligan committed Nov 9, 2011
2 parents 3281683 + a2f90aa commit 84da6c6
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Source/Headers/Matchers/Base/BeNil.h
Expand Up @@ -13,6 +13,7 @@ namespace Cedar { namespace Matchers {
// Allow default copy ctor.

virtual NSString * failure_message_end() const;
const BeNil & operator()() const;

template<typename U>
bool matches(const U &) const;
Expand All @@ -21,7 +22,7 @@ namespace Cedar { namespace Matchers {
bool matches(U * const &) const;
};

BeNil be_nil();
static const BeNil be_nil = BeNil();

#pragma mark Generic
template<typename U>
Expand Down
3 changes: 2 additions & 1 deletion Source/Headers/Matchers/Base/BeTruthy.h
Expand Up @@ -12,12 +12,13 @@ namespace Cedar { namespace Matchers {
// Allow default copy ctor.

virtual NSString * failure_message_end() const;
const BeTruthy & operator()() const;

template<typename U>
bool matches(const U &) const;
};

BeTruthy be_truthy();
static const BeTruthy be_truthy = BeTruthy();

#pragma mark Generic
template<typename U>
Expand Down
9 changes: 7 additions & 2 deletions Source/Headers/Matchers/Container/BeEmpty.h
Expand Up @@ -10,15 +10,20 @@ namespace Cedar { namespace Matchers {
~BeEmpty();
// Allow default copy ctor.

const BeEmpty & operator()() const;

template<typename U>
bool matches(const U &) const;

protected:
virtual NSString * failure_message_end() const;
};

inline BeEmpty be_empty() {
return BeEmpty();
static const BeEmpty be_empty = BeEmpty();

// For backwards compatible parenthesis syntax
inline const BeEmpty & BeEmpty::operator()() const {
return *this;
}

inline BeEmpty::BeEmpty() : Base() {
Expand Down
5 changes: 3 additions & 2 deletions Source/Matchers/BeNil.mm
Expand Up @@ -2,8 +2,9 @@

namespace Cedar { namespace Matchers {

BeNil be_nil() {
return BeNil();
// For backwards compatible parenthesis syntax
const BeNil & BeNil::operator()() const {
return *this;
}

BeNil::BeNil() : Base() {
Expand Down
5 changes: 3 additions & 2 deletions Source/Matchers/BeTruthy.mm
Expand Up @@ -2,8 +2,9 @@

namespace Cedar { namespace Matchers {

BeTruthy be_truthy() {
return BeTruthy();
// For backwards compatible parenthesis syntax
const BeTruthy & BeTruthy::operator()() const {
return *this;
}

BeTruthy::BeTruthy() : Base() {
Expand Down
18 changes: 18 additions & 0 deletions Spec/Matchers/Base/BeNilSpec.mm
Expand Up @@ -116,4 +116,22 @@
});
});

describe(@"be_nil shorthand syntax (no parenthesis)", ^{
void *value = NULL;

describe(@"positive match", ^{
it(@"should should pass", ^{
expect(value).to(be_nil);
});
});

describe(@"negative match", ^{
it(@"should fail with a sensible failure message", ^{
expectFailureWithMessage(@"Expected <0> to not be nil", ^{
expect(value).to_not(be_nil);
});
});
});
});

SPEC_END
18 changes: 18 additions & 0 deletions Spec/Matchers/Base/BeTruthySpec.mm
Expand Up @@ -104,4 +104,22 @@
});
});

describe(@"be_truthy shorthand syntax (no parenthesis)", ^{
BOOL value = YES;

describe(@"positive match", ^{
it(@"should should pass", ^{
expect(value).to(be_truthy);
});
});

describe(@"negative match", ^{
it(@"should fail with a sensible failure message", ^{
expectFailureWithMessage(@"Expected <YES> to not evaluate to true", ^{
expect(value).to_not(be_truthy);
});
});
});
});

SPEC_END
18 changes: 18 additions & 0 deletions Spec/Matchers/Container/BeEmptySpec.mm
Expand Up @@ -364,4 +364,22 @@
});
});

describe(@"be_empty shorthand syntax (no parenthesis)", ^{
NSArray *container = [NSArray array];

describe(@"positive match", ^{
it(@"should should pass", ^{
expect(container).to(be_empty);
});
});

describe(@"negative match", ^{
it(@"should fail with a sensible failure message", ^{
expectFailureWithMessage(@"Expected <(\n)> to not be empty", ^{
expect(container).to_not(be_empty);
});
});
});
});

SPEC_END

0 comments on commit 84da6c6

Please sign in to comment.