From 213c70e00d2b8c23a20e048fed57aaa6041302a4 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Thu, 9 Apr 2009 15:00:00 -0700 Subject: [PATCH] Modify CPAttributedString test to treat undefined and null as equal. I believe it must work this way, worth verifying. --- Tests/Foundation/CPAttributedStringTest.j | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Tests/Foundation/CPAttributedStringTest.j b/Tests/Foundation/CPAttributedStringTest.j index 96f7046eb..c3316ecf2 100644 --- a/Tests/Foundation/CPAttributedStringTest.j +++ b/Tests/Foundation/CPAttributedStringTest.j @@ -553,13 +553,18 @@ var sharedObject = [CPObject new]; @end +function isEqualAllowingUndefinedCast(a, b) +{ + return a === b || (a === undefined && a == b) || (b === undefined && a == b); +} + function testAttributesAtIndexWithValues(aString, anIndex, values, aSelf) { var range = CPMakeRange(0, 0), attributes = [aString attributesAtIndex:anIndex effectiveRange:range]; for(key in values) - [aSelf assertTrue:[attributes objectForKey:key] === values[key] message: "expecting '"+key+"' to be '"+values[key]+"', was '"+[attributes objectForKey:key]]; + [aSelf assertTrue:isEqualAllowingUndefinedCast([attributes objectForKey:key], values[key]) message: "expecting '"+key+"' to be '"+values[key]+"', was '"+[attributes objectForKey:key]]; var index = range.location; while(index < CPMaxRange(range)) @@ -567,7 +572,7 @@ function testAttributesAtIndexWithValues(aString, anIndex, values, aSelf) attributes = [aString attributesAtIndex:index++ effectiveRange:nil]; for(key in values) - [aSelf assertTrue:[attributes objectForKey:key] === values[key] message: "expecting '"+key+"' in loop to be '"+values[key]+"', was '"+[attributes objectForKey:key]]; + [aSelf assertTrue:isEqualAllowingUndefinedCast([attributes objectForKey:key], values[key]) message: "expecting '"+key+"' in loop to be '"+values[key]+"', was '"+[attributes objectForKey:key]]; } } @@ -576,14 +581,14 @@ function testAttributeAtIndexWithValue(aString, anIndex, aKey, aValue, aSelf) var range = CPMakeRange(0, 0), attribute = [aString attribute:aKey atIndex:anIndex effectiveRange:range]; - [aSelf assertTrue: attribute === aValue message: "expecting '"+aKey+"' to be '"+aValue+"', was '"+attribute]; + [aSelf assertTrue: isEqualAllowingUndefinedCast(attribute, aValue) message: "expecting '"+aKey+"' to be '"+aValue+"', was '"+attribute]; var index = range.location; while(index < CPMaxRange(range)) { attribute = [aString attribute:aKey atIndex:index++ effectiveRange:nil]; - [aSelf assertTrue: attribute === aValue message: "expecting '"+aKey+"' to be '"+aValue+"', was '"+attribute]; + [aSelf assertTrue: isEqualAllowingUndefinedCast(attribute, aValue) message: "expecting '"+aKey+"' to be '"+aValue+"', was '"+attribute]; } }