text:
//
//  RKValueTransformerTest.m
//  RestKit
//
//  Created by Samuel E. Giddins on 6/13/13.
//  Copyright (c) 2013 RestKit. All rights reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import <XCTest/XCTest.h>
#define EXP_SHORTHAND
#import "Expecta.h"
#import "RKValueTransformers.h"

// Used to test subclass raising
@interface RKIncompleteValueTransformer : RKValueTransformer
@end

@implementation RKIncompleteValueTransformer
@end

@interface RKValueTransformerTest : XCTestCase
@end

@implementation RKValueTransformerTest

#pragma mark - Abstract Class Tests

- (void)testThatDirectInstantiationOfRKValueTransformerRaises
{
    expect(^{ [RKValueTransformer new]; }).to.raiseWithReason(NSInternalInconsistencyException, @"`RKValueTransformer` is abstract and cannot be directly instantiated. Instantiate a subclass implementation instead.");
}

- (void)testThatIncompleteSubclassesRaiseOnTransformation
{
    RKIncompleteValueTransformer *incompleteTransformer = [RKIncompleteValueTransformer new];
    expect(^{ [incompleteTransformer transformValue:nil toValue:nil ofClass:Nil error:nil]; }).to.raiseWithReason(NSInternalInconsistencyException, @"`RKValueTransformer` subclasses must provide a concrete implementation of `transformValue:toValue:ofClass:error:`.");
}

#pragma mark - Default Transformers

#pragma mark String to URL

- (void)testStringToURLTransformerValidationSuccessFromStringToURL
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSURL class]];
    expect(success).to.beTruthy();
}

- (void)testStringToURLTransformerValidationSuccessFromURLToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSURL class]];
    expect(success).to.beTruthy();
}

- (void)testStringToURLTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSURL class]];
    expect(success).to.beFalsy();
}

- (void)testStringToURLTransformerTransformationSuccessFromStringToURL
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSURL class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beInstanceOf([NSURL class]);
    expect(value).to.equal([NSURL URLWithString:@"http://restkit.org"]);
}

- (void)testStringToURLTransformerTransformationSuccessFromURLToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    NSString *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSURL URLWithString:@"http://restkit.org"] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"http://restkit.org");
}

- (void)testStringToURLTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testStringToURLTransformerFailureWithInvalidInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@":*7vxck#sf#adsa" toValue:&value ofClass:[NSURL class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testStringToURLTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer stringToURLValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Number to String

- (void)testNumberToStringTransformerValidationSuccessFromStringToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSNumber class]];
    expect(success).to.beTruthy();
}

- (void)testNumberToStringTransformerValidationFromNumberToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSString class]];
    expect(success).to.beTruthy();
}

- (void)testNumberToStringTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSNumber class]];
    expect(success).to.beFalsy();
}

- (void)testNumberToStringTransformerTransformationSuccessFromStringToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"12345" toValue:&value  ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSNumber class]);
    expect(value).to.equal(@12345);
}

- (void)testNumberToStringTransformerTransformationSuccessFromNumberToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"12345");
}

- (void)testNumberToStringTransformerTransformationSuccessFromStringToBooleanNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"12345");
}

- (void)testNumberToStringTransformerTransformationSuccessFromBooleanNumberToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    [valueTransformer transformValue:[NSNumber numberWithBool:YES] toValue:&value ofClass:[NSString class] error:&error];
    expect(value).to.equal(@"true");
    [valueTransformer transformValue:[NSNumber numberWithBool:NO] toValue:&value ofClass:[NSString class] error:&error];
    expect(value).to.equal(@"false");
}

- (void)testNumberToStringTransformerTransformationSuccessFromBooleanStringToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;

    // True
    [valueTransformer transformValue:@"true" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"TRUE" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"t" toValue:&value ofClass:[NSNumber class]error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"T" toValue:&value ofClass:[NSNumber class]error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"yes" toValue:&value ofClass:[NSNumber class]error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"YES" toValue:&value ofClass:[NSNumber class]error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"y" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"Y" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);
    [valueTransformer transformValue:@"1" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:YES]);

    // False
    [valueTransformer transformValue:@"false" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"FALSE" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"f" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"F" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"no" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"NO" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"f" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"F" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
    [valueTransformer transformValue:@"0" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(value).to.equal([NSNumber numberWithBool:NO]);
}

- (void)testNumberToStringTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testNumberToStringTransformerTransformsNonsenseStringToZero
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@":*7vxck#sf#adsa" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.equal(0);
}

- (void)testNumberToStringTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer numberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Number to BOOL

- (void)testNumberToBOOLValueTransformationForFalseValue
{
    RKCompoundValueTransformer *valueTransformer = [RKValueTransformer defaultValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@0 toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.equal(@(NO));
}

- (void)testNumberToBOOLValueTransformationForTrueValue
{
    RKCompoundValueTransformer *valueTransformer = [RKValueTransformer defaultValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@1 toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.equal(@(YES));
}

- (void)testNumberToArm64BOOLValueTransformationForTrueValue {
    Class booleanClass = NSClassFromString(@"__NSCFBoolean");
    if (!booleanClass) return;
    RKCompoundValueTransformer *valueTransformer = [RKValueTransformer defaultValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@1 toValue:&value ofClass:booleanClass error:&error];
    expect(success).to.beTruthy();
    expect(value).to.equal(@(YES));
}

#pragma mark Array to Ordered Set

- (void)testArrayToOrderedSetTransformerValidationSuccessFromArrayToOrderedSet
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSArray class] toClass:[NSOrderedSet class]];
    expect(success).to.beTruthy();
}

- (void)testArrayToOrderedSetTransformerValidationSuccessFromOrderedSetToArray
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSArray class] toClass:[NSOrderedSet class]];
    expect(success).to.beTruthy();
}

- (void)testArrayToOrderedSetTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSOrderedSet class]];
    expect(success).to.beFalsy();
}

- (void)testArrayToOrderedSetTransformerTransformationSuccessFromArrayToOrderedSet
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[ @"one", @"two", @"three" ] toValue:&value ofClass:[NSOrderedSet class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSOrderedSet class]);
    expect(value).to.equal(([NSOrderedSet orderedSetWithArray:@[ @"one", @"two", @"three" ]]));
}

- (void)testArrayToOrderedSetTransformerTransformationSuccessFromOrderedSetToArray
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    NSString *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSOrderedSet orderedSetWithArray:@[ @"one", @"two", @"three" ]] toValue:&value ofClass:[NSArray class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSArray class]);
    expect(value).to.equal((@[ @"one", @"two", @"three" ]));
}

- (void)testArrayToOrderedSetTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSOrderedSet class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testArrayToOrderedSetTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToOrderedSetValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Array to Set

- (void)testArrayToSetTransformerValidationSuccessFromArrayToSet
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSArray class] toClass:[NSSet class]];
    expect(success).to.beTruthy();
}

- (void)testArrayToSetTransformerValidationSuccessFromSetToArray
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSArray class] toClass:[NSSet class]];
    expect(success).to.beTruthy();
}

- (void)testArrayToSetTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSSet class]];
    expect(success).to.beFalsy();
}

- (void)testArrayToSetTransformerTransformationSuccessFromArrayToSet
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[ @"one", @"two", @"three" ] toValue:&value ofClass:[NSSet class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSSet class]);
    expect(value).to.equal(([NSSet setWithArray:@[ @"one", @"two", @"three" ]]));
}

- (void)testArrayToSetTransformerTransformationSuccessFromSetToArray
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    NSString *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSSet setWithArray:@[ @"one", @"two", @"three" ]] toValue:&value ofClass:[NSSet class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSArray class]);
    expect(value).to.equal((@[ @"one", @"two", @"three" ]));
}

- (void)testArrayToSetTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSArray class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testArrayToSetTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer arrayToSetValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Decimal Number to String

- (void)testDecimalNumberToStringTransformerValidationSuccessFromDecimalNumberToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDecimalNumber class] toClass:[NSString class]];
    expect(success).to.beTruthy();
}

- (void)testDecimalNumberToStringTransformerValidationSuccessFromStringToDecimalNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSDecimalNumber class]];
    expect(success).to.beTruthy();
}

- (void)testDecimalNumberToStringTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSString class]];
    expect(success).to.beFalsy();
}

- (void)testDecimalNumberToStringTransformerTransformationSuccessFromDecimalNumberToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSDecimalNumber decimalNumberWithString:@"123456.7890"] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"123456.789");
}

- (void)testDecimalNumberToStringTransformerTransformationSuccessFromStringToDecimalNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    NSString *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"123456.7890" toValue:&value ofClass:[NSDecimalNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDecimalNumber class]);
    expect(value).to.equal([NSDecimalNumber decimalNumberWithString:@"123456.7890"]);
}

- (void)testDecimalNumberToStringTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testDecimalNumberToStringTransformerFailureWithTransformationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"abdskjfsdkfjs" toValue:&value ofClass:[NSDecimalNumber class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testDecimalNumberToStringTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToStringValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"12345.00" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Decimal Number to Number

- (void)testDecimalNumberToNumberTransformerValidationSuccessFromDecimalNumberToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDecimalNumber class] toClass:[NSNumber class]];
    expect(success).to.beTruthy();
}

- (void)testDecimalNumberToNumberTransformerValidationSuccessFromNumberToDecimalNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSDecimalNumber class]];
    expect(success).to.beTruthy();
}

- (void)testDecimalNumberToNumberTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSNumber class]];
    expect(success).to.beFalsy();
}

- (void)testDecimalNumberToNumberTransformerTransformationSuccessFromDecimalNumberToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSDecimalNumber decimalNumberWithString:@"123456.7890"] toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSNumber class]);
    expect(value).to.equal([NSDecimalNumber decimalNumberWithString:@"123456.7890"]);
}

- (void)testDecimalNumberToNumberTransformerTransformationSuccessFromNumberToDecimalNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    NSNumber *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@123456.7890 toValue:&value ofClass:[NSDecimalNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDecimalNumber class]);
    expect(value).to.equal([NSDecimalNumber decimalNumberWithString:@"123456.7890"]);
}

- (void)testDecimalNumberToNumberTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testDecimalNumberToNumberTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer decimalNumberToNumberValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Null

- (void)testNullTransformerValidationSuccessFromObjectToObject
{
    RKValueTransformer *valueTransformer = [RKValueTransformer nullValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSObject class] toClass:[NSObject class]];
    expect(success).to.beTruthy();
}

- (void)testNullTransformerTransformationSuccessFromNullToNil
{
    RKValueTransformer *valueTransformer = [RKValueTransformer nullValueTransformer];
    NSNumber *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSNull null] toValue:&value ofClass:Nil error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beNil();
}

- (void)testNullTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer nullValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:Nil error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testDecimalNumberToNumberTransformerSucceedsWithAnyOutputClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer nullValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSNull null] toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beNil();
}

#pragma mark Keyed Archiving

- (void)testKeyedArchivingTransformerValidationSuccessFromNSCodingCompliantToData
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDictionary class] toClass:[NSData class]];
    expect(success).to.beTruthy();
}

- (void)testKeyedArchivingTransformerValidationSuccessFromDataToNSCodingCompliant
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSData class] toClass:[NSDictionary class]];
    expect(success).to.beTruthy();
}

- (void)testKeyedArchivingTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSData class] toClass:[NSObject class]];
    expect(success).to.beFalsy();
}

- (void)testKeyedArchivingTransformerSuccessFromDataToDictionary
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    NSDictionary *dictionary = @{ @"key": @"value" };
    NSData *data = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:dictionary toValue:&data ofClass:[NSData class] error:&error];
    expect(success).to.beTruthy();
    expect(data).notTo.beNil();
    id<NSCoding> decodedObject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    expect(decodedObject).to.equal(dictionary);
}

- (void)testKeyedArchivingTransformerSuccessFromDictionaryToData
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    NSDictionary *dictionary = @{ @"key": @"value" };
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dictionary];
    NSError *error = nil;
    id<NSCoding> result = nil;
    BOOL success = [valueTransformer transformValue:data toValue:&result ofClass:[NSDictionary class] error:&error];
    expect(success).to.beTruthy();
    expect(result).notTo.beNil();
    expect(result).to.equal(dictionary);
}

- (void)testKeyedArchivingTransformerFailureWithInvalidInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    id<NSCoding> result = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSObject new] toValue:&result ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(result).to.beNil();
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testKeyedArchivingTransformerFailureWithNonDecodableData
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    id<NSCoding> result = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[@"this is invalid" dataUsingEncoding:NSUTF8StringEncoding] toValue:&result ofClass:[NSDictionary class] error:&error];
    expect(success).to.beFalsy();
    expect(result).to.beNil();
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testKeyedArchivingTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@{ @"key": @"value" } toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

- (void)testKeyedArchivingTransformerFailureDueToDesintationTypeMismatch
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyedArchivingValueTransformer];
    id value = nil;
    NSError *error = nil;
    NSDictionary *dictionary = @{ @"key": @"value" };
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dictionary];
    BOOL success = [valueTransformer transformValue:data toValue:&value ofClass:[NSArray class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

#pragma mark - Time Interval Since 1970 to Date

- (void)testTimeIntervalSince1970ToDateValueTransformerValidationSuccessFromNumberToDate
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSDate class]];
    expect(success).to.beTruthy();
}

- (void)testTimeIntervalSince1970ToDateValueTransformerValidationSuccessFromStringToDate
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSDate class]];
    expect(success).to.beTruthy();
}

- (void)testTimeIntervalSince1970ToDateValueTransformerValidationSuccessFromDateToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDate class] toClass:[NSNumber class]];
    expect(success).to.beTruthy();
}

- (void)testTimeIntervalSince1970ToDateValueTransformerValidationSuccessFromDateToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDate class] toClass:[NSString class]];
    expect(success).to.beTruthy();
}

- (void)testTimeIntervalSince1970ToDateValueTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSURL class]];
    expect(success).to.beFalsy();
}

- (void)testTimeIntervalSince1970ToDateValueTransformerTransformationSuccessFromNumberToDate
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@0 toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"1970-01-01 00:00:00 +0000");
}

- (void)testTimeIntervalSince1970ToDateValueTransformerTransformationSuccessFromStringToDate
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"0" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"1970-01-01 00:00:00 +0000");
}

- (void)testTimeIntervalSince1970ToDateValueTransformerTransformationSuccessFromDateToNumber
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    NSDate *inputValue = [NSDate dateWithTimeIntervalSince1970:0];
    BOOL success = [valueTransformer transformValue:inputValue toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSNumber class]);
    expect(value).to.equal(0);
}

- (void)testTimeIntervalSince1970ToDateValueTransformerTransformationSuccessFromDateToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    NSDate *inputValue = [NSDate dateWithTimeIntervalSince1970:0];
    BOOL success = [valueTransformer transformValue:inputValue toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"0");
}

- (void)testTimeIntervalSince1970ToDateValueTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testTimeIntervalSince1970ToDateValueTransformerFailureWithInvalidInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@":*7vxck#sf#adsa" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testTimeIntervalSince1970ToDateValueTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer timeIntervalSince1970ToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark - ISO 8601 Timestamp String to Date

- (void)testIso8601TimestampToDateValueTransformerValidationSuccessFromStringToDate
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSDate class]];
    expect(success).to.beTruthy();
}

- (void)testIso8601TimestampToDateValueTransformerValidationSuccessFromDateToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDate class] toClass:[NSString class]];
    expect(success).to.beTruthy();
}

- (void)testIso8601TimestampToDateValueTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSURL class]];
    expect(success).to.beFalsy();
}

- (void)testIso8601TimestampToDateValueTransformerTransformationSuccessFromStringToDate
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"2013-09-11T09:24:56-04:00" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"2013-09-11 13:24:56 +0000");
}

- (void)testIso8601TimestampToDateValueTransformerTransformationSuccessFromStringToDateWithMilliseconds
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"2013-09-11T09:24:56.123-04:00" toValue:&value ofClass:[NSDate class] error:&error];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
    formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSString *formattedValue = [formatter stringFromDate:value];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect(formattedValue).to.equal(@"2013-09-11T13:24:56.123");
}

- (void)testIso8601TimestampToDateValueTransformerTransformationSuccessFromStringToDateWithMicroseconds
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"2013-09-11T09:24:56.123456-04:00" toValue:&value ofClass:[NSDate class] error:&error];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
    formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSString *formattedValue = [formatter stringFromDate:value];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect(formattedValue).to.equal(@"2013-09-11T13:24:56.123");
}

- (void)testIso8601TimestampToDateValueTransformerTransformationValidationWithBatteryOfInputValues
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    NSError *error = nil;
    NSArray *parsableDateStrings = @[ @"2009-05-11 14:39:22",
                                      @"2009-05-11T14:39:22",
                                      @"2009-05-11T10:39:22-04:00",
                                      @"2009-05-11T14:39:22-00:00",
                                      @"2009-05-11T14:39:22-0000",
                                      @"2009-05-11T14:39:22Z"];
    for (NSString *dateString in parsableDateStrings) {
        NSDate *date = nil;
        BOOL success = [valueTransformer transformValue:dateString toValue:&date ofClass:[NSDate class] error:&error];
        XCTAssertTrue(success, @"Expected to be able to parse '%@' but could not: %@", dateString, error);

        expect(success).to.beTruthy();
        expect(date).to.beKindOf([NSDate class]);
        expect(@([date timeIntervalSince1970])).to.equal(@(1242052762));
    }

    parsableDateStrings = @[ @"2009-05-11 14:39:22.777",
                             @"2009-05-11T14:39:22.777",
                             @"2009-05-11T14:39:22.777-00:00",
                             @"2009-05-11T14:39:22.777-0000",
                             @"2009-05-11T14:39:22.777Z"];

    for (NSString *dateString in parsableDateStrings) {
        NSDate *date = nil;
        BOOL success = [valueTransformer transformValue:dateString toValue:&date ofClass:[NSDate class] error:&error];
        XCTAssertTrue(success, @"Expected to be able to parse '%@' but could not: %@", dateString, error);

        expect(success).to.beTruthy();
        expect(date).to.beKindOf([NSDate class]);
        expect(@([date timeIntervalSince1970])).to.equal(@(1242052762.777));
    }

    // NOTE: These are *all* valid ISO 8601 date strings according to the spec, but cannot be handled by the transformer. Validation must reject these input values to prevent erroneous parsing.
    NSArray *unparsableDateStrings = @[@"2011-08-09T00:00Z", // No seconds...
                                       @"2009-12T12:34",
                                       @"2009",
                                       @"2009-05-19",
                                       @"2009-05-19",
                                       @"20090519",
                                       @"2009123",
                                       @"2009-05",
                                       @"2009-123",
                                       @"2009-222",
                                       @"2009-001",
                                       @"2009-W01-1",
                                       @"2009-W51-1",
                                       @"2009-W511",
                                       @"2009-W33",
                                       @"2009W511",
                                       @"2009-05-19",
                                       @"2009-05-19 00:00",
                                       @"2009-05-19 14",
                                       @"2009-05-19 14:31",
                                       @"2009-05-19T14:39Z",
                                       @"2009-W21-2",
                                       @"2009-W21-2T01:22",
                                       @"2009-139",
                                       @"20090621T0545Z",
                                       @"2007-04-06T00:00",
                                       @"2007-04-05T24:00",];
    for (NSString *dateString in unparsableDateStrings) {
        NSDate *date = nil;
        BOOL success = [valueTransformer transformValue:dateString toValue:&date ofClass:[NSDate class] error:&error];
        XCTAssertFalse(success, @"Expected NOT to be able to parse '%@' but could.", dateString);
    }
}

- (void)testIso8601TimestampToDateValueTransformerTransformationSuccessFromDateToString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    NSDate *inputValue = [NSDate dateWithTimeIntervalSince1970:0];
    BOOL success = [valueTransformer transformValue:inputValue toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"1970-01-01T00:00:00.000Z");
}

/**
 NOTE: This test has divergent behavior based on whether the host is 32 or 64bit. Under a system with a 32bit long (from which type_t is typedef'd) the maximum year representable is 2038.
 */
- (void)testIso8601TimestampToDateValueTransformerTransformationFailsValidationFromStringToDateWithYearPast2038
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"3001-09-11T09:24:56-04:00" toValue:&value ofClass:[NSDate class] error:&error];
    if (success) {
        expect(value).to.beKindOf([NSDate class]);
        expect([value description]).to.equal(@"3001-09-11 13:24:56 +0000");
    } else {
        expect(error.domain).to.equal(RKValueTransformersErrorDomain);
        expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
    }
}

- (void)testIso8601TimestampToDateValueTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testIso8601TimestampToDateValueTransformerFailureWithInvalidInputValueEmptyString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testIso8601TimestampToDateValueTransformerFailureWithInvalidInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@":*7vxck#sf#adsa" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testIso8601TimestampToDateValueTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer iso8601TimestampToDateValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Default Date String Formats

- (void)testRFC1123StringToDateValueTransformerTransformationSuccessFromStringToDate
{
    RKCompoundValueTransformer *valueTransformer = [RKValueTransformer defaultValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"Sun, 06 Nov 1994 08:49:37 GMT" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"1994-11-06 08:49:37 +0000");
}

- (void)testRFC850StringToDateValueTransformerTransformationSuccessFromStringToDate
{
    RKCompoundValueTransformer *valueTransformer = [RKValueTransformer defaultValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"Sunday, 06-Nov-94 08:49:37 GMT" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"1994-11-06 08:49:37 +0000");
}

- (void)testANSICStringToDateValueTransformerTransformationSuccessFromStringToDate
{
    RKCompoundValueTransformer *valueTransformer = [RKValueTransformer defaultValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"Sun Nov  6 08:49:37 1994" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"1994-11-06 08:49:37 +0000");
}

#pragma mark Mutable Value

- (void)testMutableValueTransformerValidationSuccessFromString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSMutableString class]];
    expect(success).to.beTruthy();
}

- (void)testMutableValueTransformerValidationSuccessFromArray
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSArray class] toClass:[NSMutableArray class]];
    expect(success).to.beTruthy();
}

- (void)testMutableValueTransformerValidationSuccessFromSet
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSSet class] toClass:[NSMutableSet class]];
    expect(success).to.beTruthy();
}

- (void)testMutableValueTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSURL class]];
    expect(success).to.beFalsy();
}

- (void)testMutableValueTransformerTransformationSuccessFromString
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSMutableString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSMutableString class]);
    expect(value).to.equal([NSMutableString stringWithString:@"http://restkit.org"]);
}

- (void)testMutableValueTransformerTransformationSuccessFromArray
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    NSString *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[ @"one", @"two" ] toValue:&value ofClass:[NSMutableArray class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSMutableArray class]);
    expect(value).to.equal(([NSMutableArray arrayWithObjects:@"one", @"two", nil]));
}

- (void)testMutableValueTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@12345 toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testMutableValueTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer mutableValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

#pragma mark Copyable Object to NSDictionary

- (void)testKeyOfDictionaryValueTransformerValidationSuccessFromCopyableToDictionary
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSDictionary class]];
    expect(success).to.beTruthy();
}

- (void)testKeyOfDictionaryValueTransformerValidationSuccessFromCopyableToMutableDictionary
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSMutableDictionary class]];
    expect(success).to.beTruthy();
}

- (void)testKeyOfDictionaryValueTransformerValidationFailure
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSObject class] toClass:[NSDictionary class]];
    expect(success).to.beFalsy();
}

- (void)testKeyOfDictionaryValueTransformerTransformationSuccessFromStringToDictionary
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"key" toValue:&value ofClass:[NSDictionary class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDictionary class]);
    expect(value).to.equal(@{ @"key": @{}});
}

- (void)testKeyOfDictionaryValueTransformerTransformationSuccessFromStringToNSMutableDictionary
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    NSString *value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"key" toValue:&value ofClass:[NSMutableDictionary class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSMutableDictionary class]);
    expect(value).to.equal(([@{ @"key": [@{} mutableCopy] } mutableCopy]));
}

- (void)testKeyOfDictionaryValueTransformerFailureWithUntransformableInputValue
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSObject new] toValue:&value ofClass:[NSDictionary class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testKeyOfDictionaryValueTransformerFailureWithInvalidDestinationClass
{
    RKValueTransformer *valueTransformer = [RKValueTransformer keyOfDictionaryValueTransformer];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"key" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

@end

static RKBlockValueTransformer *RKTestValueTransformerWithOutputValue(id staticOutputValue)
{
    return [RKBlockValueTransformer valueTransformerWithValidationBlock:nil transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, Class outputValueClass, NSError *__autoreleasing *error) {
        *outputValue = staticOutputValue;
        return YES;
    }];
}

@interface RKCompoundValueTransformerTest : XCTestCase
@end

@implementation RKCompoundValueTransformerTest

- (void)testAddingValueTransformer
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    expect([compoundValueTransformer numberOfValueTransformers]).to.equal(0);
    [compoundValueTransformer addValueTransformer:RKTestValueTransformerWithOutputValue(@"OK")];
    expect([compoundValueTransformer numberOfValueTransformers]).to.equal(1);
}

- (void)testRemovingValueTransformer
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    expect([compoundValueTransformer numberOfValueTransformers]).to.equal(0);
    RKValueTransformer *addedTransformer = RKTestValueTransformerWithOutputValue(@"OK");
    [compoundValueTransformer addValueTransformer:addedTransformer];
    expect([compoundValueTransformer numberOfValueTransformers]).to.equal(1);
    [compoundValueTransformer removeValueTransformer:RKTestValueTransformerWithOutputValue(@"invalid")];
    expect([compoundValueTransformer numberOfValueTransformers]).to.equal(1);
    [compoundValueTransformer removeValueTransformer:addedTransformer];
    expect([compoundValueTransformer numberOfValueTransformers]).to.equal(0);
}

- (void)testInsertingValueTransformer
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    RKValueTransformer *firstTransformer = RKTestValueTransformerWithOutputValue(@"1");
    [compoundValueTransformer addValueTransformer:firstTransformer];
    RKValueTransformer *secondTransformer = RKTestValueTransformerWithOutputValue(@"2");
    [compoundValueTransformer addValueTransformer:secondTransformer];
    RKValueTransformer *thirdTransformer = RKTestValueTransformerWithOutputValue(@"3");
    [compoundValueTransformer insertValueTransformer:thirdTransformer atIndex:0];
    NSArray *valueTransformers = [compoundValueTransformer valueTransformersForTransformingFromClass:Nil toClass:Nil];
    expect(valueTransformers[0]).to.equal(thirdTransformer);
}

- (void)testRetrievingValueTransformersBySourceToDestinationClass
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    RKValueTransformer *stringToValueTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSString class]] && [destinationClass isSubclassOfClass:[NSValue class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:stringToValueTransformer];
    RKValueTransformer *stringToNumberTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSString class]] && [destinationClass isSubclassOfClass:[NSNumber class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:stringToNumberTransformer];
    RKValueTransformer *stringToDecimalNumberTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSString class]] && [destinationClass isSubclassOfClass:[NSDecimalNumber class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:stringToDecimalNumberTransformer];
    RKValueTransformer *numberToStringValueTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSNumber class]] && [destinationClass isSubclassOfClass:[NSString class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:numberToStringValueTransformer];

    expect([compoundValueTransformer valueTransformersForTransformingFromClass:[NSString class] toClass:[NSValue class]]).to.equal((@[ stringToValueTransformer ]));
    expect([compoundValueTransformer valueTransformersForTransformingFromClass:[NSString class] toClass:[NSNumber class]]).to.equal((@[ stringToValueTransformer, stringToNumberTransformer ]));
    expect([compoundValueTransformer valueTransformersForTransformingFromClass:[NSString class] toClass:[NSDecimalNumber class]]).to.equal((@[ stringToValueTransformer, stringToNumberTransformer, stringToDecimalNumberTransformer ]));
    expect([compoundValueTransformer valueTransformersForTransformingFromClass:[NSNumber class] toClass:[NSString class]]).to.equal((@[ numberToStringValueTransformer ]));
    expect([compoundValueTransformer valueTransformersForTransformingFromClass:[NSNumber class] toClass:[NSArray class]]).to.beEmpty();
}

#pragma mark RKValueTransforming

- (void)testValidatingValueTransformation
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    RKValueTransformer *stringToValueTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSString class]] && [destinationClass isSubclassOfClass:[NSValue class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:stringToValueTransformer];
    RKValueTransformer *stringToNumberTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSString class]] && [destinationClass isSubclassOfClass:[NSNumber class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:stringToNumberTransformer];
    RKValueTransformer *stringToDecimalNumberTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSString class]] && [destinationClass isSubclassOfClass:[NSDecimalNumber class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:stringToDecimalNumberTransformer];
    RKValueTransformer *numberToStringValueTransformer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class sourceClass, __unsafe_unretained Class destinationClass) {
        return [sourceClass isSubclassOfClass:[NSNumber class]] && [destinationClass isSubclassOfClass:[NSString class]];
    } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        return NO;
    }];
    [compoundValueTransformer addValueTransformer:numberToStringValueTransformer];

    expect([compoundValueTransformer validateTransformationFromClass:[NSString class] toClass:[NSValue class]]).to.beTruthy();
    expect([compoundValueTransformer validateTransformationFromClass:[NSString class] toClass:[NSNumber class]]).to.beTruthy();
    expect([compoundValueTransformer validateTransformationFromClass:[NSString class] toClass:[NSDecimalNumber class]]).to.beTruthy();
    expect([compoundValueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSString class]]).to.beTruthy();
    expect([compoundValueTransformer validateTransformationFromClass:[NSString class] toClass:[NSData class]]).to.beFalsy();
}

- (void)testTransformingValueSuccessfully
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    RKValueTransformer *firstTransformer = RKTestValueTransformerWithOutputValue(@"1");
    [compoundValueTransformer addValueTransformer:firstTransformer];
    NSString *outputValue;
    NSError *error = nil;
    BOOL success = [compoundValueTransformer transformValue:@"2" toValue:&outputValue ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(outputValue).to.equal(@"1");
}

- (void)testTransformingValueSuccessfullyRespectsOrderingOfTransformers
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    [compoundValueTransformer addValueTransformer:RKTestValueTransformerWithOutputValue(@"1")];
    [compoundValueTransformer addValueTransformer:RKTestValueTransformerWithOutputValue(@"2")];
    [compoundValueTransformer insertValueTransformer:RKTestValueTransformerWithOutputValue(@"3") atIndex:0];
    NSString *outputValue;
    NSError *error = nil;
    BOOL success = [compoundValueTransformer transformValue:@"2" toValue:&outputValue ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(outputValue).to.equal(@"3");
}

- (void)testTransformingValueFailsWithError
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    [compoundValueTransformer addValueTransformer:[RKBlockValueTransformer valueTransformerWithValidationBlock:nil transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        // Always fails
        RKValueTransformerTestTransformation(NO, error, @"This is an underlying error.");
        return YES;
    }]];
    NSString *outputValue;
    NSError *error = nil;
    BOOL success = [compoundValueTransformer transformValue:@"2" toValue:&outputValue ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(outputValue).to.beNil();
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
    expect(error.localizedDescription).to.equal(@"Failed transformation of value '2' to NSString: none of the 1 value transformers consulted were successful.");
}

- (void)testTransformingErrorWithoutDetailedErrors
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    NSString *outputValue;
    NSError *error = nil;
    BOOL success = [compoundValueTransformer transformValue:@"2" toValue:&outputValue ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(outputValue).to.beNil();
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testTransformingErrorWithNullErrorParameter
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    [compoundValueTransformer addValueTransformer:[RKBlockValueTransformer valueTransformerWithValidationBlock:nil transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {
        // Always fails
        RKValueTransformerTestTransformation(NO, error, @"This is an underlying error.");
        return YES;
    }]];
    NSString *outputValue;
    BOOL success = [compoundValueTransformer transformValue:@"2" toValue:&outputValue ofClass:[NSString class] error:NULL];
    expect(success).to.beFalsy();
    expect(outputValue).to.beNil();
}

#pragma mark NSCopying

- (void)testCopying
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    RKValueTransformer *firstTransformer = RKTestValueTransformerWithOutputValue(@"1");
    [compoundValueTransformer addValueTransformer:firstTransformer];
    RKValueTransformer *secondTransformer = RKTestValueTransformerWithOutputValue(@"2");
    [compoundValueTransformer addValueTransformer:secondTransformer];
    RKCompoundValueTransformer *copiedTransformer = [compoundValueTransformer copy];
    expect(copiedTransformer).notTo.beNil();
    NSArray *valueTransformers = [copiedTransformer valueTransformersForTransformingFromClass:Nil toClass:Nil];
    expect(valueTransformers).to.equal((@[ firstTransformer, secondTransformer ]));
}

#pragma mark NSFastEnumeration

- (void)testFastEnumeration
{
    RKCompoundValueTransformer *compoundValueTransformer = [RKCompoundValueTransformer new];
    RKValueTransformer *firstTransformer = RKTestValueTransformerWithOutputValue(@"1");
    [compoundValueTransformer addValueTransformer:firstTransformer];
    RKValueTransformer *secondTransformer = RKTestValueTransformerWithOutputValue(@"2");
    [compoundValueTransformer addValueTransformer:secondTransformer];
    NSMutableArray *enumeratedTransformers = [NSMutableArray new];
    for (id<RKValueTransforming> valueTransformer in compoundValueTransformer) {
        [enumeratedTransformers addObject:valueTransformer];
    }
    expect(enumeratedTransformers).to.equal((@[ firstTransformer, secondTransformer ]));
}

@end

@interface RKValueTransformers_NSNumberFormatterTests : XCTestCase
@end

@implementation RKValueTransformers_NSNumberFormatterTests

- (void)testValidationFromStringToNumber
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSNumber class]];
    expect(success).to.beTruthy();
}

- (void)testValidationFromNumberToString
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSNumber class] toClass:[NSString class]];
    expect(success).to.beTruthy();
}

- (void)testValidationFailure
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSURL class] toClass:[NSString class]];
    expect(success).to.beFalsy();
}

- (void)testTransformationFromNumberToString
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    valueTransformer.numberStyle = NSNumberFormatterCurrencyStyle;
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@932480932840923 toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"$932,480,932,840,923.00");
}

- (void)testTransformationFromStringToNumber
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    valueTransformer.numberStyle = NSNumberFormatterCurrencyStyle;
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"$932,480,932,840,923.00" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSNumber class]);
    expect(value).to.equal(@932480932840923);
}

- (void)testTransformationFailureWithUntransformableInputValue
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testTransformationFailureFailureWithInvalidInputValue
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@":*7vxck#sf#adsa" toValue:&value ofClass:[NSNumber class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testTransformationFailureWithInvalidDestinationClass
{
    NSNumberFormatter *valueTransformer = [NSNumberFormatter new];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

@end

@interface RKValueTransformers_NSDateFormatterTests : XCTestCase
@end

@implementation RKValueTransformers_NSDateFormatterTests

- (void)testValidationFromStringToDate
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSString class] toClass:[NSDate class]];
    expect(success).to.beTruthy();
}

- (void)testValidationFromDateToString
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSDate class] toClass:[NSString class]];
    expect(success).to.beTruthy();
}

- (void)testValidationFailure
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    BOOL success = [valueTransformer validateTransformationFromClass:[NSURL class] toClass:[NSString class]];
    expect(success).to.beFalsy();
}

- (void)testTransformationFromDateToString
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    valueTransformer.dateStyle = NSDateFormatterFullStyle;
    valueTransformer.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    valueTransformer.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:[NSDate dateWithTimeIntervalSince1970:0] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSString class]);
    expect(value).to.equal(@"Thursday, January 1, 1970");
}

- (void)testTransformationFromStringToDAte
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    valueTransformer.dateStyle = NSDateFormatterFullStyle;
    valueTransformer.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    valueTransformer.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"Thursday, January 1, 1970" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beTruthy();
    expect(value).to.beKindOf([NSDate class]);
    expect([value description]).to.equal(@"1970-01-01 00:00:00 +0000");
}

- (void)testTransformationFailureWithUntransformableInputValue
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@[] toValue:&value ofClass:[NSString class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUntransformableInputValue);
}

- (void)testTransformationFailureFailureWithInvalidInputValue
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@":*7vxck#sf#adsa" toValue:&value ofClass:[NSDate class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorTransformationFailed);
}

- (void)testTransformationFailureWithInvalidDestinationClass
{
    NSDateFormatter *valueTransformer = [NSDateFormatter new];
    id value = nil;
    NSError *error = nil;
    BOOL success = [valueTransformer transformValue:@"http://restkit.org" toValue:&value ofClass:[NSData class] error:&error];
    expect(success).to.beFalsy();
    expect(value).to.beNil();
    expect(error).notTo.beNil();
    expect(error.domain).to.equal(RKValueTransformersErrorDomain);
    expect(error.code).to.equal(RKValueTransformationErrorUnsupportedOutputClass);
}

@end


text:
class User
  include SimplyStored::Couch

  property :email
  devise :database_authenticatable, :recoverable, :rememberable, :trackable

  validates_presence_of :email
end

redpajama_set_name: RedPajamaGithub


text:
require 'spec_helper'

module CenterImageTag
  describe ViewHelper do
    describe 'normal' do
      it 'renders the image normally if it\'s not fluid or width x height set' do
        output    = View.new.center_image_tag 'image.png'
        expected  = ""
        expect(output).to eq expected
      end

      it 'ignores container_class options' do
        output    = View.new.center_image_tag 'image.png', container_class: 'custom-class'
        expected  = ""
        expect(output).to eq expected
      end
    end

    describe 'fluid' do
      it 'renders the fluid image correctly' do
        output    = View.new.center_image_tag 'image.png', fluid: "56.25%"
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
      end

      it 'renders the fluid image with container class' do
        output    = View.new.center_image_tag 'image.png', fluid: "56.25%", container_class: 'custom-class'
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end
    end

    describe 'fixed' do
      it 'renders the fixed image correctly from size options (size = widthxheight)' do
        output    = View.new.center_image_tag 'image.png', size: "200x100"
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end

      it 'renders the fixed image correctly from size options (size = widthxheight) with container class' do
        output    = View.new.center_image_tag 'image.png', size: "200x100", container_class: 'custom-class'
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end

      it 'renders the fixed image correctly from size options (single size value)' do
        output    = View.new.center_image_tag 'image.png', size: "200"
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end

      it 'renders the fixed image correctly from size options (single size value) with container class' do
        output    = View.new.center_image_tag 'image.png', size: "200", container_class: 'custom-class'
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end

      it 'renders the fixed image correctly from width and height options' do
        output    = View.new.center_image_tag 'image.png', width: "200", height: 100
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end

      it 'renders the fixed image correctly from width and height options with container class' do
        output    = View.new.center_image_tag 'image.png', width: "200", height: 100, container_class: 'custom-class'
        expected  = "
" +
                      "
" +
                        "
" +
                          "
" +
                            "" +
                            "" +
                          "
" +
                        "
" +
                      "
" +
                    "
"
        expect(output).to eq expected
      end
    end
  end
end


text:
import pymel.core as pymel

from omtk.vendor import libSerialization
from omtk.vendor.Qt import QtGui

# todo: Move to a shared location
class MetadataType:
    """
    Used to quickly determine what metadata have been monkey-patched to a QWidget.
    """
    Rig = 0
    Module = 1
    Influece = 2
    Mesh = 3

# http://forums.cgsociety.org/archive/index.php?t-1096914.html
# Use the intern maya ressources icon
_STYLE_SHEET = \
    """

      QTreeView::item::selected
      {
         background-color: highlight;
         color: rgb(40,40,40);
      }

      QTreeView::branch
      {
           selection-background-color: highlight;
           background-color: rgb(45,45,45);
       }

        QTreeView::branch:has-children:!has-siblings:closed,
        QTreeView::branch:closed:has-children:has-siblings
        {
                border-image: none;
                image: url(:/openObject.png);
        }

        QTreeView::branch:open:has-children:!has-siblings,
        QTreeView::branch:open:has-children:has-siblings
        {
                border-image: none;
                image: url(:/closeObject.png);
        }

        QTreeView::indicator:checked
        {
            image: url(:/checkboxOn.png);
        }

        QTreeView::indicator:unchecked
        {
            image: url(:/checkboxOff.png);
        }
    """

def _set_icon_from_type(obj, qItem):
    if isinstance(obj, pymel.nodetypes.Joint):
        qItem.setIcon(0, QtGui.QIcon(":/pickJointObj.png"))
    elif isinstance(obj, pymel.nodetypes.Transform):
        _set_icon_from_type(obj.getShape(), qItem)
    elif isinstance(obj, pymel.nodetypes.NurbsCurve):
        qItem.setIcon(0, QtGui.QIcon(":/nurbsCurve.svg"))
    elif isinstance(obj, pymel.nodetypes.NurbsSurface):
        qItem.setIcon(0, QtGui.QIcon(":/nurbsSurface.svg"))
    elif isinstance(obj, pymel.nodetypes.Mesh):
        qItem.setIcon(0, QtGui.QIcon(":/mesh.svg"))
    else:
        qItem.setIcon(0, QtGui.QIcon(":/question.png"))

def _update_network(module, item=None):
    if hasattr(module, "_network"):
        pymel.delete(module._network)
    new_network = libSerialization.export_network(module)  # TODO : Automatic update
    # If needed, update the network item net property to match the new exported network
    if item:
        item.net = new_network
    return new_network


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Docums Mycol. 10(nos 37-38): 91 (1979)

#### Original name
Lepista sordida var. ianthina Bon, 1979

### Remarks
null


text:
namespace NorthWind
{
    using System;
    using System.Collections.Generic;

    public partial class Products_Above_Average_Price
    {
        public string ProductName { get; set; }
        public Nullable<decimal> UnitPrice { get; set; }
    }
}


text:
<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new sfTestFunctional(new sfBrowser());

$browser->
  get('/concept/index')->

  with('request')->begin()->
    isParameter('module', 'concept')->
    isParameter('action', 'index')->
  end()->

  with('response')->begin()->
    isStatusCode(200)->
    checkElement('body', '!/This is a temporary page/')->
  end()
;


text:
<Record>
<Term>Triaminic Cold</Term>
<SemanticType>Pharmacologic Substance</SemanticType>
<ParentTerm>Cough and Cold Preparation</ParentTerm>
<ClassificationPath>Chemicals_and_Drugs_Kind/Drug, Food, Chemical or Biomedical Material/Pharmacologic Substance/Adjuvant/Combination Medication/Cough and Cold Preparation/Triaminic Cold</ClassificationPath>
<BroaderTerm>Chemicals_and_Drugs_Kind</BroaderTerm>
<BroaderTerm>Cough and Cold Preparation</BroaderTerm>
<BroaderTerm>Pharmacologic Substance</BroaderTerm>
<BroaderTerm>Adjuvant</BroaderTerm>
<BroaderTerm>Combination Medication</BroaderTerm>
<BroaderTerm>Triaminic Cold</BroaderTerm>
<BroaderTerm>Drug, Food, Chemical or Biomedical Material</BroaderTerm>
<Synonym>Triaminic Cold</Synonym>
<Description>Any of the commercial combination preparations, by Novartis, containing the antihistamine chlorpheniramine maleate and the decongestant pseudoephedrine hydrochloride, either alone or in combination with the analgesic antipyretic acetaminophen and/or the antitussive dextromethorphan hydrobromide. Chlorpheniramine maleate, an antihistamine, blocks the effects of histamine, thereby preventing symptoms such as sneezing and itchy, watery eyes, runny nose and sore throat. Pseudoephedrine hydrochloride, a sympathomimetic agent, acts as a decongestant by inducing vasoconstriction mediated via alpha-adrenergic receptors. This reduces blood flow, decreases swelling and prevents nasal and sinus congestion.</Description>
<Source>NCI Thesaurus</Source>
</Record>


text:
<?php

namespace Symfony\Component\Messenger\Exception;

/**
 * @author Grégoire Pineau <lyrixx@lyrixx.info>
 */
interface StopWorkerExceptionInterface extends \Throwable
{
}


text:
import * as is from "ramda/src/is"

import makeScope from "../utils/makeScope";

import {Config, ReducerName} from "../types";

export default function(config: Config, reducerName: ReducerName, record: any) {
  var scope = makeScope(config, reducerName);
  var isArray = is(Array, record);

  if (isArray)
    throw new TypeError(scope + ": Expected record not to be an array");
}


text:
Test function rsync_generate_delta with stream as input and output.
--SKIPIF--
<?php if (!extension_loaded("rsync")) print "skip"; ?>
--FILE--
<?php
$targetMD5 = 'b6efe00f2049d221626e63c2a2534361';
$sig = fopen('tests/006signatur.sig', 'rb');
$file = fopen('tests/006test.png', 'rb');
$patch = fopen('tests/006test.patch', 'wb');
$ret = rsync_generate_delta($sig, $file, $patch);
fclose($sig);
fclose($file);
fclose($patch);
$resultMD5 = md5_file('tests/006test.patch');
if ($resultMD5 == $targetMD5 && $ret == RSYNC_DONE) {
	echo "SUCCESS\n";
} else {
	echo "FAILED with Return $ret and MD5 $resultMD5\n";
}
unlink('tests/006test.patch');
?>
--EXPECT--
SUCCESS


text:
<?xml version="1.0" encoding="UTF-8"?>

<endpoints
    xmlns="http://docs.openstack.org/identity/api/v2.0">
  <endpoint
      id="1"
      tenantId="1"
      type="compute"
      name="Compute"
      region="North"
      publicURL="https://compute.north.public.com/v1"
      internalURL="https://compute.north.internal.com/v1"
      adminURL="https://compute.north.internal.com/v1">
      <version
          id="1"
          info="https://compute.north.public.com/v1/"
          list="https://compute.north.public.com/"
      />
  </endpoint>
  <endpoint
      id="2"
      tenantId="2"
      type="compute"
      name="Compute"
      region="South"
      publicURL="https://compute.north.public.com/v1"
      internalURL="https://compute.north.internal.com/v1"
      adminURL="https://compute.north.internal.com/v1">
      <version
          id="1"
          info="https://compute.north.public.com/v1/"
          list="https://compute.north.public.com/"
      />
  </endpoint>
  <endpoint
      id="3"
      tenantId="1"
      type="compute"
      name="Compute"
      region="East"
      publicURL="https://compute.north.public.com/v1"
      internalURL="https://compute.north.internal.com/v1"
      adminURL="https://compute.north.internal.com/v1"
  />
  <endpoint
      id="4"
      tenantId="1"
      type="compute"
      name="Compute"
      region="West"
      publicURL="https://compute.north.public.com/v1"
      internalURL="https://compute.north.internal.com/v1"
      adminURL="https://compute.north.internal.com/v1">
      <version
          id="1"
          info="https://compute.north.public.com/v1/"
          list="https://compute.north.public.com/"
      />
  </endpoint>
  <endpoint
      id="5"
      tenantId="1"
      type="compute"
      name="Compute"
      region="Global"
      publicURL="https://compute.north.public.com/v1"
      internalURL="https://compute.north.internal.com/v1"
      adminURL="https://compute.north.internal.com/v1">
      <version
          id="1"
          info="https://compute.north.public.com/v1/"
          list="https://compute.north.public.com/"
      />
  </endpoint>
</endpoints>


text:
public interface MiInterfazRemota extends java.rmi.Remote
{
	public void init() throws java.rmi.RemoteException;
	public int start() throws java.rmi.RemoteException;
}


text:
export * from './auth.actions';

export * from './auth.store';

export * from './auth.effects';


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<TITLE>
WritableVector3f (LWJGL API)
</TITLE>

<META NAME="date" CONTENT="2012-11-04">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">

      Overview
      Package
    Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV CLASS
 NEXT CLASS

  FRAMES
 NO FRAMES

  All Classes

  SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

org.lwjgl.util.vector

Interface WritableVector3f

All Superinterfaces:
WritableVector2f

All Known Subinterfaces:
WritableVector4f

All Known Implementing Classes:
Vector3f, Vector4f

public interface WritableVector3f
extends WritableVector2f

Writable interface to Vector3fs

Version:

$revision$
 $Id: WritableVector3f.java 3418 2010-09-28 21:11:35Z spasi $

Author:

$author$

Method Summary

 void
set(float x,
    float y,
    float z)

          Set the X,Y,Z values

 void
setZ(float z)

          Set the Z value

Methods inherited from interface org.lwjgl.util.vector.WritableVector2f

set, setX, setY

Method Detail

setZ

void setZ(float z)

Set the Z value

Parameters:
z -

set

void set(float x,
         float y,
         float z)

Set the X,Y,Z values

Parameters:
x -
y -
z -

      Overview
      Package
    Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV CLASS
 NEXT CLASS

  FRAMES
 NO FRAMES

  All Classes

  SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2009 lwjgl.org. All Rights Reserved.