<commit_before>//
//  BONBaseTestCase.m
//  BonMot
//
//  Created by <NAME> on 7/10/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

@import XCTest;
#import "NSDictionary+BONEquality.h"

OBJC_EXTERN NSValue *BONValueFromRange(NSUInteger location, NSUInteger length);

#define _BONTPrimitiveAssertCloseEnoughDictionaries(test, expression1, expressionStr1, expression2, expressionStr2, ...) \
({ \
    @try { \
        id expressionValue1 = (expression1); \
        id expressionValue2 = (expression2); \
        if (![expressionValue1 bon_isCloseEnoughEqualToDictionary:expressionValue2]) { \
            _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_EqualObjects, 0, expressionStr1, expressionStr2, expressionValue1, expressionValue2), __VA_ARGS__); \
        } \
    } \
    @catch (_XCTestCaseInterruptionException *interruption) { [interruption raise]; } \
    @catch (NSException *exception) { \
        _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_EqualObjects, 1, expressionStr1, expressionStr2, [exception reason]), __VA_ARGS__); \
    } \
    @catch (...) { \
        _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_EqualObjects, 2, expressionStr1, expressionStr2), __VA_ARGS__); \
    } \
})

#define BONAssertEqualDictionaries(expression1, expression2, ...) \
_BONTPrimitiveAssertCloseEnoughDictionaries(self, expression1, @#expression1, expression2, @#expression2, __VA_ARGS__)

/**
 *  Uses XCTest assertions to check that the attributes of @c attributedString match the attributes and ranges in @c controlAttributes.
 *
 *  @param attributedString  The attributed string to validate.
 *  @param controlAttributes A dictionary whose keys are @c NSValue objects containing @c NSRange structs, and whose values are attributes dictionaries.
 */
#define BONAssertAttributedStringHasAttributes(attributedString, controlAttributes) \
NSMutableDictionary *mutableControlAttributes = controlAttributes.mutableCopy; \
[attributedString enumerateAttributesInRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { \
    NSValue *testRangeValue = [NSValue valueWithRange:range]; \
    NSDictionary *controlAttrs = controlAttributes[testRangeValue]; \
    XCTAssertNotNil(controlAttrs, @"Attributed String had attributes that were not accounted for at %@: %@", NSStringFromRange(range), attrs); \
    BONAssertEqualDictionaries(attrs, controlAttrs); \<commit_msg>Rename macro to something that Xcode 7 finds more palatable.<commit_after>//
//  BONBaseTestCase.m
//  BonMot
//
//  Created by <NAME> on 7/10/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

@import XCTest;
#import "NSDictionary+BONEquality.h"

OBJC_EXTERN NSValue *BONValueFromRange(NSUInteger location, NSUInteger length);

#define BONTPrimitiveAssertCloseEnoughDictionaries(test, expression1, expressionStr1, expression2, expressionStr2, ...) \
({ \
    @try { \
        id expressionValue1 = (expression1); \
        id expressionValue2 = (expression2); \
        if (![expressionValue1 bon_isCloseEnoughEqualToDictionary:expressionValue2]) { \
            _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_EqualObjects, 0, expressionStr1, expressionStr2, expressionValue1, expressionValue2), __VA_ARGS__); \
        } \
    } \
    @catch (_XCTestCaseInterruptionException *interruption) { [interruption raise]; } \
    @catch (NSException *exception) { \
        _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_EqualObjects, 1, expressionStr1, expressionStr2, [exception reason]), __VA_ARGS__); \
    } \
    @catch (...) { \
        _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_EqualObjects, 2, expressionStr1, expressionStr2), __VA_ARGS__); \
    } \
})

#define BONAssertEqualDictionaries(expression1, expression2, ...) \
BONTPrimitiveAssertCloseEnoughDictionaries(self, expression1, @#expression1, expression2, @#expression2, __VA_ARGS__)

/**
 *  Uses XCTest assertions to check that the attributes of @c attributedString match the attributes and ranges in @c controlAttributes.
 *
 *  @param attributedString  The attributed string to validate.
 *  @param controlAttributes A dictionary whose keys are @c NSValue objects containing @c NSRange structs, and whose values are attributes dictionaries.
 */
#define BONAssertAttributedStringHasAttributes(attributedString, controlAttributes) \
NSMutableDictionary *mutableControlAttributes = controlAttributes.mutableCopy; \
[attributedString enumerateAttributesInRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { \
    NSValue *testRangeValue = [NSValue valueWithRange:range]; \
    NSDictionary *controlAttrs = controlAttributes[testRangeValue]; \
    XCTAssertNotNil(controlAttrs, @"Attributed String had attributes that were not accounted for at %@: %@", NSStringFromRange(range), attrs); \
    BONAssertEqualDictionaries(attrs, controlAttrs); \
{'fraction_non_alphanumeric': 0.09982068141063957, 'fraction_numerical': 0.015341701534170154, 'mean_word_length': 5.099635479951397, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6488012', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1429, 'n_words': 339}