-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
MTLValueTransformerSpec.m
51 lines (40 loc) · 1.69 KB
/
MTLValueTransformerSpec.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// MTLValueTransformerSpec.m
// Mantle
//
// Created by Justin Spahr-Summers on 2012-09-11.
// Copyright (c) 2012 GitHub. All rights reserved.
//
SpecBegin(MTLValueTransformer)
it(@"should return a forward transformer with a block", ^{
MTLValueTransformer *transformer = [MTLValueTransformer transformerWithBlock:^(NSString *str) {
return [str stringByAppendingString:@"bar"];
}];
expect(transformer).notTo.beNil();
expect([transformer.class allowsReverseTransformation]).to.beFalsy();
expect([transformer transformedValue:@"foo"]).to.equal(@"foobar");
expect([transformer transformedValue:@"bar"]).to.equal(@"barbar");
});
it(@"should return a reversible transformer with a block", ^{
MTLValueTransformer *transformer = [MTLValueTransformer reversibleTransformerWithBlock:^(NSString *str) {
return [str stringByAppendingString:@"bar"];
}];
expect(transformer).notTo.beNil();
expect([transformer.class allowsReverseTransformation]).to.beTruthy();
expect([transformer transformedValue:@"foo"]).to.equal(@"foobar");
expect([transformer reverseTransformedValue:@"foo"]).to.equal(@"foobar");
});
it(@"should return a reversible transformer with forward and reverse blocks", ^{
MTLValueTransformer *transformer = [MTLValueTransformer
reversibleTransformerWithForwardBlock:^(NSString *str) {
return [str stringByAppendingString:@"bar"];
}
reverseBlock:^(NSString *str) {
return [str substringToIndex:str.length - 3];
}];
expect(transformer).notTo.beNil();
expect([transformer.class allowsReverseTransformation]).to.beTruthy();
expect([transformer transformedValue:@"foo"]).to.equal(@"foobar");
expect([transformer reverseTransformedValue:@"foobar"]).to.equal(@"foo");
});
SpecEnd