/
GBApplicationSettingsProviderTesting.m
659 lines (606 loc) · 38.4 KB
/
GBApplicationSettingsProviderTesting.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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//
// GBApplicationSettingsProviderTesting.m
// appledoc
//
// Created by Tomaz Kragelj on 14.10.10.
// Copyright (C) 2010 Gentle Bytes. All rights reserved.
//
#import "GBDataObjects.h"
#import "GBApplicationSettingsProvider.h"
@interface GBApplicationSettingsProviderTesting : GHTestCase
- (NSDateFormatter *)yearFormatterFromSettings:(GBApplicationSettingsProvider *)settings;
- (NSDateFormatter *)yearToDayFormatterFromSettings:(GBApplicationSettingsProvider *)settings;
@end
@implementation GBApplicationSettingsProviderTesting
#pragma mark Placeholders replacing
- (void)testPlaceholderReplacements_shouldReplacePlaceholderStringsInAllSupportedValues {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.projectName = @"<P N>";
settings.projectCompany = @"<P C>";
settings.projectVersion = @"<P V>";
settings.companyIdentifier = @"<C I>";
NSString *template = @"%PROJECT/%COMPANY/%VERSION/%PROJECTID/%COMPANYID/%VERSIONID/%YEAR/%UPDATEDATE";
settings.docsetBundleIdentifier = template;
settings.docsetBundleName = template;
settings.docsetCertificateIssuer = template;
settings.docsetCertificateSigner = template;
settings.docsetDescription = template;
settings.docsetFallbackURL = template;
settings.docsetFeedName = template;
settings.docsetFeedURL = template;
settings.docsetPackageURL = template;
settings.docsetMinimumXcodeVersion = template;
settings.docsetPlatformFamily = template;
settings.docsetPublisherIdentifier = template;
settings.docsetPublisherName = template;
settings.docsetCopyrightMessage = template;
settings.docsetBundleFilename = template;
settings.docsetAtomFilename = template;
settings.docsetPackageFilename = template;
// setup expected values; this might break sometimes as it's based on time...
NSDate *date = [NSDate date];
NSString *year = [[self yearFormatterFromSettings:settings] stringFromDate:date];
NSString *day = [[self yearToDayFormatterFromSettings:settings] stringFromDate:date];
NSString *expected = [NSString stringWithFormat:@"<P N>/<P C>/<P V>/<P-N>/<C I>/<P-V>/%@/%@", year, day];
// execute
[settings replaceAllOccurencesOfPlaceholderStringsInSettingsValues];
// verify
assertThat(settings.docsetBundleIdentifier, is(expected));
assertThat(settings.docsetBundleName, is(expected));
assertThat(settings.docsetCertificateIssuer, is(expected));
assertThat(settings.docsetCertificateSigner, is(expected));
assertThat(settings.docsetDescription, is(expected));
assertThat(settings.docsetFallbackURL, is(expected));
assertThat(settings.docsetFeedName, is(expected));
assertThat(settings.docsetFeedURL, is(expected));
assertThat(settings.docsetPackageURL, is(expected));
assertThat(settings.docsetMinimumXcodeVersion, is(expected));
assertThat(settings.docsetPlatformFamily, is(expected));
assertThat(settings.docsetPublisherIdentifier, is(expected));
assertThat(settings.docsetPublisherName, is(expected));
assertThat(settings.docsetCopyrightMessage, is(expected));
assertThat(settings.docsetBundleFilename, is(expected));
assertThat(settings.docsetAtomFilename, is(expected));
assertThat(settings.docsetPackageFilename, is(expected));
}
- (void)testPlaceholderReplacements_shouldReplaceDocSetFilenames {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.projectName = @"<PN>";
settings.projectCompany = @"<PC>";
settings.projectVersion = @"<PV>";
settings.companyIdentifier = @"<CI>";
settings.docsetBundleFilename = @"<DSB>";
settings.docsetAtomFilename = @"<DSA>";
settings.docsetPackageFilename = @"<DSP>";
NSString *template = @"%DOCSETBUNDLEFILENAME/%DOCSETATOMFILENAME/%DOCSETPACKAGEFILENAME";
settings.docsetBundleIdentifier = template;
settings.docsetBundleName = template;
settings.docsetCertificateIssuer = template;
settings.docsetCertificateSigner = template;
settings.docsetDescription = template;
settings.docsetFallbackURL = template;
settings.docsetFeedName = template;
settings.docsetFeedURL = template;
settings.docsetPackageURL = template;
settings.docsetMinimumXcodeVersion = template;
settings.docsetPlatformFamily = template;
settings.docsetPublisherIdentifier = template;
settings.docsetPublisherName = template;
settings.docsetCopyrightMessage = template;
NSString *expected = @"<DSB>/<DSA>/<DSP>";
// execute
[settings replaceAllOccurencesOfPlaceholderStringsInSettingsValues];
// verify
assertThat(settings.docsetBundleIdentifier, is(expected));
assertThat(settings.docsetBundleName, is(expected));
assertThat(settings.docsetCertificateIssuer, is(expected));
assertThat(settings.docsetCertificateSigner, is(expected));
assertThat(settings.docsetDescription, is(expected));
assertThat(settings.docsetFallbackURL, is(expected));
assertThat(settings.docsetFeedName, is(expected));
assertThat(settings.docsetFeedURL, is(expected));
assertThat(settings.docsetPackageURL, is(expected));
assertThat(settings.docsetMinimumXcodeVersion, is(expected));
assertThat(settings.docsetPlatformFamily, is(expected));
assertThat(settings.docsetPublisherIdentifier, is(expected));
assertThat(settings.docsetPublisherName, is(expected));
assertThat(settings.docsetCopyrightMessage, is(expected));
}
- (void)testProjectIdentifier_shouldNormalizeProjectName {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.projectName = @"My Great \t Project";
// execute & verify
assertThat(settings.projectIdentifier, is(@"My-Great-Project"));
}
- (void)testVersionIdentifier_shouldNormalizeProjectVersion {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.projectVersion = @"1.0 beta3 \t something";
// execute & verify
assertThat(settings.versionIdentifier, is(@"1.0-beta3-something"));
}
#pragma mark HTML href names handling
- (void)testHtmlReferenceNameForObject_shouldReturnProperValueForTopLevelObjects {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBCategoryData *extension = [GBCategoryData categoryDataWithName:nil className:@"Class"];
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
// execute & verify
assertThat([settings htmlReferenceNameForObject:class], is(@"Class.html"));
assertThat([settings htmlReferenceNameForObject:category], is(@"Class+Category.html"));
assertThat([settings htmlReferenceNameForObject:extension], is(@"Class+.html"));
assertThat([settings htmlReferenceNameForObject:protocol], is(@"Protocol.html"));
}
- (void)testHtmlReferenceNameForObject_shouldReturnProperValueForDocuments {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"document-template.html" basePath:@""];
GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"path/document-template.html" basePath:@""];
GBDocumentData *document3 = [GBDocumentData documentDataWithContents:@"c" path:@"path/sub/document-template.html" basePath:@""];
GBDocumentData *document4 = [GBDocumentData documentDataWithContents:@"c" path:@"path/sub/document-template.html" basePath:@"path"];
// verify
assertThat([settings htmlReferenceNameForObject:document1], is(@"document.html"));
assertThat([settings htmlReferenceNameForObject:document2], is(@"document.html"));
assertThat([settings htmlReferenceNameForObject:document3], is(@"document.html"));
assertThat([settings htmlReferenceNameForObject:document4], is(@"document.html"));
}
- (void)testHtmlReferenceNameForObject_shouldReturnProperValueForMethods {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBMethodArgument *argument = [GBMethodArgument methodArgumentWithName:@"method"];
GBMethodData *method1 = [GBTestObjectsRegistry instanceMethodWithArguments:argument, nil];
GBMethodData *method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"doSomething", @"withVars", nil];
GBMethodData *property = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
GBClassData *class = [GBClassData classDataWithName:@"Class"];
[class.methods registerMethod:method1];
[class.methods registerMethod:method2];
[class.methods registerMethod:property];
// execute & verify
assertThat([settings1 htmlReferenceNameForObject:method1], is(@"//api/name/method"));
assertThat([settings1 htmlReferenceNameForObject:method2], is(@"//api/name/doSomething:withVars:"));
assertThat([settings1 htmlReferenceNameForObject:property], is(@"//api/name/value"));
assertThat([settings2 htmlReferenceNameForObject:method1], is(@"//apple_ref/occ/instm/Class/method"));
assertThat([settings2 htmlReferenceNameForObject:method2], is(@"//apple_ref/occ/instm/Class/doSomething:withVars:"));
assertThat([settings2 htmlReferenceNameForObject:property], is(@"//apple_ref/occ/instp/Class/value"));
}
#pragma mark HTML href references handling - index
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForClassFromIndex {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[class.methods registerMethod:method];
// execute & verify
assertThat([settings1 htmlReferenceForObject:class fromSource:nil], is(@"Classes/Class.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:nil], is(@"Classes/Class.html#//api/name/method:"));
assertThat([settings2 htmlReferenceForObject:class fromSource:nil], is(@"Classes/Class.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:nil], is(@"Classes/Class.html#//apple_ref/occ/instm/Class/method:"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCategoryFromIndex {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[category.methods registerMethod:method];
// execute & verify
assertThat([settings1 htmlReferenceForObject:category fromSource:nil], is(@"Categories/Class+Category.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:nil], is(@"Categories/Class+Category.html#//api/name/method:"));
assertThat([settings2 htmlReferenceForObject:category fromSource:nil], is(@"Categories/Class+Category.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:nil], is(@"Categories/Class+Category.html#//apple_ref/occ/instm/Class(Category)/method:"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForProtocolFromIndex {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBMethodData *method = [GBTestObjectsRegistry instanceMethodWithNames:@"method", nil];
[protocol.methods registerMethod:method];
// execute & verify
assertThat([settings1 htmlReferenceForObject:protocol fromSource:nil], is(@"Protocols/Protocol.html"));
assertThat([settings1 htmlReferenceForObject:method fromSource:nil], is(@"Protocols/Protocol.html#//api/name/method:"));
assertThat([settings2 htmlReferenceForObject:protocol fromSource:nil], is(@"Protocols/Protocol.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:nil], is(@"Protocols/Protocol.html#//apple_ref/occ/intfm/Protocol/method:"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForDocumentFromIndex {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"document-template.html" basePath:@""];
GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"include/document-template.html" basePath:@""];
GBDocumentData *document3 = [GBDocumentData documentDataWithContents:@"c" path:@"include/sub/document-template.html" basePath:@""];
GBDocumentData *document4 = [GBDocumentData documentDataWithContents:@"c" path:@"include/sub/document-template.html" basePath:@"include"];
GBDocumentData *document5 = [GBDocumentData documentDataWithContents:@"c" path:@"include/sub/document-template.html" basePath:@"include/sub"];
GBDocumentData *document6 = [GBDocumentData documentDataWithContents:@"c" path:@"include/sub/document-template.html" basePath:@"include/sub/document-template.html"];
// verify
assertThat([settings htmlReferenceForObject:document1 fromSource:nil], is(@"docs/document.html"));
assertThat([settings htmlReferenceForObject:document2 fromSource:nil], is(@"docs/include/document.html"));
assertThat([settings htmlReferenceForObject:document3 fromSource:nil], is(@"docs/include/sub/document.html"));
assertThat([settings htmlReferenceForObject:document4 fromSource:nil], is(@"docs/include/sub/document.html"));
assertThat([settings htmlReferenceForObject:document5 fromSource:nil], is(@"docs/sub/document.html"));
assertThat([settings htmlReferenceForObject:document6 fromSource:nil], is(@"docs/document.html"));
}
#pragma mark HTML href references handling - top level to top level
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToSameObjectReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBDocumentData *document = [GBDocumentData documentDataWithContents:@"c" path:@"document.ext"];
// execute & verify
assertThat([settings htmlReferenceForObject:class fromSource:class], is(@"Class.html"));
assertThat([settings htmlReferenceForObject:category fromSource:category], is(@"Class+Category.html"));
assertThat([settings htmlReferenceForObject:protocol fromSource:protocol], is(@"Protocol.html"));
assertThat([settings htmlReferenceForObject:document fromSource:document], is(@"document.html"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToSameTypeTopLevelObjectReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBClassData *class1 = [GBClassData classDataWithName:@"Class1"];
GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
GBCategoryData *category1 = [GBCategoryData categoryDataWithName:@"Category1" className:@"Class"];
GBCategoryData *category2 = [GBCategoryData categoryDataWithName:@"Category2" className:@"Class"];
GBProtocolData *protocol1 = [GBProtocolData protocolDataWithName:@"Protocol1"];
GBProtocolData *protocol2 = [GBProtocolData protocolDataWithName:@"Protocol2"];
GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"include/document1.ext" basePath:@"include"];
GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"include/document2.ext" basePath:@"include/document2.ext"];
// execute & verify
assertThat([settings htmlReferenceForObject:class1 fromSource:class2], is(@"../Classes/Class1.html"));
assertThat([settings htmlReferenceForObject:class2 fromSource:class1], is(@"../Classes/Class2.html"));
assertThat([settings htmlReferenceForObject:category1 fromSource:category2], is(@"../Categories/Class+Category1.html"));
assertThat([settings htmlReferenceForObject:category2 fromSource:category1], is(@"../Categories/Class+Category2.html"));
assertThat([settings htmlReferenceForObject:protocol1 fromSource:protocol2], is(@"../Protocols/Protocol1.html"));
assertThat([settings htmlReferenceForObject:protocol2 fromSource:protocol1], is(@"../Protocols/Protocol2.html"));
assertThat([settings htmlReferenceForObject:document1 fromSource:document2], is(@"../docs/include/document1.html"));
assertThat([settings htmlReferenceForObject:document2 fromSource:document1], is(@"../../docs/document2.html"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToDifferentTypeOfTopLevelObjectReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"include/document1.ext" basePath:@"include/document1.ext"];
GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"include/document2.ext" basePath:@"include"];
// execute & verify
assertThat([settings htmlReferenceForObject:class fromSource:category], is(@"../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:protocol], is(@"../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:document1], is(@"../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:document2], is(@"../../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:category fromSource:class], is(@"../Categories/Class+Category.html"));
assertThat([settings htmlReferenceForObject:category fromSource:protocol], is(@"../Categories/Class+Category.html"));
assertThat([settings htmlReferenceForObject:category fromSource:document1], is(@"../Categories/Class+Category.html"));
assertThat([settings htmlReferenceForObject:category fromSource:document2], is(@"../../Categories/Class+Category.html"));
assertThat([settings htmlReferenceForObject:protocol fromSource:class], is(@"../Protocols/Protocol.html"));
assertThat([settings htmlReferenceForObject:protocol fromSource:category], is(@"../Protocols/Protocol.html"));
assertThat([settings htmlReferenceForObject:protocol fromSource:document1], is(@"../Protocols/Protocol.html"));
assertThat([settings htmlReferenceForObject:protocol fromSource:document2], is(@"../../Protocols/Protocol.html"));
assertThat([settings htmlReferenceForObject:document1 fromSource:class], is(@"../docs/document1.html"));
assertThat([settings htmlReferenceForObject:document1 fromSource:category], is(@"../docs/document1.html"));
assertThat([settings htmlReferenceForObject:document1 fromSource:protocol], is(@"../docs/document1.html"));
assertThat([settings htmlReferenceForObject:document1 fromSource:document2], is(@"../../docs/document1.html"));
assertThat([settings htmlReferenceForObject:document2 fromSource:class], is(@"../docs/include/document2.html"));
assertThat([settings htmlReferenceForObject:document2 fromSource:category], is(@"../docs/include/document2.html"));
assertThat([settings htmlReferenceForObject:document2 fromSource:protocol], is(@"../docs/include/document2.html"));
assertThat([settings htmlReferenceForObject:document2 fromSource:document1], is(@"../docs/include/document2.html"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForDocumentToTopLevelObjectReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"document-template.html" basePath:@""];
GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"include/document-template.html" basePath:@""];
GBDocumentData *document3 = [GBDocumentData documentDataWithContents:@"c" path:@"include/sub/document-template.html" basePath:@"include"];
GBDocumentData *document4 = [GBDocumentData documentDataWithContents:@"c" path:@"include/sub/document-template.html" basePath:@"include/sub/document-template.html"];
// verify
assertThat([settings htmlReferenceForObject:class fromSource:document1], is(@"../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:document2], is(@"../../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:document3], is(@"../../../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:document4], is(@"../Classes/Class.html"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForCustomDocumentToTopLevelObjectReference {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
settings.outputPath = @"anything :)";
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"path/document-template.html" basePath:@"path"];
document1.isCustomDocument = YES;
GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"path/document-template.html" basePath:@""];
document2.isCustomDocument = YES;
// verify
assertThat([settings htmlReferenceForObject:class fromSource:document1], is(@"../Classes/Class.html"));
assertThat([settings htmlReferenceForObject:class fromSource:document2], is(@"Classes/Class.html"));
}
#pragma mark HTML href references handling - top level to members
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToItsMemberReference {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
[class.methods registerMethod:method];
// execute & verify
assertThat([settings1 htmlReferenceForObject:method fromSource:class], is(@"#//api/name/value"));
assertThat([settings1 htmlReferenceForObject:class fromSource:method], is(@"Class.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:class], is(@"#//apple_ref/occ/instp/Class/value"));
assertThat([settings2 htmlReferenceForObject:class fromSource:method], is(@"Class.html"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToSameTypeRemoteMemberReference {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class1 = [GBClassData classDataWithName:@"Class1"];
GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
GBMethodData *method = [GBTestObjectsRegistry propertyMethodWithArgument:@"value"];
[class1.methods registerMethod:method];
// execute & verify
assertThat([settings1 htmlReferenceForObject:method fromSource:class2], is(@"../Classes/Class1.html#//api/name/value"));
assertThat([settings1 htmlReferenceForObject:method fromSource:class1], is(@"#//api/name/value"));
assertThat([settings1 htmlReferenceForObject:class1 fromSource:method], is(@"Class1.html"));
assertThat([settings1 htmlReferenceForObject:class2 fromSource:method], is(@"../Classes/Class2.html"));
assertThat([settings2 htmlReferenceForObject:method fromSource:class2], is(@"../Classes/Class1.html#//apple_ref/occ/instp/Class1/value"));
assertThat([settings2 htmlReferenceForObject:method fromSource:class1], is(@"#//apple_ref/occ/instp/Class1/value"));
assertThat([settings2 htmlReferenceForObject:class1 fromSource:method], is(@"Class1.html"));
assertThat([settings2 htmlReferenceForObject:class2 fromSource:method], is(@"../Classes/Class2.html"));
}
- (void)testHtmlReferenceForObjectFromSource_shouldReturnProperValueForTopLevelObjectToDifferentTypeRemoteMemberReference {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings1.outputPath = @"anything :)";
settings2.outputPath = @"anything :)";
settings2.htmlAnchorFormat = GBHTMLAnchorFormatApple;
GBClassData *class = [GBClassData classDataWithName:@"Class"];
GBCategoryData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
GBMethodData *method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value1"];
GBMethodData *method2 = [GBTestObjectsRegistry propertyMethodWithArgument:@"value2"];
[class.methods registerMethod:method1];
[protocol.methods registerMethod:method2];
// execute & verify
assertThat([settings1 htmlReferenceForObject:method1 fromSource:protocol], is(@"../Classes/Class.html#//api/name/value1"));
assertThat([settings1 htmlReferenceForObject:method2 fromSource:class], is(@"../Protocols/Protocol.html#//api/name/value2"));
assertThat([settings2 htmlReferenceForObject:method1 fromSource:protocol], is(@"../Classes/Class.html#//apple_ref/occ/instp/Class/value1"));
assertThat([settings2 htmlReferenceForObject:method2 fromSource:class], is(@"../Protocols/Protocol.html#//apple_ref/occ/intfp/Protocol/value2"));
}
#pragma mark Template files handling
- (void)testIsPathRepresentingTemplateFile_shouldReturnCorrectResults {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute & verify
assertThatBool([settings isPathRepresentingTemplateFile:@"file"], equalToBool(NO));
assertThatBool([settings isPathRepresentingTemplateFile:@"file.html"], equalToBool(NO));
assertThatBool([settings isPathRepresentingTemplateFile:@"path/file.html"], equalToBool(NO));
assertThatBool([settings isPathRepresentingTemplateFile:@"file-template"], equalToBool(YES));
assertThatBool([settings isPathRepresentingTemplateFile:@"file-template.html"], equalToBool(YES));
assertThatBool([settings isPathRepresentingTemplateFile:@"path/file-template"], equalToBool(YES));
assertThatBool([settings isPathRepresentingTemplateFile:@"path/file-template.html"], equalToBool(YES));
}
- (void)testOutputFilenameForTemplatePath_shouldReturnCorrectResults {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute & verify
assertThat([settings outputFilenameForTemplatePath:@"file"], is(@"file"));
assertThat([settings outputFilenameForTemplatePath:@"file.html"], is(@"file.html"));
assertThat([settings outputFilenameForTemplatePath:@"path/file.html"], is(@"file.html"));
assertThat([settings outputFilenameForTemplatePath:@"file-template"], is(@"file"));
assertThat([settings outputFilenameForTemplatePath:@"file-template.html"], is(@"file.html"));
assertThat([settings outputFilenameForTemplatePath:@"path/file-template"], is(@"file"));
assertThat([settings outputFilenameForTemplatePath:@"path/file-template.html"], is(@"file.html"));
}
- (void)testTemplateFilenameForOutputPath_shuoldReturnCorrectResults {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute & verify
assertThat([settings templateFilenameForOutputPath:@"file"], is(@"file-template"));
assertThat([settings templateFilenameForOutputPath:@"file.html"], is(@"file-template.html"));
assertThat([settings templateFilenameForOutputPath:@"path/file.html"], is(@"path/file-template.html"));
assertThat([settings templateFilenameForOutputPath:@"path/file-template"], is(@"path/file-template"));
assertThat([settings templateFilenameForOutputPath:@"path/file-template.html"], is(@"path/file-template.html"));
}
#pragma mark Text conversion methods
- (void)testStringByEmbeddingCrossReference_shouldEmbeddCrossReferenceIfRequired {
// setup
GBApplicationSettingsProvider *settings1 = [GBApplicationSettingsProvider provider];
GBApplicationSettingsProvider *settings2 = [GBApplicationSettingsProvider provider];
settings2.embedCrossReferencesWhenProcessingMarkdown = NO;
// execute
NSString *result11 = [settings1 stringByEmbeddingCrossReference:@"[description](address \"title\")"];
NSString *result12 = [settings1 stringByEmbeddingCrossReference:@"[`description`](address \"title\")"];
NSString *result21 = [settings2 stringByEmbeddingCrossReference:@"[description](address \"title\")"];
NSString *result22 = [settings2 stringByEmbeddingCrossReference:@"[`description`](address \"title\")"];
// verify
assertThat(result11, is(@"~!@[description](address \"title\")@!~"));
assertThat(result12, is(@"~!@[`description`](address \"title\")@!~"));
assertThat(result21, is(@"[description](address \"title\")"));
assertThat(result22, is(@"[`description`](address \"title\")"));
}
#pragma mark Markdown to HTML conversion
- (void)testStringByConvertingMarkdownToHTML_shouldConvertEmbeddedCrossReferencesInText {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToHTML:@"~!@[description](address)@!~"];
NSString *result2 = [settings stringByConvertingMarkdownToHTML:@"[description](address)"];
// verify - Discount converts any kind of link, we just need to strip embedded prefix and suffix!
assertThat(result1, is(@"<p><a href=\"address\">description</a></p>"));
assertThat(result2, is(@"<p><a href=\"address\">description</a></p>"));
}
- (void)testStringByConvertingMarkdownToHTML_shouldAllowUsageOfUTF8CharacterSet {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToHTML:@"对"];
// verify
assertThat(result1, is(@"<p>对</p>"));
}
- (void)testStringByConvertingMarkdownToHTML_shouldConvertEmbeddedCrossReferencesInExampleBlock {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToHTML:@"\t~!@[description](address)@!~"];
NSString *result2 = [settings stringByConvertingMarkdownToHTML:@"\t[description](address)"];
// verify - Discount doesn't process links here, but we need to return auto generated to deafult! Note that Discount adds new line!
assertThat(result1, is(@"<pre><code>description\n</code></pre>"));
assertThat(result2, is(@"<pre><code>[description](address)\n</code></pre>"));
}
- (void)testStringByConvertingMarkdownToHTML_shouldConvertAppledocStyleBoldMarkersInText {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result = [settings stringByConvertingMarkdownToHTML:@"**~!$text$!~**"];
// verify - Discount converts ** part, we just need to cleanup the remaining texts!
assertThat(result, is(@"<p><strong>text</strong></p>"));
}
- (void)testStringByConvertingMarkdownToHTML_shouldConvertAppledocStyleBoldMarkersInExampleBlock {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToHTML:@"\t**~!$text$!~**"];
NSString *result2 = [settings stringByConvertingMarkdownToHTML:@"\t**text**"];
// verify - Discount doesn't process text here, so we should revert to original markup!
assertThat(result1, is(@"<pre><code>*text*\n</code></pre>"));
assertThat(result2, is(@"<pre><code>**text**\n</code></pre>"));
}
#pragma mark Markdown to text conversion
- (void)testStringByConvertingMarkdownToText_shouldConvertEmbeddedCrossReferencesInText {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"~!@[description](address)@!~"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"[description](address)"];
NSString *result3 = [settings stringByConvertingMarkdownToText:@"\t~!@[[class method]](address)@!~"];
NSString *result4 = [settings stringByConvertingMarkdownToText:@"\t[[class method]](address)"];
// verify - Discount converts any kind of link, we just need to strip embedded prefix and suffix!
assertThat(result1, is(@"description"));
assertThat(result2, is(@"description"));
assertThat(result3, is(@"\t[class method]"));
assertThat(result4, is(@"\t[class method]"));
}
- (void)testStringByConvertingMarkdownToText_shouldConvertEmbeddedCrossReferencesInExampleBlock {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"\t~!@[description](address)@!~"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"\t[description](address)"];
NSString *result3 = [settings stringByConvertingMarkdownToText:@"\t~!@[[class method]](address)@!~"];
NSString *result4 = [settings stringByConvertingMarkdownToText:@"\t[[class method]](address)"];
// verify - Discount doesn't process links here, but we need to return auto generated to deafult! Note that Discount adds new line!
assertThat(result1, is(@"\tdescription"));
assertThat(result2, is(@"\tdescription"));
assertThat(result3, is(@"\t[class method]"));
assertThat(result4, is(@"\t[class method]"));
}
- (void)testStringByConvertingMarkdownToText_shouldConvertEmbeddedAppledocBoldMarkersInText {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"~!$text$!~"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"**~!$text$!~**"];
// verify
assertThat(result1, is(@"text"));
assertThat(result2, is(@"text"));
}
- (void)testStringByConvertingMarkdownToText_shouldConvertEmbeddedAppledocBoldMarkersInExampleBlock {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"\t~!$text$!~"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"\t**~!$text$!~**"];
// verify
assertThat(result1, is(@"\ttext"));
assertThat(result2, is(@"\ttext"));
}
- (void)testStringByConvertingMarkdownToText_shouldConvertMarkdownReferences {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"simple text"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"[description](address)"];
NSString *result3 = [settings stringByConvertingMarkdownToText:@"[description](address \"title\")"];
NSString *result4 = [settings stringByConvertingMarkdownToText:@"prefix [description](address) suffix"];
NSString *result5 = [settings stringByConvertingMarkdownToText:@"[description1](address) [description2](address) [description3](address)"];
// verify
assertThat(result1, is(@"simple text"));
assertThat(result2, is(@"description"));
assertThat(result3, is(@"description"));
assertThat(result4, is(@"prefix description suffix"));
assertThat(result5, is(@"description1 description2 description3"));
}
- (void)testStringByConvertingMarkdownToText_shouldConvertFormattingMarkers {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"*desc*"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"`desc`"];
NSString *result3 = [settings stringByConvertingMarkdownToText:@"prefix *desc* suffix"];
NSString *result4 = [settings stringByConvertingMarkdownToText:@"*1* **2** ***3*** _4_ __5__ ___6___"];
NSString *result5 = [settings stringByConvertingMarkdownToText:@"_*1*_ *_2_* **_3_** _**4**_ *__5__* __*6*__"];
// verify
assertThat(result1, is(@"desc"));
assertThat(result2, is(@"desc"));
assertThat(result3, is(@"prefix desc suffix"));
assertThat(result4, is(@"1 2 3 4 5 6"));
assertThat(result5, is(@"1 2 3 4 5 6"));
}
- (void)testStringByConvertingMarkdownToText_shouldConvertManualAnchors {
// setup
GBApplicationSettingsProvider *settings = [GBApplicationSettingsProvider provider];
// execute
NSString *result1 = [settings stringByConvertingMarkdownToText:@"<a href=\"address\">desc</a>"];
NSString *result2 = [settings stringByConvertingMarkdownToText:@"<a href='address'>desc</a>"];
NSString *result3 = [settings stringByConvertingMarkdownToText:@"<a href=\"address\"></a>"];
NSString *result4 = [settings stringByConvertingMarkdownToText:@"<a href='address'></a>"];
NSString *result5 = [settings stringByConvertingMarkdownToText:@"<a href=\"address\" />"];
NSString *result6 = [settings stringByConvertingMarkdownToText:@"<a href='address' />"];
NSString *result7 = [settings stringByConvertingMarkdownToText:@"<a\n\n\thref\n=\n\t 'address'\n>desc</a>"];
NSString *result8 = [settings stringByConvertingMarkdownToText:@"<a\n\n\thref\n=\n\t 'address'\n/>"];
// verify
assertThat(result1, is(@"desc"));
assertThat(result2, is(@"desc"));
assertThat(result3, is(@"address"));
assertThat(result4, is(@"address"));
assertThat(result5, is(@"address"));
assertThat(result6, is(@"address"));
assertThat(result7, is(@"desc"));
assertThat(result8, is(@"address"));
}
#pragma mark Private accessor helpers
- (NSDateFormatter *)yearFormatterFromSettings:(GBApplicationSettingsProvider *)settings {
return [settings valueForKey:@"yearDateFormatter"];
}
- (NSDateFormatter *)yearToDayFormatterFromSettings:(GBApplicationSettingsProvider *)settings {
return [settings valueForKey:@"yearToDayDateFormatter"];
}
@end