-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy pathGBMethodDataTesting.m
616 lines (563 loc) · 23.7 KB
/
GBMethodDataTesting.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//
// GBAdoptedProtocolsProviderTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 26.7.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBTestObjectsRegistry.h"
#import "GBDataObjects.h"
@interface GBMethodData (PrivateAPI)
@property (readonly) NSString *methodSelectorDelimiter;
@property (readonly) NSString *methodPrefix;
@end
#pragma mark -
@interface GBMethodDataTesting : GBObjectsAssertor
@end
@implementation GBMethodDataTesting
#pragma mark Initialization testing
- (void)testMethodData_shouldInitializeSingleTypelessInstanceSelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry instanceMethodWithArguments:[GBMethodArgument methodArgumentWithName:@"method"], nil];
// verify
assertThat(data.methodSelector, is(@"method"));
}
- (void)testMethodData_shouldInitializeSingleTypedInstanceSelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
// verify
assertThat(data.methodSelector, is(@"method:"));
}
- (void)testMethodData_shouldInitializeMultipleArgumentInstanceSelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry instanceMethodWithNames:@"delegate", @"checked", @"something", nil];
// verify
assertThat(data.methodSelector, is(@"delegate:checked:something:"));
}
- (void)testMethodData_shouldInitializeSingleTypelessClassSelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry classMethodWithArguments:[GBMethodArgument methodArgumentWithName:@"method"], nil];
// verify
assertThat(data.methodSelector, is(@"method"));
}
- (void)testMethodData_shouldInitializeSingleTypedClassSelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry classMethodWithNames:@"method", nil];
// verify
assertThat(data.methodSelector, is(@"method:"));
}
- (void)testMethodData_shouldInitializeMultipleArgumentClassSelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry classMethodWithNames:@"delegate", @"checked", @"something", nil];
// verify
assertThat(data.methodSelector, is(@"delegate:checked:something:"));
}
- (void)testMethodData_shouldInitializePropertySelector {
// setup & execute
GBMethodData *data = [GBTestObjectsRegistry propertyMethodWithArgument:@"isSelected"];
// verify
assertThat(data.methodSelector, is(@"isSelected"));
}
#pragma mark - Property initializations
- (void)testMethodData_shouldInitializePropertyWithSingleComponent {
// setup & execute
NSArray *attributes = @[@"readonly"];
NSArray *components = @[@"UIView", @"*", @"value"];
GBMethodData *data = [GBMethodData propertyDataWithAttributes:attributes components:components];
// verify
assertThat(data.methodAttributes, onlyContains(@"readonly", nil));
assertThat(data.methodResultTypes, onlyContains(@"UIView", @"*", nil));
assertThat(data.methodSelector, is(@"value"));
}
- (void)testMethodData_shouldInitializePropertyWithMultipleComponents {
// setup & execute
NSArray *attributes = @[@"nonatomic", @"assign"];
NSArray *components = @[@"IBOutlet", @"UIView", @"*", @"value"];
GBMethodData *data = [GBMethodData propertyDataWithAttributes:attributes components:components];
// verify
assertThat(data.methodAttributes, onlyContains(@"nonatomic", @"assign", nil));
assertThat(data.methodResultTypes, onlyContains(@"IBOutlet", @"UIView", @"*", nil));
assertThat(data.methodSelector, is(@"value"));
}
#pragma mark Merging testing
- (void)testMergeDataFromObject_shouldMergeImplementationDetails {
// setup - methods don't merge any data, except they need to send base class merging message!
GBMethodData *original = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
GBMethodData *source = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"file" lineNumber:1]];
// execute
[original mergeDataFromObject:source];
// verify - simple testing here, fully tested in GBModelBaseTesting!
assertThatInteger([original.sourceInfos count], equalToInteger(1));
}
- (void)testMergeDataFromObject_shouldMergeMethodWithDifferentResultType {
// setup
GBMethodData *original = [GBMethodData methodDataWithType:GBMethodTypeInstance result:@[@"id"] arguments:@[[GBMethodArgument methodArgumentWithName:@"method"]]];
GBMethodData *source = [GBMethodData methodDataWithType:GBMethodTypeInstance result:@[@"NSString *"] arguments:@[[GBMethodArgument methodArgumentWithName:@"method"]]];
// execute
[original mergeDataFromObject:source];
// verify - should keep original return type
assertThatInteger([original.methodResultTypes count], equalToInteger(1));
assertThat(original.methodResultTypes[0], is(@"id"));
}
- (void)testMergeDataFromObject_shouldMergePropertyWithDifferentResultType {
// setup
GBMethodData *original = [GBMethodData propertyDataWithAttributes:@[@"readonly", @"retain"] components:@[@"id", @"value"]];
GBMethodData *source = [GBMethodData propertyDataWithAttributes:@[@"readwrite", @"retain"] components:@[@"NSString *", @"value"]];
// execute
[original mergeDataFromObject:source];
// verify - should keep original return type
assertThatInteger([original.methodResultTypes count], equalToInteger(1));
assertThat(original.methodResultTypes[0], is(@"id"));
}
- (void)testMergeDataFromObject_shouldMergePropertyWithDifferentAttributes {
// setup
GBMethodData *original = [GBMethodData propertyDataWithAttributes:@[@"readonly", @"retain"] components:@[@"BOOL", @"value"]];
GBMethodData *source = [GBMethodData propertyDataWithAttributes:@[@"readwrite", @"retain"] components:@[@"BOOL", @"value"]];
// execute
[original mergeDataFromObject:source];
// verify - should keep original attributes
assertThat(original.methodAttributes[0], is(@"readonly"));
assertThat(original.methodAttributes[1], is(@"retain"));
}
- (void)testMergeDataFromObject_shouldMergeManualPropertyGetterImplementation {
// setup
GBMethodData *original = [GBMethodData propertyDataWithAttributes:@[@"readonly"] components:@[@"BOOL", @"value"]];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"file1" lineNumber:1]];
GBMethodArgument *arg = [GBMethodArgument methodArgumentWithName:@"value"];
GBMethodData *source = [GBMethodData methodDataWithType:GBMethodTypeInstance result:@[@"BOOL"] arguments:@[arg]];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"file2" lineNumber:1]];
// execute
[original mergeDataFromObject:source];
// verify - simple testing here, just to make sure both are used and manual implementation is properly detected (i.e. no exception is thrown), fully tested in GBModelBaseTesting!
assertThatInteger([original.sourceInfos count], equalToInteger(2));
}
- (void)testMergeDataFromObject_shouldMergeManualPropertySetterImplementation {
// setup
GBMethodData *original = [GBMethodData propertyDataWithAttributes:@[@"readonly"] components:@[@"BOOL", @"value"]];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"file1" lineNumber:1]];
GBMethodData *source = [GBTestObjectsRegistry instanceMethodWithNames:@"setValue", nil];
[source registerSourceInfo:[GBSourceInfo infoWithFilename:@"file2" lineNumber:1]];
// execute
[original mergeDataFromObject:source];
// verify - simple testing here, just to make sure both are used and manual implementation is properly detected (i.e. no exception is thrown), fully tested in GBModelBaseTesting!
assertThatInteger([original.sourceInfos count], equalToInteger(2));
}
- (void)testMergeDataFromObject_shouldMergeManualPropertyGetterAndSetterImplementation {
// setup
GBMethodData *original = [GBMethodData propertyDataWithAttributes:@[@"readonly"] components:@[@"BOOL", @"value"]];
[original registerSourceInfo:[GBSourceInfo infoWithFilename:@"file1" lineNumber:1]];
GBMethodArgument *arg = [GBMethodArgument methodArgumentWithName:@"value"];
GBMethodData *getter = [GBMethodData methodDataWithType:GBMethodTypeInstance result:@[@"BOOL"] arguments:@[arg]];
[getter registerSourceInfo:[GBSourceInfo infoWithFilename:@"file2" lineNumber:1]];
GBMethodData *setter = [GBTestObjectsRegistry instanceMethodWithNames:@"setValue", nil];
[setter registerSourceInfo:[GBSourceInfo infoWithFilename:@"file3" lineNumber:1]];
// execute
[original mergeDataFromObject:getter];
[original mergeDataFromObject:setter];
// verify - simple testing here, just to make sure both are used and manual implementation is properly detected (i.e. no exception is thrown), fully tested in GBModelBaseTesting!
assertThatInteger([original.sourceInfos count], equalToInteger(3));
}
- (void)testMergeDataFromObject_shouldUseArgumentNamesFromComment {
// setup
GBMethodArgument *arg1 = [GBMethodArgument methodArgumentWithName:@"method" types:@[@"id"] var:@"var"];
GBMethodData *original = [GBTestObjectsRegistry instanceMethodWithArguments:arg1, nil];
GBMethodArgument *arg2 = [GBMethodArgument methodArgumentWithName:@"method" types:@[@"id"] var:@"theVar"];
GBMethodData *source = [GBTestObjectsRegistry instanceMethodWithArguments:arg2, nil];
[source setComment:[GBComment commentWithStringValue:@"Comment"]];
// execute
[original mergeDataFromObject:source];
// verify
GBMethodArgument *mergedArgument = original.methodArguments[0];
assertThat(mergedArgument.argumentVar, is(@"theVar"));
}
#pragma mark Property helpers
- (void)testPropertySelectors_shouldReturnProperValueForProperties {
// setup & execute
NSArray *components = @[@"BOOL", @"value"];
GBMethodData *property1 = [GBMethodData propertyDataWithAttributes:@[@"readonly"] components:components];
GBMethodData *property2 = [GBMethodData propertyDataWithAttributes:@[@"getter", @"=", @"isValue"] components:components];
GBMethodData *property3 = [GBMethodData propertyDataWithAttributes:@[@"setter", @"=", @"setTheValue:"] components:components];
GBMethodData *property4 = [GBMethodData propertyDataWithAttributes:@[@"getter", @"=", @"isValue", @"setter", @"=", @"setTheValue:"] components:components];
// verify
assertThat(property1.propertyGetterSelector, is(@"value"));
assertThat(property1.propertySetterSelector, is(@"setValue:"));
assertThat(property2.propertyGetterSelector, is(@"isValue"));
assertThat(property2.propertySetterSelector, is(@"setValue:"));
assertThat(property3.propertyGetterSelector, is(@"value"));
assertThat(property3.propertySetterSelector, is(@"setTheValue:"));
assertThat(property4.propertyGetterSelector, is(@"isValue"));
assertThat(property4.propertySetterSelector, is(@"setTheValue:"));
}
- (void)testPropertySelectors_shouldReturnNilForMethods {
// setup & execute
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"value", nil];
// verify
assertThat(method.propertyGetterSelector, is(nil));
assertThat(method.propertySetterSelector, is(nil));
}
#pragma mark Convenience methods testing
- (void)testIsInstanceMethod_shouldReturnProperValue {
// setup & execute
GBMethodData *method1 = [GBTestObjectsRegistry classMethodWithNames:@"method", nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
GBMethodData *method3 = [GBTestObjectsRegistry propertyMethodWithArgument:@"method"];
// verify
assertThatBool(method1.isInstanceMethod, equalToBool(NO));
assertThatBool(method2.isInstanceMethod, equalToBool(YES));
assertThatBool(method3.isInstanceMethod, equalToBool(NO));
}
- (void)testIsClassMethod_shouldReturnProperValue {
// setup & execute
GBMethodData *method1 = [GBTestObjectsRegistry classMethodWithNames:@"method", nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
GBMethodData *method3 = [GBTestObjectsRegistry propertyMethodWithArgument:@"method"];
// verify
assertThatBool(method1.isClassMethod, equalToBool(YES));
assertThatBool(method2.isClassMethod, equalToBool(NO));
assertThatBool(method3.isClassMethod, equalToBool(NO));
}
- (void)testIsMethod_shouldReturnProperValue {
// setup & execute
GBMethodData *method1 = [GBTestObjectsRegistry classMethodWithNames:@"method", nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
GBMethodData *method3 = [GBTestObjectsRegistry propertyMethodWithArgument:@"method"];
// verify
assertThatBool(method1.isMethod, equalToBool(YES));
assertThatBool(method2.isMethod, equalToBool(YES));
assertThatBool(method3.isMethod, equalToBool(NO));
}
- (void)testIsProperty_shouldReturnProperValue {
// setup & execute
GBMethodData *method1 = [GBTestObjectsRegistry classMethodWithNames:@"method", nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
GBMethodData *method3 = [GBTestObjectsRegistry propertyMethodWithArgument:@"method"];
// verify
assertThatBool(method1.isProperty, equalToBool(NO));
assertThatBool(method2.isProperty, equalToBool(NO));
assertThatBool(method3.isProperty, equalToBool(YES));
}
#pragma mark Formatted components testing
- (void)testFormattedComponents_shouldReturnSimplePropertyComponents {
// setup
NSArray *attributes = @[@"readonly"];
NSArray *components = @[@"BOOL", @"name"];
GBMethodData *method = [GBMethodData propertyDataWithAttributes:attributes components:components];
// execute
NSArray *result = [method formattedComponents];
// verify: {@property}-{ }-{(}-{readonly}-{)}-{ }-{BOOL}-{ }-{name}
[self assertFormattedComponents:result match:
@"@property", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"readonly", 0, GBNULL,
@")", 0, GBNULL,
@" ", 0, GBNULL,
@"BOOL", 0, GBNULL,
@" ", 0, GBNULL,
@"name", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnComplexPropertyComponents {
// setup
NSArray *attributes = @[@"readonly", @"nonatomic"];
NSArray *components = @[@"unsigned", @"int", @"name"];
GBMethodData *method = [GBMethodData propertyDataWithAttributes:attributes components:components];
// execute
NSArray *result = [method formattedComponents];
// verify: {@property}-{ }-{(}-{readonly}-{,}-{ }-{nonatomic}-{)}-{ }-{unsigned}-{ }-{int}-{ }-{name}
[self assertFormattedComponents:result match:
@"@property", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"readonly", 0, GBNULL,
@",", 0, GBNULL,
@" ", 0, GBNULL,
@"nonatomic", 0, GBNULL,
@")", 0, GBNULL,
@" ", 0, GBNULL,
@"unsigned", 0, GBNULL,
@" ", 0, GBNULL,
@"int", 0, GBNULL,
@" ", 0, GBNULL,
@"name", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldProperlyHandlePropertyWithNoAttributes {
// setup
NSArray *attributes = [NSArray array];
NSArray *components = @[@"NSString", @"*", @"name"];
GBMethodData *method = [GBMethodData propertyDataWithAttributes:attributes components:components];
// execute
NSArray *result = [method formattedComponents];
// verify: {@property}-{ }-{NSString}-{ }-{*}-{name}
[self assertFormattedComponents:result match:
@"@property", 0, GBNULL,
@" ", 0, GBNULL,
@"NSString", 0, GBNULL,
@" ", 0, GBNULL,
@"*", 0, GBNULL,
@"name", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnPointerPropertyComponents {
// setup
NSArray *attributes = @[@"readonly"];
NSArray *components = @[@"NSString", @"*", @"name"];
GBMethodData *method = [GBMethodData propertyDataWithAttributes:attributes components:components];
// execute
NSArray *result = [method formattedComponents];
// verify: {@property}-{ }-{(}-{readonly}-{)}-{ }-{NSString}-{ }-{*}-{name}
[self assertFormattedComponents:result match:
@"@property", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"readonly", 0, GBNULL,
@")", 0, GBNULL,
@" ", 0, GBNULL,
@"NSString", 0, GBNULL,
@" ", 0, GBNULL,
@"*", 0, GBNULL,
@"name", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldCombineGetterAndSetterAttributes {
// setup
NSArray *attributes = @[@"readonly", @"getter", @"=", @"isName", @"setter", @"=", @"setName:"];
NSArray *components = @[@"NSString", @"*", @"name"];
GBMethodData *method = [GBMethodData propertyDataWithAttributes:attributes components:components];
// execute
NSArray *result = [method formattedComponents];
// verify: {@property}-{ }-{(}-{readonly}-{,}-{ }-{getter}-{=}-{isName}-{,}-{ }-{setter}-{=}-{setName:}-{)}-{ }-{NSString}-{ }-{*}-{name}
[self assertFormattedComponents:result match:
@"@property", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"readonly", 0, GBNULL,
@",", 0, GBNULL,
@" ", 0, GBNULL,
@"getter", 0, GBNULL,
@"=", 0, GBNULL,
@"isName", 0, GBNULL,
@",", 0, GBNULL,
@" ", 0, GBNULL,
@"setter", 0, GBNULL,
@"=", 0, GBNULL,
@"setName:", 0, GBNULL,
@")", 0, GBNULL,
@" ", 0, GBNULL,
@"NSString", 0, GBNULL,
@" ", 0, GBNULL,
@"*", 0, GBNULL,
@"name", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnSimpleInstanceMethodComponents {
// setup
NSArray *results = @[@"void"];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"method"]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeInstance result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {-}-{ }-{(}-{void}-{)}-{method}
[self assertFormattedComponents:result match:
@"-", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"void", 0, GBNULL,
@")", 0, GBNULL,
@"method", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnSingleArgumentInstanceMethodComponents {
// setup
NSArray *results = @[@"unsigned", @"int"];
NSArray *types = @[@"bla", @"blu"];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"method" types:types var:@"val"]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeInstance result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {-}-{ }-{(}-{BOOL}-{)}-{method}-{:}-{(}-{int}-{)}-{val}
[self assertFormattedComponents:result match:
@"-", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"unsigned", 0, GBNULL,
@" ", 0, GBNULL,
@"int", 0, GBNULL,
@")", 0, GBNULL,
@"method", 0, GBNULL,
@":", 0, GBNULL,
@"(", 0, GBNULL,
@"bla", 0, GBNULL,
@" ", 0, GBNULL,
@"blu", 0, GBNULL,
@")", 0, GBNULL,
@"val", 1, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnMultiArgumentInstanceMethodComponents {
// setup
NSArray *results = @[@"BOOL"];
NSArray *types = @[@"int"];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"doSomething" types:types var:@"val"],
[GBMethodArgument methodArgumentWithName:@"withOperator" types:types var:@"op"]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeInstance result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {-}-{ }-{(}-{BOOL}-{)}-{doSomething}-{:}-{(}-{int}-{)}-{val}-{ }-{withOperator}-{:}-{(}-{int}-{)}-{op}
[self assertFormattedComponents:result match:
@"-", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"BOOL", 0, GBNULL,
@")", 0, GBNULL,
@"doSomething", 0, GBNULL,
@":", 0, GBNULL,
@"(", 0, GBNULL,
@"int", 0, GBNULL,
@")", 0, GBNULL,
@"val", 1, GBNULL,
@" ", 0, GBNULL,
@"withOperator", 0, GBNULL,
@":", 0, GBNULL,
@"(", 0, GBNULL,
@"int", 0, GBNULL,
@")", 0, GBNULL,
@"op", 1, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnPointerInstanceMethodComponents {
// setup
NSArray *results = @[@"NSArray", @"*"];
NSArray *types = @[@"NSString", @"*"];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"method" types:types var:@"val"]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeInstance result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {-}-{ }-{(}-{BOOL}-{)}-{method}-{:}-{(}-{int}-{)}-{val}
[self assertFormattedComponents:result match:
@"-", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"NSArray", 0, GBNULL,
@" ", 0, GBNULL,
@"*", 0, GBNULL,
@")", 0, GBNULL,
@"method", 0, GBNULL,
@":", 0, GBNULL,
@"(", 0, GBNULL,
@"NSString", 0, GBNULL,
@" ", 0, GBNULL,
@"*", 0, GBNULL,
@")", 0, GBNULL,
@"val", 1, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnVariableArgumentInstanceMethodComponents {
// setup
NSArray *results = @[@"void"];
NSArray *types = @[@"id"];
NSArray *macros = [NSArray array];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"method" types:types var:@"format" variableArg:YES terminationMacros:macros]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeInstance result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {-}-{ }-{(}-{void}-{)}-{method}-{:}-{(}-{id}-{)}-{format}-{,}-{ }-{...}
[self assertFormattedComponents:result match:
@"-", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"void", 0, GBNULL,
@")", 0, GBNULL,
@"method", 0, GBNULL,
@":", 0, GBNULL,
@"(", 0, GBNULL,
@"id", 0, GBNULL,
@")", 0, GBNULL,
@"format", 1, GBNULL,
@",", 0, GBNULL,
@" ", 0, GBNULL,
@"...", 1, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldReturnClassMethodComponents {
// setup
NSArray *results = @[@"void"];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"method"]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeClass result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {+}-{ }-{(}-{void}-{)}-{method}
[self assertFormattedComponents:result match:
@"+", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"void", 0, GBNULL,
@")", 0, GBNULL,
@"method", 0, GBNULL,
nil];
}
- (void)testFormattedComponents_shouldNotAddSpaceForProtocols {
// setup
NSArray *results = @[@"NSArray", @"*"];
NSArray *types = @[@"id", @"<", @"Protocol", @">"];
NSArray *arguments = @[[GBMethodArgument methodArgumentWithName:@"method" types:types var:@"val"]];
GBMethodData *method = [GBMethodData methodDataWithType:GBMethodTypeInstance result:results arguments:arguments];
// execute
NSArray *result = [method formattedComponents];
// verify: {-}-{ }-{(}-{BOOL}-{)}-{method}-{:}-{(}-{id}-{<}-{Protocol}-{>}-{)}-{val}
[self assertFormattedComponents:result match:
@"-", 0, GBNULL,
@" ", 0, GBNULL,
@"(", 0, GBNULL,
@"NSArray", 0, GBNULL,
@" ", 0, GBNULL,
@"*", 0, GBNULL,
@")", 0, GBNULL,
@"method", 0, GBNULL,
@":", 0, GBNULL,
@"(", 0, GBNULL,
@"id", 0, GBNULL,
@"<", 0, GBNULL,
@"Protocol", 0, GBNULL,
@">", 0, GBNULL,
@")", 0, GBNULL,
@"val", 1, GBNULL,
nil];
}
#pragma mark Helper methods testing
- (void)testMethodSelectorDelimiter_shouldReturnEmptyStringForProperties {
// setup
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"name"];
// execute & verify
assertThat(method.methodSelectorDelimiter, is(@""));
}
- (void)testMethodSelectorDelimiter_shouldReturnEmptyStringForMethodsWithoutParameters {
// setup
GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
// execute & verify
assertThat(method.methodSelectorDelimiter, is(@""));
}
- (void)testMethodSelectorDelimiter_shouldReturnEmptyStringForMethodsWithParameters {
// setup
GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withStyle", nil];
// execute & verify
assertThat(method1.methodSelectorDelimiter, is(@":"));
assertThat(method2.methodSelectorDelimiter, is(@":"));
}
- (void)testMethodPrefix_shouldReturnProperPrefix {
// setup, execute & verify
assertThat([[GBTestObjectsRegistry propertyMethodWithArgument:@"name"] methodPrefix], is(@"@property"));
assertThat(([[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil] methodPrefix]), is(@"-"));
assertThat(([[GBTestObjectsRegistry classMethodWithNames:@"method", nil] methodPrefix]), is(@"+"));
}
- (void)testIsTopLevelObject_shouldReturnNO {
// setup & execute
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
// verify
assertThatBool(method.isTopLevelObject, equalToBool(NO));
}
@end