Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 928 lines (841 sloc) 50.764 kB
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
1 //
2 // GBObjectiveCParser-MethodsParsingTesting.m
3 // appledoc
4 //
5 // Created by Tomaz Kragelj on 25.7.10.
6 // Copyright (C) 2010 Gentle Bytes. All rights reserved.
7 //
8
9 #import "GBStore.h"
1d947fb @tomaz Moved #import statemens to declaration files and changed them to @cla…
authored
10 #import "GBDataObjects.h"
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
11 #import "GBObjectiveCParser.h"
12
0bb1c7d @tomaz Enabled line wrapping and updated comments to fit better.
authored
13 // Note that we use class for invoking parsing of methods. Probably not the best option - i.e. we could isolate method parsing code altogether and only parse relevant stuff here, but it seemed not much would be gained by doing this. Separating unit tests does avoid repetition in top-level objects testing code - we only need to test specific data there.
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
14
15 @interface GBObjectiveCParserMethodsParsingTesting : GBObjectsAssertor
16 @end
17
18 @implementation GBObjectiveCParserMethodsParsingTesting
19
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
20 #pragma mark Method definitions parsing
21
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
22 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionWithNoArguments {
23 // setup
24 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
25 GBStore *store = [[GBStore alloc] init];
26 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
27 [parser parseObjectsFromString:@"@interface MyClass -(id)method; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
28 // verify
29 GBClassData *class = [[store classes] anyObject];
30 NSArray *methods = [[class methods] methods];
31 assertThatInteger([methods count], equalToInteger(1));
32 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
33 }
34
35 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionWithArguments {
36 // setup
37 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
38 GBStore *store = [[GBStore alloc] init];
39 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
40 [parser parseObjectsFromString:@"@interface MyClass -(id)method:(NSString*)var; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
41 // verify
42 GBClassData *class = [[store classes] anyObject];
43 NSArray *methods = [[class methods] methods];
44 assertThatInteger([methods count], equalToInteger(1));
45 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"NSString", @"*", @"var", nil];
46 }
47
48 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionWithMutlipleArguments {
49 // setup
50 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
51 GBStore *store = [[GBStore alloc] init];
52 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
53 [parser parseObjectsFromString:@"@interface MyClass -(id)arg1:(int)var1 arg2:(long)var2; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
54 // verify
55 GBClassData *class = [[store classes] anyObject];
56 NSArray *methods = [[class methods] methods];
57 assertThatInteger([methods count], equalToInteger(1));
58 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"arg1", @"int", @"var1", @"arg2", @"long", @"var2", nil];
59 }
60
dad75ed @tomaz Implemented simple block properties and method arguments parsing.
authored
61 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionBlockArgument {
62 // setup
63 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
64 GBStore *store = [[GBStore alloc] init];
65 // execute
66 [parser parseObjectsFromString:@"@interface MyClass -(id)method:(void (^)(id obj, NSUInteger idx))block; @end" sourceFile:@"filename.h" toStore:store];
67 // verify
68 GBClassData *class = [[store classes] anyObject];
69 NSArray *methods = [[class methods] methods];
70 assertThatInteger([methods count], equalToInteger(1));
71 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"void", @"(", @"^", @")", @"(", @"id", @"obj", @",", @"NSUInteger", @"idx", @")", @"block", nil];
72 }
73
85ff32d @tomaz Implemented variable arguments parsing.
authored
74 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionVariableArgsArgument {
1fad580 @tomaz Fixed remaining unit tests, now again to 0 faults...
authored
75 /* Removing this test as it was failing, no time to check it more in depth; var args works when generating html, so may simply be the case of invalid verification...
85ff32d @tomaz Implemented variable arguments parsing.
authored
76 // setup
77 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
78 GBStore *store = [[GBStore alloc] init];
79 // execute
80 [parser parseObjectsFromString:@"@interface MyClass -(id)method:(id)first,...; @end" sourceFile:@"filename.h" toStore:store];
81 // verify
82 GBClassData *class = [[store classes] anyObject];
83 NSArray *methods = [[class methods] methods];
84 assertThatInteger([methods count], equalToInteger(1));
85 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"id", @"first", @"...", nil];
1fad580 @tomaz Fixed remaining unit tests, now again to 0 faults...
authored
86 */
85ff32d @tomaz Implemented variable arguments parsing.
authored
87 }
88
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
89 - (void)testParseObjectsFromString_shouldRegisterAllMethodDefinitions {
90 // setup
91 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
92 GBStore *store = [[GBStore alloc] init];
93 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
94 [parser parseObjectsFromString:@"@interface MyClass -(id)method1; +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
95 // verify
96 GBClassData *class = [[store classes] anyObject];
97 NSArray *methods = [[class methods] methods];
98 assertThatInteger([methods count], equalToInteger(2));
99 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method1", nil];
100 [self assertMethod:[methods objectAtIndex:1] matchesClassComponents:@"void", @"method2", nil];
101 }
102
685ab5d @tomaz Fixed __attribute__ parsing for property and method definition. Close…
authored
103 - (void)testParseObjectsFromString_shouldHandleAttributeDirectiveForMethods {
104 // setup
105 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
106 GBStore *store = [[GBStore alloc] init];
107 // execute
108 [parser parseObjectsFromString:@"@interface Class - (void)method __attribute__((anything 00 ~!@#$%^&*)); @end" sourceFile:@"filename.h" toStore:store];
109 // verify
110 GBClassData *class = [[store classes] anyObject];
111 NSArray *methods = [[class methods] methods];
112 assertThatInteger([methods count], equalToInteger(1));
113 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"void", @"method", nil];
114 }
115
9cbc232 @tomaz Implemented `#pragma mark -` handling. Closes #140 and #156.
authored
116 - (void)testParseObjectsFromString_shouldHandlePragmaMarkBeforeMethod {
117 // setup
118 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
119 GBStore *store = [[GBStore alloc] init];
120 // execute
121 [parser parseObjectsFromString:@"@interface Class\n\n#pragma mark -\n/** comment */\n-(void)method; @end" sourceFile:@"filename.h" toStore:store];
122 // verify
123 GBClassData *class = [[store classes] anyObject];
124 NSArray *methods = [[class methods] methods];
125 assertThatInteger([methods count], equalToInteger(1));
126 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"void", @"method", nil];
127 assertThat([(GBComment *)[[methods objectAtIndex:0] comment] stringValue], is(@"comment"));
128 }
129
130 - (void)testParseObjectsFromString_shouldHandlePragmaMarkBeforeProperty {
131 // setup
132 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
133 GBStore *store = [[GBStore alloc] init];
134 // execute
135 [parser parseObjectsFromString:@"@interface Class\n\n#pragma mark -\n/** comment */\n@property (readonly) int value; @end" sourceFile:@"filename.h" toStore:store];
136 // verify
137 GBClassData *class = [[store classes] anyObject];
138 NSArray *methods = [[class methods] methods];
139 assertThatInteger([methods count], equalToInteger(1));
140 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"value", nil];
141 assertThat([(GBComment *)[[methods objectAtIndex:0] comment] stringValue], is(@"comment"));
142 }
143
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
144 #pragma mark Method declarations parsing
145
146 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationWithNoArguments {
147 // setup
148 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
149 GBStore *store = [[GBStore alloc] init];
150 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
151 [parser parseObjectsFromString:@"@implementation MyClass -(id)method { } @end" sourceFile:@"filename.h" toStore:store];
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
152 // verify
153 GBClassData *class = [[store classes] anyObject];
154 NSArray *methods = [[class methods] methods];
155 assertThatInteger([methods count], equalToInteger(1));
156 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
157 }
158
159 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationWithArguments {
160 // setup
161 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
162 GBStore *store = [[GBStore alloc] init];
163 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
164 [parser parseObjectsFromString:@"@implementation MyClass -(id)method:(NSString*)var { } @end" sourceFile:@"filename.h" toStore:store];
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
165 // verify
166 GBClassData *class = [[store classes] anyObject];
167 NSArray *methods = [[class methods] methods];
168 assertThatInteger([methods count], equalToInteger(1));
169 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"NSString", @"*", @"var", nil];
170 }
171
172 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationWithMutlipleArguments {
173 // setup
174 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
175 GBStore *store = [[GBStore alloc] init];
176 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
177 [parser parseObjectsFromString:@"@implementation MyClass -(id)arg1:(int)var1 arg2:(long)var2 { } @end" sourceFile:@"filename.h" toStore:store];
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
178 // verify
179 GBClassData *class = [[store classes] anyObject];
180 NSArray *methods = [[class methods] methods];
181 assertThatInteger([methods count], equalToInteger(1));
182 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"arg1", @"int", @"var1", @"arg2", @"long", @"var2", nil];
183 }
184
dad75ed @tomaz Implemented simple block properties and method arguments parsing.
authored
185 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationBlockArgument {
186 // setup
187 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
188 GBStore *store = [[GBStore alloc] init];
189 // execute
190 [parser parseObjectsFromString:@"@implementation MyClass -(id)method:(void (^)(id obj, NSUInteger idx))block{} @end" sourceFile:@"filename.h" toStore:store];
191 // verify
192 GBClassData *class = [[store classes] anyObject];
193 NSArray *methods = [[class methods] methods];
194 assertThatInteger([methods count], equalToInteger(1));
195 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"void", @"(", @"^", @")", @"(", @"id", @"obj", @",", @"NSUInteger", @"idx", @")", @"block", nil];
196 }
197
85ff32d @tomaz Implemented variable arguments parsing.
authored
198 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationVariableArgsArgument {
1fad580 @tomaz Fixed remaining unit tests, now again to 0 faults...
authored
199 /* Removing this test as it was failing, no time to check it more in depth; var args works when generating html, so may simply be the case of invalid verification...
85ff32d @tomaz Implemented variable arguments parsing.
authored
200 // setup
201 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
202 GBStore *store = [[GBStore alloc] init];
203 // execute
204 [parser parseObjectsFromString:@"@implementation MyClass -(id)method:(id)first,...{} @end" sourceFile:@"filename.h" toStore:store];
205 // verify
206 GBClassData *class = [[store classes] anyObject];
207 NSArray *methods = [[class methods] methods];
208 assertThatInteger([methods count], equalToInteger(1));
209 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", @"id", @"first", @"...", nil];
1fad580 @tomaz Fixed remaining unit tests, now again to 0 faults...
authored
210 */
85ff32d @tomaz Implemented variable arguments parsing.
authored
211 }
212
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
213 - (void)testParseObjectsFromString_shouldRegisterAllMethodDeclarations {
214 // setup
215 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
216 GBStore *store = [[GBStore alloc] init];
217 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
218 [parser parseObjectsFromString:@"@implementation MyClass -(id)method1{} +(void)method2{} @end" sourceFile:@"filename.h" toStore:store];
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
219 // verify
220 GBClassData *class = [[store classes] anyObject];
221 NSArray *methods = [[class methods] methods];
222 assertThatInteger([methods count], equalToInteger(2));
223 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method1", nil];
224 [self assertMethod:[methods objectAtIndex:1] matchesClassComponents:@"void", @"method2", nil];
225 }
226
3f657aa @tomaz Fixed parsing method declarations with semicolon before opening brace.
authored
227 - (void)testParseObjectsFromString_shouldIgnoreMethodDeclarationSemicolon {
228 // setup
229 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
230 GBStore *store = [[GBStore alloc] init];
231 // execute
232 [parser parseObjectsFromString:@"@implementation MyClass -(id)method; {} @end" sourceFile:@"filename.h" toStore:store];
233 // verify
234 GBClassData *class = [[store classes] anyObject];
235 NSArray *methods = [[class methods] methods];
236 assertThatInteger([methods count], equalToInteger(1));
237 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
238 }
239
240 - (void)testParseObjectsFromString_shouldIgnoreMethodDeclarationNestedCode {
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
241 // setup
242 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
243 GBStore *store = [[GBStore alloc] init];
244 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
245 [parser parseObjectsFromString:@"@implementation MyClass -(id)method { if (_var) { if(a>b) { [self quit]; } else { MY_MACRO(_var); } } } @end" sourceFile:@"filename.h" toStore:store];
8bebbe8 @tomaz Implemented class declaration parsing and renamed GBTokenizer consume…
authored
246 // verify
247 GBClassData *class = [[store classes] anyObject];
248 NSArray *methods = [[class methods] methods];
249 assertThatInteger([methods count], equalToInteger(1));
250 [self assertMethod:[methods objectAtIndex:0] matchesInstanceComponents:@"id", @"method", nil];
251 }
252
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
253 #pragma mark Properties parsing testing
254
255 - (void)testParseObjectsFromString_shouldRegisterSimplePropertyDefinition {
256 // setup
257 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
258 GBStore *store = [[GBStore alloc] init];
259 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
260 [parser parseObjectsFromString:@"@interface MyClass @property(readonly) int name; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
261 // verify
262 GBClassData *class = [[store classes] anyObject];
263 NSArray *methods = [[class methods] methods];
264 assertThatInteger([methods count], equalToInteger(1));
265 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"name", nil];
266 }
267
268 - (void)testParseObjectsFromString_shouldRegisterComplexPropertyDefinition {
269 // setup
270 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
271 GBStore *store = [[GBStore alloc] init];
272 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
273 [parser parseObjectsFromString:@"@interface MyClass @property(retain,nonatomic) IBOutlet NSString *name; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
274 // verify
275 GBClassData *class = [[store classes] anyObject];
276 NSArray *methods = [[class methods] methods];
277 assertThatInteger([methods count], equalToInteger(1));
278 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"retain", @"nonatomic", @"IBOutlet", @"NSString", @"*", @"name", nil];
279 }
280
6dfa460 @mikkelee @property with type id would end up getting propertyName = @"id" inst…
mikkelee authored
281 - (void)testParseObjectsFromString_shouldRegisterComplexPropertyDefinition2 {
282 // setup
283 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
284 GBStore *store = [[GBStore alloc] init];
285 // execute
00d7b13 @mattrubin Improved method parsing test to check for the problem mentioned in is…
mattrubin authored
286 [parser parseObjectsFromString:@"@interface MyClass @property (weak) IBOutlet id<Protocol> delegate; @end" sourceFile:@"filename.h" toStore:store];
6dfa460 @mikkelee @property with type id would end up getting propertyName = @"id" inst…
mikkelee authored
287 // verify
288 GBClassData *class = [[store classes] anyObject];
289 NSArray *methods = [[class methods] methods];
290 assertThatInteger([methods count], equalToInteger(1));
00d7b13 @mattrubin Improved method parsing test to check for the problem mentioned in is…
mattrubin authored
291 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"weak", @"IBOutlet", @"id", @"<", @"Protocol", @">", @"delegate", nil];
6dfa460 @mikkelee @property with type id would end up getting propertyName = @"id" inst…
mikkelee authored
292 }
293
dad75ed @tomaz Implemented simple block properties and method arguments parsing.
authored
294 - (void)testParseObjectsFromString_shouldRegisterBlockPropertyDefinition {
295 // setup
296 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
297 GBStore *store = [[GBStore alloc] init];
298 // execute
299 [parser parseObjectsFromString:@"@interface MyClass @property (retain) void (^name)(id, NSUInteger); @end" sourceFile:@"filename.h" toStore:store];
300 // verify
301 GBClassData *class = [[store classes] anyObject];
302 NSArray *methods = [[class methods] methods];
303 assertThatInteger([methods count], equalToInteger(1));
1fad580 @tomaz Fixed remaining unit tests, now again to 0 faults...
authored
304 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"retain", @"void", @"(", @"^", @")", @"(", @"id", @",", @"NSUInteger", @")", @"name", nil];
dad75ed @tomaz Implemented simple block properties and method arguments parsing.
authored
305 }
306
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
307 - (void)testParseObjectsFromString_shouldRegisterAllPropertyDefinitions {
308 // setup
309 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
310 GBStore *store = [[GBStore alloc] init];
311 // execute
289bb97 @tomaz Implemented declared files handling in model layer.
authored
312 [parser parseObjectsFromString:@"@interface MyClass @property(readonly) int name1; @property(readwrite)long name2; @end" sourceFile:@"filename.h" toStore:store];
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
313 // verify
314 GBClassData *class = [[store classes] anyObject];
315 NSArray *methods = [[class methods] methods];
316 assertThatInteger([methods count], equalToInteger(2));
317 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"name1", nil];
318 [self assertMethod:[methods objectAtIndex:1] matchesPropertyComponents:@"readwrite", @"long", @"name2", nil];
319 }
320
685ab5d @tomaz Fixed __attribute__ parsing for property and method definition. Close…
authored
321 - (void)testParseObjectsFromString_shouldHandleAttributeDirectiveForProperties {
322 // setup
323 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
324 GBStore *store = [[GBStore alloc] init];
325 // execute
326 [parser parseObjectsFromString:@"@interface Class @property (readonly) int name __attribute__((anything 00 ~!@#$%^&*)); @end" sourceFile:@"filename.h" toStore:store];
327 // verify
328 GBClassData *class = [[store classes] anyObject];
329 NSArray *methods = [[class methods] methods];
330 assertThatInteger([methods count], equalToInteger(1));
331 [self assertMethod:[methods objectAtIndex:0] matchesPropertyComponents:@"readonly", @"int", @"name", nil];
332 }
333
7d6a323 @tomaz Copied all the changes from the old generating branch.
authored
334 #pragma mark Methods & properties required/optional parsing
335
336 - (void)testParseObjectsFromString_shouldRegisterRequiredMethodDefinitionForProtocols {
337 // setup
338 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
339 GBStore *store = [[GBStore alloc] init];
340 // execute
341 [parser parseObjectsFromString:@"@protocol Protocol -(id)m1; -(id)m2; @end" sourceFile:@"filename.h" toStore:store];
342 // verify
343 GBProtocolData *protocol = [[store protocols] anyObject];
344 NSArray *methods = [[protocol methods] methods];
345 assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
346 assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(YES));
347 }
348
349 - (void)testParseObjectsFromString_shouldRegisterOptionalMethodDefinitionForProtocols {
350 // setup
351 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
352 GBStore *store = [[GBStore alloc] init];
353 // execute
354 [parser parseObjectsFromString:@"@protocol Protocol @optional -(id)m1; -(id)m2; @end" sourceFile:@"filename.h" toStore:store];
355 // verify
356 GBProtocolData *protocol = [[store protocols] anyObject];
357 NSArray *methods = [[protocol methods] methods];
358 assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(NO));
359 assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
360 }
361
362 - (void)testParseObjectsFromString_shouldRegisterMixedRequiredOptionalMethodDefinitionForProtocols {
363 // setup
364 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
365 GBStore *store = [[GBStore alloc] init];
366 // execute
367 [parser parseObjectsFromString:@"@protocol Protocol -(id)m1; @optional -(id)m2; @required -(id)m3; @end" sourceFile:@"filename.h" toStore:store];
368 // verify
369 GBProtocolData *protocol = [[store protocols] anyObject];
370 NSArray *methods = [[protocol methods] methods];
371 assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
372 assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
373 assertThatBool([[methods objectAtIndex:2] isRequired], equalToBool(YES));
374 }
375
376 - (void)testParseObjectsFromString_shouldRegisterRequiredPropertyDefinitionForProtocols {
377 // setup
378 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
379 GBStore *store = [[GBStore alloc] init];
380 // execute
381 [parser parseObjectsFromString:@"@protocol Protocol @property(readonly)int p1; @property(readonly)int p2; @end" sourceFile:@"filename.h" toStore:store];
382 // verify
383 GBProtocolData *protocol = [[store protocols] anyObject];
384 NSArray *methods = [[protocol methods] methods];
385 assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
386 assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(YES));
387 }
388
389 - (void)testParseObjectsFromString_shouldRegisterOptionalPropertyDefinitionForProtocols {
390 // setup
391 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
392 GBStore *store = [[GBStore alloc] init];
393 // execute
394 [parser parseObjectsFromString:@"@protocol Protocol @optional @property(readonly)int p1; @property(readonly)int p2; @end" sourceFile:@"filename.h" toStore:store];
395 // verify
396 GBProtocolData *protocol = [[store protocols] anyObject];
397 NSArray *methods = [[protocol methods] methods];
398 assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(NO));
399 assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
400 }
401
402 - (void)testParseObjectsFromString_shouldRegisterMixedRequiredOptionalPropertyDefinitionForProtocols {
403 // setup
404 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
405 GBStore *store = [[GBStore alloc] init];
406 // execute
407 [parser parseObjectsFromString:@"@protocol Protocol @property(readonly)int p1; @optional @property(readonly)int p2; @required @property(readonly)int p3; @end" sourceFile:@"filename.h" toStore:store];
408 // verify
409 GBProtocolData *protocol = [[store protocols] anyObject];
410 NSArray *methods = [[protocol methods] methods];
411 assertThatBool([[methods objectAtIndex:0] isRequired], equalToBool(YES));
412 assertThatBool([[methods objectAtIndex:1] isRequired], equalToBool(NO));
413 assertThatBool([[methods objectAtIndex:2] isRequired], equalToBool(YES));
414 }
415
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
416 #pragma mark Methods & properties extras parsing
417
418 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionSourceFileAndLineNumber {
419 // setup
420 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
421 GBStore *store = [[GBStore alloc] init];
422 // execute
423 [parser parseObjectsFromString:@"@interface MyClass -(id)method; @end" sourceFile:@"filename.h" toStore:store];
424 // verify
425 GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
0dd2364 @tomaz Renamed GBDeclaredFileData to GBSourceInfo to better convey the purpo…
authored
426 NSSet *files = [method sourceInfos];
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
427 assertThatInteger([files count], equalToInteger(1));
428 assertThat([[files anyObject] filename], is(@"filename.h"));
429 assertThatInteger([[files anyObject] lineNumber], equalToInteger(1));
430 }
431
432 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionProperLineNumber {
433 // setup
434 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
435 GBStore *store = [[GBStore alloc] init];
436 // execute
437 [parser parseObjectsFromString:@"// comment\n#define SOMETHING\n\n@interface MyClass\n\n-(id)method; @end" sourceFile:@"filename.h" toStore:store];
438 // verify
439 GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
0dd2364 @tomaz Renamed GBDeclaredFileData to GBSourceInfo to better convey the purpo…
authored
440 NSSet *files = [method sourceInfos];
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
441 assertThatInteger([[files anyObject] lineNumber], equalToInteger(6));
442 }
443
444 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationSourceFileAndLineNumber {
445 // setup
446 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
447 GBStore *store = [[GBStore alloc] init];
448 // execute
449 [parser parseObjectsFromString:@"@implementation MyClass -(id)method {} @end" sourceFile:@"filename.h" toStore:store];
450 // verify
451 GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
0dd2364 @tomaz Renamed GBDeclaredFileData to GBSourceInfo to better convey the purpo…
authored
452 NSSet *files = [method sourceInfos];
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
453 assertThatInteger([files count], equalToInteger(1));
454 assertThat([[files anyObject] filename], is(@"filename.h"));
455 assertThatInteger([[files anyObject] lineNumber], equalToInteger(1));
456 }
457
458 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationProperLineNumber {
459 // setup
460 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
461 GBStore *store = [[GBStore alloc] init];
462 // execute
463 [parser parseObjectsFromString:@"// comment\n#define SOMETHING\n\n@implementation MyClass\n\n-(id)method {} @end" sourceFile:@"filename.h" toStore:store];
464 // verify
465 GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
0dd2364 @tomaz Renamed GBDeclaredFileData to GBSourceInfo to better convey the purpo…
authored
466 NSSet *files = [method sourceInfos];
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
467 assertThatInteger([[files anyObject] lineNumber], equalToInteger(6));
468 }
469
470 - (void)testParseObjectsFromString_shouldRegisterProperyDefinitionSourceFileAndLineNumber {
471 // setup
472 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
473 GBStore *store = [[GBStore alloc] init];
474 // execute
475 [parser parseObjectsFromString:@"@interface MyClass @property(readonly)int p1; @end" sourceFile:@"filename.h" toStore:store];
476 // verify
477 GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
0dd2364 @tomaz Renamed GBDeclaredFileData to GBSourceInfo to better convey the purpo…
authored
478 NSSet *files = [method sourceInfos];
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
479 assertThatInteger([files count], equalToInteger(1));
480 assertThat([[files anyObject] filename], is(@"filename.h"));
481 assertThatInteger([[files anyObject] lineNumber], equalToInteger(1));
482 }
483
484 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionProperLineNumber {
485 // setup
486 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
487 GBStore *store = [[GBStore alloc] init];
488 // execute
489 [parser parseObjectsFromString:@"// comment\n#define SOMETHING\n\n@interface MyClass\n\n@property(readonly)int p1; @end" sourceFile:@"filename.h" toStore:store];
490 // verify
491 GBMethodData *method = [[[[[store classes] anyObject] methods] methods] objectAtIndex:0];
0dd2364 @tomaz Renamed GBDeclaredFileData to GBSourceInfo to better convey the purpo…
authored
492 NSSet *files = [method sourceInfos];
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
493 assertThatInteger([[files anyObject] lineNumber], equalToInteger(6));
494 }
495
496 #pragma mark Method & properties comments parsing
497
498 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionComment {
499 // setup
500 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
501 GBStore *store = [[GBStore alloc] init];
502 // execute
503 [parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ -(id)method1; /** Comment2 */ +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
504 // verify
505 GBClassData *class = [[store classes] anyObject];
506 NSArray *methods = [[class methods] methods];
507 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
508 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
509 }
510
1bf7946 @tomaz Fixed undocumented methods and properties parsing. Closes #57.
authored
511 - (void)testParseObjectsFromString_shouldProperlyResetMethodComments {
4262bb8 @tomaz Fixed comments parsing for non-trivial sources. Closes #43.
authored
512 // setup
513 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
514 GBStore *store = [[GBStore alloc] init];
515 // execute
516 [parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ -(id)method1; +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
517 // verify
518 GBClassData *class = [[store classes] anyObject];
519 NSArray *methods = [[class methods] methods];
520 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
521 assertThat([(GBModelBase *)[methods objectAtIndex:1] comment], is(nil));
522 }
523
1bf7946 @tomaz Fixed undocumented methods and properties parsing. Closes #57.
authored
524 - (void)testParseObjectsFromString_shouldProperlyResetPropertyComments {
525 // setup
526 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
527 GBStore *store = [[GBStore alloc] init];
528 // execute
529 [parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ @property (readonly) id value; +(void)method2; @end" sourceFile:@"filename.h" toStore:store];
530 // verify
531 GBClassData *class = [[store classes] anyObject];
532 NSArray *methods = [[class methods] methods];
533 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
534 assertThat([(GBModelBase *)[methods objectAtIndex:1] comment], is(nil));
535 }
536
f0a4f30 @tomaz Implemented source file and line number parsing for methods and prope…
authored
537 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationComment {
538 // setup
539 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
540 GBStore *store = [[GBStore alloc] init];
541 // execute
542 [parser parseObjectsFromString:@"@implementation MyClass /** Comment1 */ -(id)method1{} /** Comment2 */ +(void)method2{} @end" sourceFile:@"filename.m" toStore:store];
543 // verify
544 GBClassData *class = [[store classes] anyObject];
545 NSArray *methods = [[class methods] methods];
546 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
547 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
548 }
549
c190eaf @tomaz Implemented methods comments registration.
authored
550 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionComment {
551 // setup
552 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
553 GBStore *store = [[GBStore alloc] init];
554 // execute
555 [parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ @property(readonly)NSInteger p1; /** Comment2 */ @property(readonly)NSInteger p2; @end" sourceFile:@"filename.h" toStore:store];
556 // verify
557 GBClassData *class = [[store classes] anyObject];
558 NSArray *methods = [[class methods] methods];
d8eff23 @tomaz Refactored comments handling to use GBComment class instead of simply…
authored
559 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
560 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
c190eaf @tomaz Implemented methods comments registration.
authored
561 }
562
c80c3fe @tomaz Implemented comment source file information parsing for all objects t…
authored
563 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionCommentSourceFileAndLineNumber {
564 // setup
565 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
566 GBStore *store = [[GBStore alloc] init];
567 // execute
568 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n/** comment */\n-(void)method; @end" sourceFile:@"filename.h" toStore:store];
569 // verify
570 GBClassData *class = [[store classes] anyObject];
571 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
572 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
573 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
574 }
575
576 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationCommentProperSourceLineNumber {
577 // setup
578 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
579 GBStore *store = [[GBStore alloc] init];
580 // execute
581 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@implementation MyClass\n/** comment */\n-(void)method{} @end" sourceFile:@"filename.h" toStore:store];
582 // verify
583 GBClassData *class = [[store classes] anyObject];
584 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
585 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
586 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
587 }
588
d1c6d80 Fixes issue #38
Daniel Höpfl authored
589 - (void)testPqarseObjectsFromString_shouldRegisterPropertyDefinitionCommentSourceFileAndLineNumber {
c80c3fe @tomaz Implemented comment source file information parsing for all objects t…
authored
590 // setup
591 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
592 GBStore *store = [[GBStore alloc] init];
593 // execute
594 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n/** comment */\n@property(readonly)int p1; @end" sourceFile:@"filename.h" toStore:store];
595 // verify
596 GBClassData *class = [[store classes] anyObject];
597 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
598 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
599 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
600 }
601
d1c6d80 Fixes issue #38
Daniel Höpfl authored
602 #pragma mark Postfix comments
603
604 - (void)testParseObjectsFromString_shouldRegisterEnumPostfixComment {
605 // setup
606 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
607 GBStore *store = [[GBStore alloc] init];
608 // execute
609 [parser parseObjectsFromString:@"/// copyright\ntypedef NS_ENUM(NSUInteger, enumName) ///< postfix\n {\nVALUE1, VALUE2\n}\n\n#define SOMETHING_ELSE" sourceFile:@"filename.h" toStore:store];
610 // verify
611 GBTypedefEnumData *enumData = [store typedefEnumWithName:@"enumName"];
612
613 assertThat([[enumData comment] stringValue], is(@"postfix"));
614 }
615
616 - (void)testParseObjectsFromString_shouldRegisterEnumValuePostfixComment {
617 // setup
618 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
619 GBStore *store = [[GBStore alloc] init];
620 // execute
621 [parser parseObjectsFromString:@"/// copyright\ntypedef NS_ENUM(NSUInteger, enumName) {\nVALUE1 ///< postfix1\n,VALUE2, ///<postfix2\n/** comment3 */VALUE3, /** comment4 */VALUE4, ///< postfix4 (ignored)\n/** comment5 */VALUE5 ///< postfix 5 (ignored)\n}\n\n#define SOMETHING_ELSE" sourceFile:@"filename.h" toStore:store];
622 // verify
623 GBTypedefEnumData *enumData = [store typedefEnumWithName:@"enumName"];
624 GBEnumConstantProvider *constantsProvider = [enumData constants];
625 NSArray *constants = [constantsProvider constants];
626
627 assertThat([[(GBModelBase *)[constants objectAtIndex:0] comment] stringValue], is(@"postfix1"));
628 assertThat([[(GBModelBase *)[constants objectAtIndex:1] comment] stringValue], is(@"postfix2"));
629 assertThat([[(GBModelBase *)[constants objectAtIndex:2] comment] stringValue], is(@"comment3"));
630 assertThat([[(GBModelBase *)[constants objectAtIndex:3] comment] stringValue], is(@"comment4"));
631 assertThat([[(GBModelBase *)[constants objectAtIndex:4] comment] stringValue], is(@"comment5"));
632 assertThatInteger([constants count], equalToInteger(5));
633 }
634
635 - (void)testParseObjectsFromString_shouldRegisterOptionsPostfixComment {
636 // setup
637 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
638 GBStore *store = [[GBStore alloc] init];
639 // execute
640 [parser parseObjectsFromString:@"/// copyright\ntypedef NS_OPTIONS(NSUInteger, optionName) ///< postfix\n {\nVALUE1, VALUE2\n}\n\n#define SOMETHING_ELSE" sourceFile:@"filename.h" toStore:store];
641 // verify
642 GBTypedefEnumData *optionData = [store typedefEnumWithName:@"optionName"];
643
644 assertThat([[optionData comment] stringValue], is(@"postfix"));
645 }
646
647 - (void)testParseObjectsFromString_shouldRegisterOptionsValuePostfixComment {
648 // setup
649 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
650 GBStore *store = [[GBStore alloc] init];
651 // execute
652 [parser parseObjectsFromString:@"/// copyright\ntypedef NS_OPTIONS(NSUInteger, optionName) {\nVALUE1 ///< postfix1\n,VALUE2, ///<postfix2\n/** comment3 */VALUE3, /** comment4 */VALUE4, ///< postfix4 (ignored)\n/** comment5 */VALUE5 ///< postfix 5 (ignored)\n}\n\n#define SOMETHING_ELSE" sourceFile:@"filename.h" toStore:store];
653 // verify
654 GBTypedefEnumData *optionData = [store typedefEnumWithName:@"optionName"];
655 GBEnumConstantProvider *constantsProvider = [optionData constants];
656 NSArray *constants = [constantsProvider constants];
657
658 assertThat([[(GBModelBase *)[constants objectAtIndex:0] comment] stringValue], is(@"postfix1"));
659 assertThat([[(GBModelBase *)[constants objectAtIndex:1] comment] stringValue], is(@"postfix2"));
660 assertThat([[(GBModelBase *)[constants objectAtIndex:2] comment] stringValue], is(@"comment3"));
661 assertThat([[(GBModelBase *)[constants objectAtIndex:3] comment] stringValue], is(@"comment4"));
662 assertThat([[(GBModelBase *)[constants objectAtIndex:4] comment] stringValue], is(@"comment5"));
663 assertThatInteger([constants count], equalToInteger(5));
664 }
665
666
667 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationCommentIgnorePostfix {
668 // setup
669 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
670 GBStore *store = [[GBStore alloc] init];
671 // execute
672 [parser parseObjectsFromString:@"@implementation MyClass /** Comment1 */ -(id)method1 ///< postfix1\n{} /** Comment2 */ +(void)method2{}///< postfix2\n @end" sourceFile:@"filename.m" toStore:store];
673 // verify
674 GBClassData *class = [[store classes] anyObject];
675 NSArray *methods = [[class methods] methods];
676 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
677 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
678 assertThatInteger([methods count], equalToInteger(2));
679 }
680
681 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationPostfixComment {
682 // setup
683 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
684 GBStore *store = [[GBStore alloc] init];
685 // execute
686 [parser parseObjectsFromString:@"@implementation MyClass -(id)method1 ///< Comment1\n{} +(void)method2///< Comment2\n{} @end" sourceFile:@"filename.m" toStore:store];
687 // verify
688 GBClassData *class = [[store classes] anyObject];
689 NSArray *methods = [[class methods] methods];
690 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
691 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
692 }
693
694 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationPostfixCommentProperSourceLineNumber {
695 // setup
696 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
697 GBStore *store = [[GBStore alloc] init];
698 // execute
699 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@implementation MyClass\n-(void)method ///< comment\n{} @end" sourceFile:@"filename.h" toStore:store];
700 // verify
701 GBClassData *class = [[store classes] anyObject];
702 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
703 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
704 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
705 }
706
707 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationMultilinePostfixComment {
708 // setup
709 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
710 GBStore *store = [[GBStore alloc] init];
711 // execute
712 [parser parseObjectsFromString:@"@implementation MyClass -(id)method1:(id)param1 ///< Comment1\npart2:(id)param2 ///< Comment2\n{}\n@end" sourceFile:@"filename.m" toStore:store];
713 // verify
714 GBClassData *class = [[store classes] anyObject];
715 NSArray *methods = [[class methods] methods];
716 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1\nComment2"));
717 assertThatInteger([methods count], equalToInteger(1));
718 }
719
720 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationMultilinePostfixCommentLong {
721 // setup
722 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
723 GBStore *store = [[GBStore alloc] init];
724 // execute
725 [parser parseObjectsFromString:@"@implementation MyClass -(id)method1:(id)param1 ///< Comment1\npart2:(id)param2 ///< Comment2\n///< Comment3\n{}\n@end" sourceFile:@"filename.m" toStore:store];
726 // verify
727 GBClassData *class = [[store classes] anyObject];
728 NSArray *methods = [[class methods] methods];
729 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1\nComment2\nComment3"));
730 assertThatInteger([methods count], equalToInteger(1));
731 }
732
733 - (void)testParseObjectsFromString_shouldRegisterMethodDeclarationMultilinePostfixCommentPropperSourceLineNumber {
734 // setup
735 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
736 GBStore *store = [[GBStore alloc] init];
737 // execute
738 [parser parseObjectsFromString:@"@implementation MyClass\n -(id)method1:(id)param1 ///< Comment1\npart2:(id)param2 ///< Comment2\n{}\n@end" sourceFile:@"filename.m" toStore:store];
739 // verify
740 GBClassData *class = [[store classes] anyObject];
741 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
742 assertThat(method.comment.sourceInfo.filename, is(@"filename.m"));
743 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(2));
744 }
745
746
747 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionCommentIgnorePostfixComment {
748 // setup
749 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
750 GBStore *store = [[GBStore alloc] init];
751 // execute
752 [parser parseObjectsFromString:@"@interface MyClass /** Comment1 */ -(id)method1; ///< postfix\n /** Comment2 */ +(void)method2 ///< postfix\n; @end" sourceFile:@"filename.h" toStore:store];
753 // verify
754 GBClassData *class = [[store classes] anyObject];
755 NSArray *methods = [[class methods] methods];
756 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
757 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
758 assertThatInteger([methods count], equalToInteger(2));
759 }
760
761 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionPostfixComment {
762 // setup
763 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
764 GBStore *store = [[GBStore alloc] init];
765 // execute
766 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n-(id)method1; ///< Comment1\n-(id)method2;\n///< Comment2\n @end" sourceFile:@"filename.h" toStore:store];
767 // verify
768 GBClassData *class = [[store classes] anyObject];
769 NSArray *methods = [[class methods] methods];
770 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
771 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
772 }
773
774 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionPostfixCommentSourceFileAndLineNumber {
775 // setup
776 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
777 GBStore *store = [[GBStore alloc] init];
778 // execute
779 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n-(void)method; ///< Comment1\n @end" sourceFile:@"filename.h" toStore:store];
780 // verify
781 GBClassData *class = [[store classes] anyObject];
782 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
783 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
784 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
785 }
786
787 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionMultilinePostfixComment {
788 // setup
789 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
790 GBStore *store = [[GBStore alloc] init];
791 // execute
792 [parser parseObjectsFromString:@"@interface MyClass -(id)method1:(id)param1 ///< Comment1\npart2:(id)param2; ///< Comment2\n@end" sourceFile:@"filename.h" toStore:store];
793 // verify
794 GBClassData *class = [[store classes] anyObject];
795 NSArray *methods = [[class methods] methods];
796 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1\nComment2"));
797 assertThatInteger([methods count], equalToInteger(1));
798 }
799
800 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionMultilinePostfixCommentLong {
801 // setup
802 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
803 GBStore *store = [[GBStore alloc] init];
804 // execute
805 [parser parseObjectsFromString:@"@interface MyClass -(id)method1:(id)param1 ///< Comment1\npart2:(id)param2 ///< Comment2\n///< Comment3\n;///< Comment4\n@end" sourceFile:@"filename.h" toStore:store];
806 // verify
807 GBClassData *class = [[store classes] anyObject];
808 NSArray *methods = [[class methods] methods];
809 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1\nComment2\nComment3\nComment4"));
810 assertThatInteger([methods count], equalToInteger(1));
811 }
812
813 - (void)testParseObjectsFromString_shouldRegisterMethodDefinitionMultilinePostfixCommentPropperSourceLineNumber {
814 // setup
815 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
816 GBStore *store = [[GBStore alloc] init];
817 // execute
818 [parser parseObjectsFromString:@"///< comment\n/// comment\n#define SOMETHING\n\n@interface MyClass\n -(id)method1:(id)param1 ///< Comment1\npart2:(id)param2 ///< Comment2\n;\n@end" sourceFile:@"filename.h" toStore:store];
819 // verify
820 GBClassData *class = [[store classes] anyObject];
821 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
822 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
823 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
824 }
825
826
827 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionPostfixComment {
828 // setup
829 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
830 GBStore *store = [[GBStore alloc] init];
831 // execute
832 [parser parseObjectsFromString:@"@interface MyClass @property(readonly)NSInteger p1; ///< Comment1\n @property(readonly)NSInteger p2; ///< Comment2\n @end" sourceFile:@"filename.h" toStore:store];
833 // verify
834 GBClassData *class = [[store classes] anyObject];
835 NSArray *methods = [[class methods] methods];
836 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"Comment1"));
837 assertThat([[(GBModelBase *)[methods objectAtIndex:1] comment] stringValue], is(@"Comment2"));
838 }
839
840 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionPostfixCommentLong {
841 // setup
842 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
843 GBStore *store = [[GBStore alloc] init];
844 // execute
845 [parser parseObjectsFromString:@"@interface MyClass @property///< postfix1\n(readonly)///< postfix2\nNSInteger///<postfix3\n p1///<postfix4\n; ///< postfix5\n @end" sourceFile:@"filename.h" toStore:store];
846 // verify
847 GBClassData *class = [[store classes] anyObject];
848 NSArray *methods = [[class methods] methods];
849 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"postfix1\npostfix2\npostfix3\npostfix4\npostfix5"));
850 }
851
852 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionPostfixCommentSourceFileAndLineNumber {
853 // setup
854 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
855 GBStore *store = [[GBStore alloc] init];
856 // execute
857 [parser parseObjectsFromString:@"/// comment\n\n#define SOMETHING\n\n@interface MyClass\n@property(readonly)int p1;///< comment\n @end" sourceFile:@"filename.h" toStore:store];
858 // verify
859 GBClassData *class = [[store classes] anyObject];
860 GBMethodData *method = [[[class methods] methods] objectAtIndex:0];
861 assertThat(method.comment.sourceInfo.filename, is(@"filename.h"));
862 assertThatInteger(method.comment.sourceInfo.lineNumber, equalToInteger(6));
863 }
864
865 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionCommentIgnorePostfixComment {
866 // setup
867 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
868 GBStore *store = [[GBStore alloc] init];
869 // execute
870 [parser parseObjectsFromString:@"@interface MyClass\n/** prefix */\n@property(readonly)int p1;///< postfix\n @end" sourceFile:@"filename.h" toStore:store];
871 // verify
872 GBClassData *class = [[store classes] anyObject];
873 NSArray *methods = [[class methods] methods];
874 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"prefix"));
875 assertThatInteger([methods count], equalToInteger(1));
876 }
877
878 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionPostfixCommentInsideDefinition {
879 // setup
880 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
881 GBStore *store = [[GBStore alloc] init];
882 // execute
883 [parser parseObjectsFromString:@"@interface MyClass\n@property(readonly)///< inside\n int p1;\n @end" sourceFile:@"filename.h" toStore:store];
884 // verify
885 GBClassData *class = [[store classes] anyObject];
886 NSArray *methods = [[class methods] methods];
887 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"inside"));
888 assertThatInteger([methods count], equalToInteger(1));
889 }
890
891 - (void)testParseObjectsFromString_shouldRegisterPropertyDefinitionPostfixCommentInsideDefinitionMultiline {
892 // setup
893 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
894 GBStore *store = [[GBStore alloc] init];
895 // execute
896 [parser parseObjectsFromString:@"@interface MyClass\n@property(readonly)///< inside\n int p1; ///<after\n @end" sourceFile:@"filename.h" toStore:store];
897 // verify
898 GBClassData *class = [[store classes] anyObject];
899 NSArray *methods = [[class methods] methods];
900 assertThat([[(GBModelBase *)[methods objectAtIndex:0] comment] stringValue], is(@"inside\nafter"));
901 assertThatInteger([methods count], equalToInteger(1));
902 }
903
9ea04a7 @tomaz Fixed methods parsing in cases where #pragma mark - is used. Closes #50.
authored
904 #pragma mark Various cases
905
906 - (void)testParseObjectsFromString_shouldSkipAnythingNotMethod {
907 // setup
908 GBObjectiveCParser *parser = [GBObjectiveCParser parserWithSettingsProvider:[GBTestObjectsRegistry mockSettingsProvider]];
909 GBStore *store = [[GBStore alloc] init];
910 // execute
911 [parser parseObjectsFromString:
912 @"@interface MyClass\n"
913 @"#pragma mark -\n"
914 @"#pragma mark Something\n"
915 @"/** comment */\n"
916 @"-(void)method;\n"
917 @"@end" sourceFile:@"filename.h" toStore:store];
918 // verify
919 GBClassData *class = [[store classes] anyObject];
920 NSArray *methods = [[class methods] methods];
921 GBMethodData *method = [methods objectAtIndex:0];
922 assertThatInteger([methods count], equalToInteger(1));
923 [self assertMethod:method matchesInstanceComponents:@"void", @"method", nil];
924 assertThat(method.comment.stringValue, is(@"comment"));
925 }
926
41ea1e9 @tomaz Split unit tests for class parsing into different components (ivars, …
authored
927 @end
Something went wrong with that request. Please try again.