Skip to content

Commit

Permalink
Added assertThat___ and equalTo___ for all types understood by NSNumb…
Browse files Browse the repository at this point in the history
…er. For example: assertThatInt(42, equalToInt(42))

git-svn-id: http://hamcrest.googlecode.com/svn/trunk/hamcrest-objectivec@477 2aa0e9f1-8e24-0410-adc4-1b6a3a6e65e2
  • Loading branch information
jon.m.reid committed Dec 1, 2009
1 parent 99890c2 commit 67ed2b5
Show file tree
Hide file tree
Showing 19 changed files with 1,435 additions and 24 deletions.
30 changes: 21 additions & 9 deletions CHANGES.txt
@@ -1,20 +1,32 @@
01 Dec 2009:
* Added assertThat___ and equalTo___ for all types understood by NSNumber. For example: assertThatInt(42, equalToInt(42))

24 Nov 2009:
* Changed assertThat behavior to work more seamlessly with OCUnit: Instead of throwing an exception, it calls the same method as OCUnit's assertion macros to fail the test. As a result, a failing assertThat will not terminate the test, so that the test can record other failures. (Following normal OCUnit behavior, you can instruct the test case to terminate at the first failure by invoking raiseAfterFailure.)
This change requires that assertThat be called only within subclasses of SenTestCase, which wasn't the case before. You will need to recompile your tests.
If you need an original-style assertion that can be called outside of a SenTestCase, email your request to hamcrest-dev@googlegroups.com
(24 Nov 2009)

* Support Xcode 3.2's redesigned Build Results window by removing colons from assertThat description. (24 Nov 2009)
24 Nov 2009:
* Support Xcode 3.2's redesigned Build Results window by removing colons from assertThat description.

* Added helper class HCInvocationMatcher for building other matchers from NSInvocations. See HCHasDescription for an example. (17 Oct 2009)
17 Oct 2009:
* Added helper class HCInvocationMatcher for building other matchers from NSInvocations. See HCHasDescription for an example.

* Renamed framework to OCHamcrest. (11 Aug 2009)
11 Aug 2009:
* Renamed framework to OCHamcrest.

* Added support for Mac OS X 10.4 projects. (07 Jul 2009)
07 Jul 2009:
* Added support for Mac OS X 10.4 projects.

* Fixed compiler errors when used with Objective-C++ (.mm files). (28 Jan 2009)
28 Jan 2009:
* Fixed compiler errors when used with Objective-C++ (.mm files).

* Added means for matchers to describe mismatches. You can use either matches:describingMismatchTo: to do it one shot, or call describeMismatchOf:To: once you know a particular item does not match. (24 Jan 2009)
24 Jan 2009:
* Added means for matchers to describe mismatches. You can use either matches:describingMismatchTo: to do it one shot, or call describeMismatchOf:To: once you know a particular item does not match.

* Changed matchers whose description looks similar to a function call so that the description matches the name of the factory function. (18 Jul 2008)
18 Jul 2008:
* Changed matchers whose description looks similar to a function call so that the description matches the name of the factory function.

* Initial release (13 Apr 2008)
13 Apr 2008:
* Initial release

6 changes: 6 additions & 0 deletions Examples/ExampleWithAssertThat/ExampleWithAssertThat.mm
Expand Up @@ -15,4 +15,10 @@ - (void) testUsingAssertThat
assertThat(@"i like cheese", containsString(@"cheese"));
}

- (void) testUsingNumbers
{
assertThatInt(42, equalToInt(42));
assertThatUnsignedShort(6 * 9, isNot(equalToUnsignedShort(42)));
}

@end
4 changes: 3 additions & 1 deletion Source/Core/Core/HCAllOf.mm
Expand Up @@ -9,9 +9,11 @@
#import "HCAllOf.h"

// OCHamcrest
#import "HCCollectMatchers.h"
#import "HCDescription.h"

// OCHamcrest internal
#import "HCCollectMatchers.h"


@implementation HCAllOf

Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/HCAnyOf.mm
Expand Up @@ -9,9 +9,11 @@
#import "HCAnyOf.h"

// OCHamcrest
#import "HCCollectMatchers.h"
#import "HCDescription.h"

// OCHamcrest internal
#import "HCCollectMatchers.h"


@implementation HCAnyOf

Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HCDescribedAs.mm
Expand Up @@ -10,6 +10,8 @@

// OCHamcrest
#import "HCDescription.h"

// OCHamcrest internal
#import "HCIntegerTypes.h"

// C++
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/HCBaseDescription.mm
Expand Up @@ -9,10 +9,12 @@
#import "HCBaseDescription.h"

// OCHamcrest
#import "HCIntegerTypes.h"
#import "HCMatcher.h"
#import "HCSelfDescribing.h"

// OCHamcrest internal
#import "HCIntegerTypes.h"


@interface HCBaseDescription(Private)
- (void) toCSyntaxString:(NSString*)unformatted;
Expand Down
Expand Up @@ -17,7 +17,7 @@ extern "C" {
@a item is returned as-is if it is already an HCMatcher.
*/
id<HCMatcher> HC_wrapInMatcher (id item);
id<HCMatcher> HC_wrapInMatcher(id item);

#ifdef __cplusplus
}
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions Source/Core/Internal/HCIntegerTypes.h
Expand Up @@ -12,7 +12,9 @@

#if !defined(OBJC_API_VERSION) || OBJC_API_VERSION < 2

typedef long NSInteger;
typedef unsigned long NSUInteger;
// Define 32-bit types only. I presume that anyone in 64-bit is not building for Tiger.

typedef int NSInteger;
typedef unsigned int NSUInteger;

#endif
87 changes: 87 additions & 0 deletions Source/Library/Number/HCBoxNumber.h
@@ -0,0 +1,87 @@
//
// OCHamcrest - HCBoxNumber.h
// Copyright 2009 www.hamcrest.org. See LICENSE.txt
//
// Created by: Jon Reid
//

#ifdef __cplusplus

namespace hamcrest {

/**
Boxes scalar value in NSNumber, specialized per type.
*/
template <typename T>
inline
NSNumber* boxNumber(T value)
{ return nil; }

template <>
inline
NSNumber* boxNumber(BOOL value)
{ return [NSNumber numberWithBool:value]; }

template <>
inline
NSNumber* boxNumber(char value)
{ return [NSNumber numberWithChar:value]; }

template <>
inline
NSNumber* boxNumber(double value)
{ return [NSNumber numberWithDouble:value]; }

template <>
inline
NSNumber* boxNumber(float value)
{ return [NSNumber numberWithFloat:value]; }

template <>
inline
NSNumber* boxNumber(int value)
{ return [NSNumber numberWithInt:value]; }

template <>
inline
NSNumber* boxNumber(long value)
{ return [NSNumber numberWithLong:value]; }

template <>
inline
NSNumber* boxNumber(long long value)
{ return [NSNumber numberWithLongLong:value]; }

template <>
inline
NSNumber* boxNumber(short value)
{ return [NSNumber numberWithShort:value]; }

template <>
inline
NSNumber* boxNumber(unsigned char value)
{ return [NSNumber numberWithUnsignedChar:value]; }

template <>
inline
NSNumber* boxNumber(unsigned int value)
{ return [NSNumber numberWithUnsignedInt:value]; }

template <>
inline
NSNumber* boxNumber(unsigned long value)
{ return [NSNumber numberWithUnsignedLong:value]; }

template <>
inline
NSNumber* boxNumber(unsigned long long value)
{ return [NSNumber numberWithUnsignedLongLong:value]; }

template <>
inline
NSNumber* boxNumber(unsigned short value)
{ return [NSNumber numberWithUnsignedShort:value]; }

} // namespace hamcrest

#endif // __cplusplus
185 changes: 185 additions & 0 deletions Source/Library/Number/HCIsEqualToNumber.h
@@ -0,0 +1,185 @@
//
// OCHamcrest - HCIsEqualToNumber.h
// Copyright 2009 www.hamcrest.org. See LICENSE.txt
//
// Created by: Jon Reid
//

// Inherited
#import <OCHamcrest/HCBaseMatcher.h>


#ifdef __cplusplus
extern "C" {
#endif

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToBool(BOOL value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToChar(char value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToDouble(double value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToFloat(float value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToInt(int value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToLong(long value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToLongLong(long long value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToShort(short value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToUnsignedChar(unsigned char value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToUnsignedInt(unsigned int value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToUnsignedLong(unsigned long value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToUnsignedLongLong(unsigned long long value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToUnsignedShort(unsigned short value);


#if defined(OBJC_API_VERSION) && OBJC_API_VERSION >= 2

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToInteger(NSInteger value);

/**
Is the value, when converted to an NSNumber, equal to another object?
*/
id<HCMatcher> HC_equalToUnsignedInteger(NSUInteger value);

#endif // Objective-C 2.0


#ifdef __cplusplus
}
#endif


#ifdef HC_SHORTHAND

/**
Shorthand for HC_equalToBool, available if HC_SHORTHAND is defined.
*/
#define equalToBool HC_equalToBool

/**
Shorthand for HC_equalToChar, available if HC_SHORTHAND is defined.
*/
#define equalToChar HC_equalToChar

/**
Shorthand for HC_equalToDouble, available if HC_SHORTHAND is defined.
*/
#define equalToDouble HC_equalToDouble

/**
Shorthand for HC_equalToFloat, available if HC_SHORTHAND is defined.
*/
#define equalToFloat HC_equalToFloat

/**
Shorthand for HC_equalToInt, available if HC_SHORTHAND is defined.
*/
#define equalToInt HC_equalToInt

/**
Shorthand for HC_equalToLong, available if HC_SHORTHAND is defined.
*/
#define equalToLong HC_equalToLong

/**
Shorthand for HC_equalToLongLong, available if HC_SHORTHAND is defined.
*/
#define equalToLongLong HC_equalToLongLong

/**
Shorthand for HC_equalToShort, available if HC_SHORTHAND is defined.
*/
#define equalToShort HC_equalToShort

/**
Shorthand for HC_equalToUnsignedChar, available if HC_SHORTHAND is defined.
*/
#define equalToUnsignedChar HC_equalToUnsignedChar

/**
Shorthand for HC_equalToUnsignedInt, available if HC_SHORTHAND is defined.
*/
#define equalToUnsignedInt HC_equalToUnsignedInt

/**
Shorthand for HC_equalToUnsignedLong, available if HC_SHORTHAND is defined.
*/
#define equalToUnsignedLong HC_equalToUnsignedLong

/**
Shorthand for HC_equalToUnsignedLongLong, available if HC_SHORTHAND is defined.
*/
#define equalToUnsignedLongLong HC_equalToUnsignedLongLong

/**
Shorthand for HC_equalToUnsignedShort, available if HC_SHORTHAND is defined.
*/
#define equalToUnsignedShort HC_equalToUnsignedShort


#if defined(OBJC_API_VERSION) && OBJC_API_VERSION >= 2

/**
Shorthand for HC_equalToInteger, available if HC_SHORTHAND is defined.
*/
#define equalToInteger HC_equalToInteger

/**
Shorthand for HC_equalToUnsignedInteger, available if HC_SHORTHAND is defined.
*/
#define equalToUnsignedInteger HC_equalToUnsignedInteger

#endif // Objective-C 2.0


#endif // HC_SHORTHAND

0 comments on commit 67ed2b5

Please sign in to comment.