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