1*17293a6fSEric Samelson// Copyright © 2021 650 Industries. All rights reserved. 2*17293a6fSEric Samelson 3*17293a6fSEric Samelson#import "NSArray+EXStructuredHeadersTests.h" 4*17293a6fSEric Samelson 5*17293a6fSEric SamelsonNS_ASSUME_NONNULL_BEGIN 6*17293a6fSEric Samelson 7*17293a6fSEric Samelson@implementation NSArray (EXStructuredHeadersTests) 8*17293a6fSEric Samelson 9*17293a6fSEric Samelson- (BOOL)isEqualToTestResult:(id)object 10*17293a6fSEric Samelson{ 11*17293a6fSEric Samelson // dictionaries in the expected results are represented as arrays of tuplets [key, value] 12*17293a6fSEric Samelson if ([object isKindOfClass:[NSDictionary class]]) { 13*17293a6fSEric Samelson NSMutableDictionary *dictionaryToCompare = [NSMutableDictionary dictionaryWithCapacity:self.count]; 14*17293a6fSEric Samelson for (id member in self) { 15*17293a6fSEric Samelson if (![member isKindOfClass:[NSArray class]] || ((NSArray *)member).count != 2) { 16*17293a6fSEric Samelson // self is not a dictionary represented as an array of tuplets, so it isn't equal to object 17*17293a6fSEric Samelson return NO; 18*17293a6fSEric Samelson } 19*17293a6fSEric Samelson id key = member[0]; 20*17293a6fSEric Samelson id value = member[1]; 21*17293a6fSEric Samelson if (dictionaryToCompare[key] != nil) { 22*17293a6fSEric Samelson // there are multiple duplicate keys, so self is not in the format we would expect for a dictionary 23*17293a6fSEric Samelson return NO; 24*17293a6fSEric Samelson } 25*17293a6fSEric Samelson dictionaryToCompare[key] = value; 26*17293a6fSEric Samelson } 27*17293a6fSEric Samelson return [dictionaryToCompare.copy isEqualToDictionary:object]; 28*17293a6fSEric Samelson } 29*17293a6fSEric Samelson 30*17293a6fSEric Samelson // plain isEqual implementation 31*17293a6fSEric Samelson if (self == object) { 32*17293a6fSEric Samelson return YES; 33*17293a6fSEric Samelson } 34*17293a6fSEric Samelson if (![object isKindOfClass:[NSArray class]]) { 35*17293a6fSEric Samelson return NO; 36*17293a6fSEric Samelson } 37*17293a6fSEric Samelson return [self isEqualToArray:object]; 38*17293a6fSEric Samelson} 39*17293a6fSEric Samelson 40*17293a6fSEric Samelson@end 41*17293a6fSEric Samelson 42*17293a6fSEric SamelsonNS_ASSUME_NONNULL_END 43