Skip to content
Browse files

This was to make the equals: message behave more sanely. Before a == …

…b did not imply that b == a, which is inconsistent with the definition of equality. It made it difficult to wrap someone's head around it. So, I changed it so that a == b => b == a. Now, the numberOfArguments logic is contained in the "find:by:" selector which states that A can have arguments and still match B which has no arguments, as long as the names are equal.
  • Loading branch information...
1 parent ee364b3 commit 1e5d1f236c7d692f7f4e8c8a34febe8c7f49bcac @hammerdr committed Jan 25, 2010
Showing with 32 additions and 16 deletions.
  1. +30 −14 Framework/OJMoq/OJMoqSelector.j
  2. +2 −2 tests/OJMoqSelectorTest.j
View
44 Framework/OJMoq/OJMoqSelector.j
@@ -11,7 +11,17 @@
+ (OJMoqSelector)find:(OJMoqSelector)aSelector in:(CPArray)selectors
{
- return [selectors findBy:function(anotherSelector){return [aSelector equals:anotherSelector]}];
+ return [selectors findBy:function(anotherSelector)
+ {
+ if([anotherSelector numberOfArguments] > 0)
+ {
+ return [aSelector equals:anotherSelector]
+ }
+ else
+ {
+ return [aSelector isEqualToNameOf:anotherSelector];
+ }
+ }];
}
- (id)initWithName:(CPString)aName withArguments:(CPArray)someArguments
@@ -31,23 +41,29 @@
timesCalled = timesCalled + 1;
}
+- (BOOL)isEqualToNameOf:(OJMoqSelector)anotherSelector
+{
+ if(name === [anotherSelector name])
+ {
+ return YES;
+ }
+
+ return NO;
+}
+
- (BOOL)equals:(OJMoqSelector)anotherSelector
{
- if(name != [anotherSelector name])
- {
- return NO;
- }
+ if(name === [anotherSelector name] && [arguments isEqualToArray:[anotherSelector arguments]])
+ {
+ return YES;
+ }
- // If no arguments are specified, then we don't care.
- if([arguments count] > 0 && [[anotherSelector arguments] count] > 0)
- {
- if (![arguments isEqualToArray:[anotherSelector arguments]])
- {
- return NO;
- }
- }
+ return NO;
+}
- return YES;
+- (CPNumber)numberOfArguments
+{
+ return [arguments count];
}
- (CPComparisonResult)compareTimesCalled:(CPNumber)anotherNumber
View
4 tests/OJMoqSelectorTest.j
@@ -30,8 +30,8 @@
{
var sel1 = [[OJMoqSelector alloc] initWithName:@"same" withArguments:[CPArray arrayWithObject:@"yes"]];
var sel2 = [[OJMoqSelector alloc] initWithName:@"same" withArguments:[CPArray array]];
- [self assert:YES equals:[sel1 equals:sel2]];
- [self assert:YES equals:[sel2 equals:sel1]];
+ [self assert:NO equals:[sel1 equals:sel2]];
+ [self assert:NO equals:[sel2 equals:sel1]];
}
@end

0 comments on commit 1e5d1f2

Please sign in to comment.
Something went wrong with that request. Please try again.