Permalink
Browse files

Added support for comparing and describing ranges.

  • Loading branch information...
1 parent 428eb6b commit 50609703003228bbb82cd7c7e1b0c354e577ad14 @robrix committed Apr 9, 2010
Showing with 37 additions and 0 deletions.
  1. +21 −0 RXAssertionHelperTests.m
  2. +10 −0 RXAssertions.m
  3. +6 −0 RXAssertions.xcodeproj/project.pbxproj
@@ -0,0 +1,21 @@
+// RXAssertionHelperTests.m
+// Created by Rob Rix on 2010-04-09
+// Copyright 2010 Monochrome Industries
+
+#import "RXAssertions.h"
+
+@interface RXAssertionHelperTests : SenTestCase
+@end
+
+@implementation RXAssertionHelperTests
+
+-(void)testCanTestRangesForEquality {
+ NSRange a = NSMakeRange(0, 1), b = NSMakeRange(0, 1), c = NSMakeRange(1, 2);
+ RXAssert([RXAssertionHelper compareValue: &a withValue: &b ofObjCType: @encode(NSRange)]);
+ RXAssertFalse([RXAssertionHelper compareValue: &a withValue: &c ofObjCType: @encode(NSRange)]);
+
+ // RXAssertEquals(NSMakeRange(0, 1), NSMakeRange(0, 1));
+ // RXAssertNotEquals(NSMakeRange(0, 1), NSMakeRange(1, 2));
+}
+
+@end
View
@@ -45,6 +45,10 @@ BOOL RXAssertionHelperNSPointComparison(const void *a, const void *b) {
return NSEqualPoints(*RXCast(a, const NSPoint *), *RXCast(b, const NSPoint *));
}
+BOOL RXAssertionHelperNSRangeComparison(const void *a, const void *b) {
+ return NSEqualRanges(*RXCast(a, const NSRange *), *RXCast(b, const NSRange *));
+}
+
NSString *RXAssertionHelperHexadecimalDescription(const void *ref) {
return [NSString stringWithFormat: @"%x", *RXCast(ref, const void **)];
@@ -98,6 +102,10 @@ BOOL RXAssertionHelperNSPointComparison(const void *a, const void *b) {
return NSStringFromPoint(*RXCast(ref, const NSPoint *));
}
+NSString *RXAssertionHelperNSRangeDescription(const void *ref) {
+ return NSStringFromRange(*RXCast(ref, const NSRange *));
+}
+
@implementation RXAssertionHelper
@@ -128,6 +136,7 @@ +(void)initialize {
[self registerComparisonFunction: RXAssertionHelperObjectComparison forObjCType: @encode(Class)];
[self registerComparisonFunction: RXAssertionHelperNSPointComparison forObjCType: @encode(NSPoint)];
[self registerComparisonFunction: RXAssertionHelperNSPointComparison forObjCType: @encode(CGPoint)];
+ [self registerComparisonFunction: RXAssertionHelperNSRangeComparison forObjCType: @encode(NSRange)];
[self registerDescriptionFunction: RXAssertionHelperHexadecimalDescription forObjCType: @encode(void *)];
[self registerDescriptionFunction: RXAssertionHelperInt8Description forObjCType: @encode(int8_t)];
@@ -144,6 +153,7 @@ +(void)initialize {
[self registerDescriptionFunction: RXAssertionHelperObjectDescription forObjCType: @encode(Class)];
[self registerDescriptionFunction: RXAssertionHelperNSPointDescription forObjCType: @encode(NSPoint)];
[self registerDescriptionFunction: RXAssertionHelperNSPointDescription forObjCType: @encode(CGPoint)];
+ [self registerDescriptionFunction: RXAssertionHelperNSRangeDescription forObjCType: @encode(NSRange)];
}
@@ -11,6 +11,7 @@
D472095311581618003F9546 /* RXMockObjectTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D472095211581618003F9546 /* RXMockObjectTests.m */; };
D4C03B4A1063445800925A75 /* RXAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = D4C03B471063445800925A75 /* RXAssertions.h */; };
D4C03B4B1063445800925A75 /* RXAssertions.m in Sources */ = {isa = PBXBuildFile; fileRef = D4C03B481063445800925A75 /* RXAssertions.m */; };
+ D4CE0C55116FB8E400FE6B86 /* RXAssertionHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D4CE0C54116FB8E400FE6B86 /* RXAssertionHelperTests.m */; };
D4F3DD2811558CC2008BB0F8 /* RXMockObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D4F3DD2611558CC2008BB0F8 /* RXMockObject.h */; };
D4F3DD2911558CC2008BB0F8 /* RXMockObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D4F3DD2711558CC2008BB0F8 /* RXMockObject.m */; };
/* End PBXBuildFile section */
@@ -34,6 +35,7 @@
D4C03B471063445800925A75 /* RXAssertions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RXAssertions.h; sourceTree = "<group>"; };
D4C03B481063445800925A75 /* RXAssertions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RXAssertions.m; sourceTree = "<group>"; };
D4C03B491063445800925A75 /* RXAssertions.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RXAssertions.pch; sourceTree = "<group>"; };
+ D4CE0C54116FB8E400FE6B86 /* RXAssertionHelperTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RXAssertionHelperTests.m; sourceTree = "<group>"; };
D4F3DD2611558CC2008BB0F8 /* RXMockObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RXMockObject.h; sourceTree = "<group>"; };
D4F3DD2711558CC2008BB0F8 /* RXMockObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RXMockObject.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -73,6 +75,7 @@
D4C03B481063445800925A75 /* RXAssertions.m */,
D4C03B491063445800925A75 /* RXAssertions.pch */,
D442A48D106FD99700944F07 /* RXAssertionsTests.m */,
+ D4CE0C54116FB8E400FE6B86 /* RXAssertionHelperTests.m */,
D4F3DD2611558CC2008BB0F8 /* RXMockObject.h */,
D4F3DD2711558CC2008BB0F8 /* RXMockObject.m */,
D472095211581618003F9546 /* RXMockObjectTests.m */,
@@ -193,6 +196,7 @@
buildActionMask = 2147483647;
files = (
D472095311581618003F9546 /* RXMockObjectTests.m in Sources */,
+ D4CE0C55116FB8E400FE6B86 /* RXAssertionHelperTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -263,6 +267,7 @@
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
@@ -276,6 +281,7 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;

0 comments on commit 5060970

Please sign in to comment.