/
GBModelBaseTesting.m
143 lines (126 loc) · 5.51 KB
/
GBModelBaseTesting.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// GBModelBaseTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 28.7.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBDataObjects.h"
@interface GBModelBaseTesting : GHTestCase
@end
@implementation GBModelBaseTesting
#pragma mark Common merging testing
- (void)testMergeDataFromObject_shouldMergeDeclaredFiles {
// setup
GBModelBase *original = [[GBModelBase alloc] init];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"f1" lineNumber:1]];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"f2" lineNumber:2]];
GBModelBase *source = [[GBModelBase alloc] init];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"f1" lineNumber:3]];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"f3" lineNumber:4]];
// execute
[original mergeDataFromObject:source];
// verify
NSArray *files = [original sourceInfosSortedByName];
assertThatInteger([files count], equalToInteger(3));
assertThat([[files objectAtIndex:0] filename], is(@"f1"));
assertThat([[files objectAtIndex:1] filename], is(@"f2"));
assertThat([[files objectAtIndex:2] filename], is(@"f3"));
assertThatInteger([[files objectAtIndex:0] lineNumber], equalToInteger(3));
assertThatInteger([[files objectAtIndex:1] lineNumber], equalToInteger(2));
assertThatInteger([[files objectAtIndex:2] lineNumber], equalToInteger(4));
}
- (void)testMergeDataFromObject_shouldPreserveSourceDeclaredFiles {
// setup
GBModelBase *original = [[GBModelBase alloc] init];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"f1" lineNumber:4]];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"f2" lineNumber:3]];
GBModelBase *source = [[GBModelBase alloc] init];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"f1" lineNumber:2]];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"f3" lineNumber:1]];
// execute
[original mergeDataFromObject:source];
// verify
NSArray *files = [source sourceInfosSortedByName];
assertThatInteger([files count], equalToInteger(2));
assertThat([[files objectAtIndex:0] filename], is(@"f1"));
assertThat([[files objectAtIndex:1] filename], is(@"f3"));
assertThatInteger([[files objectAtIndex:0] lineNumber], equalToInteger(2));
assertThatInteger([[files objectAtIndex:1] lineNumber], equalToInteger(1));
}
#pragma mark Comments merging handling
- (void)testMergeDataFromObject_shouldUseOriginalCommentIfSourceIsNotGiven {
// setup
GBModelBase *original = [[GBModelBase alloc] init];
original.comment = [GBComment commentWithStringValue:@"Comment"];
GBModelBase *source = [[GBModelBase alloc] init];
// execute
[original mergeDataFromObject:source];
// verify
assertThat(original.comment.stringValue, is(@"Comment"));
assertThat(source.comment.stringValue, is(nil));
}
- (void)testMergeDataFromObject_shouldUseSourceCommentIfOriginalIsNotGiven {
// setup
GBModelBase *original = [[GBModelBase alloc] init];
GBModelBase *source = [[GBModelBase alloc] init];
source.comment = [GBComment commentWithStringValue:@"Comment"];
// execute
[original mergeDataFromObject:source];
// verify
assertThat(original.comment.stringValue, is(@"Comment"));
assertThat(source.comment.stringValue, is(@"Comment"));
}
- (void)testMergeDataFromObject_shouldKeepOriginalCommentIfBothObjectsHaveComments {
// setup
GBModelBase *original = [[GBModelBase alloc] init];
original.comment = [GBComment commentWithStringValue:@"Comment1"];
GBModelBase *source = [[GBModelBase alloc] init];
source.comment = [GBComment commentWithStringValue:@"Comment2"];
// execute
[original mergeDataFromObject:source];
// verify
assertThat(original.comment.stringValue, is(@"Comment1"));
assertThat(source.comment.stringValue, is(@"Comment2"));
}
#pragma mark Source information testing
- (void)testPrefferedSourceInfo_shouldReturnSourceInfoFromComment {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
object.comment = [GBComment commentWithStringValue:@"comment"];
object.comment.sourceInfo = [GBSourceInfo infoWithFilename:@"file1" lineNumber:1];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"file.h" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo, is(object.comment.sourceInfo));
}
- (void)testPrefferedSourceInfo_shouldReturnHeaderFileSourceInfoIfCommentNotGiven {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"a.m" lineNumber:1]];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"b.h" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo.filename, is(@"b.h"));
}
- (void)testPrefferedSourceInfo_shouldReturnHeaderFileSourceInfoIfCommentDoesntHaveSourceInfo {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
object.comment = [GBComment commentWithStringValue:@"comment"];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"a.m" lineNumber:1]];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"b.h" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo.filename, is(@"b.h"));
}
- (void)testPrefferedSourceInfo_shouldReturnSingleSourceInfo {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
[object registerSourceInfo:[GBSourceInfo infoWithFilename:@"a.m" lineNumber:1]];
// execute & verify
assertThat(object.prefferedSourceInfo.filename, is(@"a.m"));
}
- (void)testPrefferedSourceInfo_shouldReturnNilIfNoSourceInfoAvailable {
// setup
GBModelBase *object = [[GBModelBase alloc] init];
// execute & verify
assertThat(object.prefferedSourceInfo, is(nil));
}
@end