Skip to content

Commit

Permalink
Added failing test for NSDate equality after decoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Kreiser authored and nicklockwood committed Mar 19, 2018
1 parent c8c7f75 commit 625968e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Tests/UnitTests/FastCoderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface Model : NSObject <NSCopying>
@property (nonatomic, strong) NSString *textNew;
@property (nonatomic, strong) NSArray *array1;
@property (nonatomic, strong) NSArray *array2;
@property (nonatomic, strong) NSDate *date;

@end

Expand All @@ -31,7 +32,8 @@ - (BOOL)isEqual:(id)object
((!self.text2 && !model.text2) || [self.text2 isEqual:model.text2]) &&
((!self.textNew && !model.textNew) || [self.textNew isEqual:model.textNew]) &&
((!self.array1 && !model.array1) || [self.array1 isEqual:model.array1]) &&
((!self.array2 && !model.array2) || [self.array2 isEqual:model.array2]);
((!self.array2 && !model.array2) || [self.array2 isEqual:model.array2]) &&
((!self.date && !model.date) || [self.date isEqual:model.date]);
}
return NO;
}
Expand All @@ -43,6 +45,7 @@ - (id)copyWithZone:(NSZone *)zone
copy.textNew = self.textNew;
copy.array1 = self.array1;
copy.array2 = self.array2;
copy.date = self.date;
return copy;
}

Expand Down Expand Up @@ -101,6 +104,7 @@ - (void)testChangingModel
model.textNew = [NSMutableString stringWithString:@"bar"];
model.array1 = @[@"foo", @"bar"];
model.array2 = @[@1, @2];
model.date = [NSDate date];

//save model
NSData *data = [FastCoder dataWithRootObject:model];
Expand Down Expand Up @@ -226,6 +230,18 @@ - (void)testDateAlignment
XCTAssertEqualObjects([input description], [output description]);
}

- (void)testDateEquality
{
NSDate *input = [NSDate dateWithTimeIntervalSinceReferenceDate:542911754.16538298];

//convert to FastCoded data
NSData *data = [FastCoder dataWithRootObject:input];
NSDate *output = [FastCoder objectWithData:data];

//check
XCTAssertTrue([input isEqualToDate:output]);
}

- (void)testBooleans
{
NSNumber *input = @1;
Expand Down

0 comments on commit 625968e

Please sign in to comment.