Skip to content

Commit

Permalink
Merge branch 'cedar' into experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz committed May 4, 2012
2 parents 7431299 + 0b7c273 commit 61caeca
Show file tree
Hide file tree
Showing 135 changed files with 5,687 additions and 6,674 deletions.
83 changes: 36 additions & 47 deletions AppledocTests/Application/AppledocTests.mm
Expand Up @@ -6,64 +6,53 @@
// Copyright (c) 2012 Tomaz Kragelj. All rights reserved.
//

#import "Objects+TestingPrivateAPI.h"
#import "Store.h"
#import "Parser.h"
#import "Appledoc.h"
#import "TestCaseBase.h"
#import "TestCaseBase.hh"

@interface Appledoc (TestingPrivateAPI)
@property (nonatomic, strong) GBSettings *settings;
@end

#pragma mark -

@interface AppledocTests : TestCaseBase
@end

@interface AppledocTests (CreationMethods)
- (void)runWithAppledoc:(void(^)(Appledoc *appledoc))handler;
@end

@implementation AppledocTests

#pragma mark - Properties

- (void)testLazyAccessorsShouldInitializeObjects {
[self runWithAppledoc:^(Appledoc *appledoc) {
// execute & verify
assertThat(appledoc.store, instanceOf([Store class]));
assertThat(appledoc.parser, instanceOf([Parser class]));
}];
}

#pragma mark - runWithSettings:

- (void)testRunWithSettingsShouldInvokeAllSubcomponents {
[self runWithAppledoc:^(Appledoc *appledoc) {
// setup
id settings = [OCMockObject niceMockForClass:[GBSettings class]];
id store = [OCMockObject niceMockForClass:[Store class]];
id parser = [OCMockObject mockForClass:[Parser class]];
[[parser expect] runWithSettings:settings store:store];
appledoc.store = store;
appledoc.parser = parser;
// execute
[appledoc runWithSettings:settings];
// verify
STAssertNoThrow([parser verify], nil);
}];
}

@end

#pragma mark -

@implementation AppledocTests (CreationMethods)

- (void)runWithAppledoc:(void(^)(Appledoc *appledoc))handler {
static void runWithAppledoc(void(^handler)(Appledoc *appledoc)) {
Appledoc *appledoc = [[Appledoc alloc] init];
handler(appledoc);
[appledoc release];
}

@end
#pragma mark -

SPEC_BEGIN(AppledocTests)

describe(@"lazy accessors", ^{
it(@"should initialize objects", ^{
runWithAppledoc(^(Appledoc *appledoc) {
// execute & verify
appledoc.store should be_instance_of([Store class]);
appledoc.parser should be_instance_of([Parser class]);
});
});
});

describe(@"run", ^{
it(@"should invoke parser", ^{
runWithAppledoc(^(Appledoc *appledoc) {
// setup
id settings = [OCMockObject niceMockForClass:[GBSettings class]];
id store = [OCMockObject niceMockForClass:[Store class]];
id parser = [OCMockObject mockForClass:[Parser class]];
[[parser expect] runWithSettings:settings store:store];
appledoc.store = store;
appledoc.parser = parser;
// execute
[appledoc runWithSettings:settings];
// verify
^{ [parser verify]; } should_not raise_exception();
});
});
});

SPEC_END
1 change: 1 addition & 0 deletions AppledocTests/Libraries/Cedar.framework/Cedar
Binary file not shown.
@@ -0,0 +1,117 @@
#import <Foundation/Foundation.h>
#import <iostream>

#import "StringifiersBase.h"
#import "CDRSpecFailure.h"

namespace Cedar { namespace Matchers {

void CDR_fail(const char *fileName, int lineNumber, NSString * reason);

template<typename T> class ActualValue;

#pragma mark class ActualValueMatchProxy
template<typename T>
class ActualValueMatchProxy {
private:
template<typename U>
ActualValueMatchProxy(const ActualValueMatchProxy<U> &);
template<typename U>
ActualValueMatchProxy & operator=(const ActualValueMatchProxy<U> &);

public:
explicit ActualValueMatchProxy(const ActualValue<T> &, bool negate = false);
ActualValueMatchProxy();

template<typename MatcherType> void operator()(const MatcherType &) const;
ActualValueMatchProxy<T> negate() const;

private:
const ActualValue<T> & actualValue_;
bool negate_;
};

template<typename T>
ActualValueMatchProxy<T>::ActualValueMatchProxy(const ActualValue<T> & actualValue, bool negate /*= false */)
: actualValue_(actualValue), negate_(negate) {}

template<typename T> template<typename MatcherType>
void ActualValueMatchProxy<T>::operator()(const MatcherType & matcher) const {
if (negate_) {
actualValue_.execute_negative_match(matcher);
} else {
actualValue_.execute_positive_match(matcher);
}
}

template<typename T>
ActualValueMatchProxy<T> ActualValueMatchProxy<T>::negate() const {
return ActualValueMatchProxy<T>(actualValue_, !negate_);
}

#pragma mark class ActualValue
template<typename T>
class ActualValue {
private:
template<typename U>
ActualValue(const ActualValue<U> &);
template<typename U>
ActualValue & operator=(const ActualValue<U> &);

public:
explicit ActualValue(const char *, int, const T &);
~ActualValue();

ActualValueMatchProxy<T> to;
ActualValueMatchProxy<T> to_not;

private:
template<typename MatcherType> void execute_positive_match(const MatcherType &) const;
template<typename MatcherType> void execute_negative_match(const MatcherType &) const;
friend class ActualValueMatchProxy<T>;

private:
const T & value_;
std::string fileName_;
int lineNumber_;
};

template<typename T>
ActualValue<T>::ActualValue(const char *fileName, int lineNumber, const T & value) : fileName_(fileName), lineNumber_(lineNumber), value_(value), to(*this), to_not(*this, true) {
}

template<typename T>
ActualValue<T>::~ActualValue() {
}

template<typename T> template<typename MatcherType>
void ActualValue<T>::execute_positive_match(const MatcherType & matcher) const {
if (!matcher.matches(value_)) {
CDR_fail(fileName_.c_str(), lineNumber_, matcher.failure_message_for(value_));
}
}

template<typename T> template<typename MatcherType>
void ActualValue<T>::execute_negative_match(const MatcherType & matcher) const {
if (matcher.matches(value_)) {
CDR_fail(fileName_.c_str(), lineNumber_, matcher.negative_failure_message_for(value_));
}
}

template<typename T>
const ActualValue<T> CDR_expect(const char *fileName, int lineNumber, const T & actualValue) {
return ActualValue<T>(fileName, lineNumber, actualValue);
}

inline void CDR_fail(const char *fileName, int lineNumber, NSString * reason) {
[[CDRSpecFailure specFailureWithReason:reason
fileName:[NSString stringWithUTF8String:fileName]
lineNumber:lineNumber] raise];
}

}}

#ifndef CEDAR_MATCHERS_COMPATIBILITY_MODE
#define expect(x) CDR_expect(__FILE__, __LINE__, (x))
#define fail(x) CDR_fail(__FILE__, __LINE__, (x))
#endif
@@ -0,0 +1,60 @@
#import <Foundation/Foundation.h>
#import "CompareEqual.h"
#import "CedarStringifiers.h"
#import "CedarComparators.h"

namespace Cedar { namespace Doubles {

class Argument {
public:
virtual ~Argument() = 0;

virtual const char * value_encoding() const = 0;
virtual NSString * value_string() const = 0;

virtual bool matches_bytes(void * expectedArgumentBytes) const = 0;
};

inline /* virtual */ Argument::~Argument() {}

template<typename T>
class TypedArgument : public Argument {
private:
TypedArgument<T> & operator=(const TypedArgument<T> &);

public:
explicit TypedArgument(const T &);
virtual ~TypedArgument();
// Allow default copy ctor.

virtual const char * value_encoding() const;
virtual NSString * value_string() const;

virtual bool matches_bytes(void * expectedArgumentBytes) const;

private:
const T & value_;
};


template<typename T>
TypedArgument<T>::TypedArgument(const T & value) : Argument(), value_(value) {}

template<typename T>
/* virtual */ TypedArgument<T>::~TypedArgument() {}

template<typename T>
/* virtual */ const char * TypedArgument<T>::value_encoding() const {
return @encode(T);
}

template<typename T>
/* virtual */ NSString * TypedArgument<T>::value_string() const {
return Matchers::Stringifiers::string_for(value_);
}

template<typename T>
/* virtual */ bool TypedArgument<T>::matches_bytes(void * expectedArgumentBytes) const {
return Matchers::Comparators::compare_equal(value_, *(static_cast<T *>(expectedArgumentBytes)));
}
}}
51 changes: 51 additions & 0 deletions AppledocTests/Libraries/Cedar.framework/Versions/A/Headers/Base.h
@@ -0,0 +1,51 @@
#import <Foundation/Foundation.h>
#import <sstream>

#import "CedarStringifiers.h"

namespace Cedar { namespace Matchers {
struct BaseMessageBuilder {
template<typename U>
static NSString * string_for_actual_value(const U & value) {
return Stringifiers::string_for(value);
}
};

/**
* Basic functionality for all matchers. Meant to be used as a convenience base class for
* matcher classes.
*/
template<typename MessageBuilder_ = BaseMessageBuilder>
class Base {
private:
Base & operator=(const Base &);

public:
Base();
virtual ~Base() = 0;
// Allow default copy ctor.

template<typename U>
NSString * failure_message_for(const U &) const;
template<typename U>
NSString * negative_failure_message_for(const U &) const;

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

template<typename MessageBuilder_>
Base<MessageBuilder_>::Base() {}
template<typename MessageBuilder_>
Base<MessageBuilder_>::~Base() {}

template<typename MessageBuilder_> template<typename U>
NSString * Base<MessageBuilder_>::failure_message_for(const U & value) const {
return [NSString stringWithFormat:@"Expected <%@> to %@", MessageBuilder_::string_for_actual_value(value), this->failure_message_end()];
}

template<typename MessageBuilder_> template<typename U>
NSString * Base<MessageBuilder_>::negative_failure_message_for(const U & value) const {
return [NSString stringWithFormat:@"Expected <%@> to not %@", MessageBuilder_::string_for_actual_value(value), this->failure_message_end()];
}
}}

0 comments on commit 61caeca

Please sign in to comment.