/Testing/GBCommentsProcessor-RegistrationsTesting.m

https://github.com/SinnerSchraderMobileMirrors/appledoc · Objective C · 510 lines · 389 code · 45 blank · 76 comment · 8 complexity · d7a95ea7a2330edd30afeba34139c0b8 MD5 · raw file

  1. //
  2. // GBCommentsProcessor-RegistrationsTesting.m
  3. // appledoc
  4. //
  5. // Created by Tomaz Kragelj on 14.2.11.
  6. // Copyright (C) 2011 Gentle Bytes. All rights reserved.
  7. //
  8. #import "GBApplicationSettingsProvider.h"
  9. #import "GBDataObjects.h"
  10. #import "GBStore.h"
  11. #import "GBCommentsProcessor.h"
  12. @interface GBCommentsProcessor (PrivateAPI)
  13. - (BOOL)findCommentBlockInLines:(NSArray *)lines blockRange:(NSRange *)range shortRange:(NSRange *)shortRange;
  14. @end
  15. #pragma mark -
  16. @interface GBCommentsProcessorRegistrationsTesting : GBObjectsAssertor
  17. - (OCMockObject *)settingsProviderRepeatFirst:(BOOL)repeat;
  18. - (void)assertFindCommentWithString:(NSString *)string matchesBlockRange:(NSRange)b shortRange:(NSRange)s;
  19. @end
  20. #pragma mark -
  21. @implementation GBCommentsProcessorRegistrationsTesting
  22. #pragma mark Short & long descriptions testing
  23. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleTextOnlyBasedOnSettings {
  24. // setup
  25. GBStore *store = [GBTestObjectsRegistry store];
  26. GBCommentsProcessor *processor1 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:YES]];
  27. GBCommentsProcessor *processor2 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:NO]];
  28. GBComment *comment1 = [GBComment commentWithStringValue:@"Some text\n\nAnother paragraph"];
  29. GBComment *comment2 = [GBComment commentWithStringValue:comment1.stringValue];
  30. // execute
  31. [processor1 processComment:comment1 withContext:nil store:store];
  32. [processor2 processComment:comment2 withContext:nil store:store];
  33. // verify
  34. [self assertComment:comment1 matchesShortDesc:@"Some text" longDesc:@"Some text\n\nAnother paragraph", nil];
  35. [self assertComment:comment2 matchesShortDesc:@"Some text" longDesc:@"Another paragraph", nil];
  36. }
  37. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleAllTextAsLongDescBasedOnFlagsRegardlessOnSettingsAndContext {
  38. // setup
  39. GBStore *store = [GBTestObjectsRegistry store];
  40. GBCommentsProcessor *processor1 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:YES]];
  41. GBCommentsProcessor *processor2 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:NO]];
  42. GBComment *comment1 = [GBComment commentWithStringValue:@"Some text\n\nAnother paragraph"];
  43. GBComment *comment2 = [GBComment commentWithStringValue:comment1.stringValue];
  44. // execute
  45. processor1.alwaysRepeatFirstParagraph = YES;
  46. [processor1 processComment:comment1 withContext:nil store:store];
  47. processor2.alwaysRepeatFirstParagraph = YES;
  48. [processor2 processComment:comment2 withContext:nil store:store];
  49. // verify
  50. [self assertComment:comment1 matchesShortDesc:@"Some text" longDesc:@"Some text\n\nAnother paragraph", nil];
  51. [self assertComment:comment2 matchesShortDesc:@"Some text" longDesc:@"Some text\n\nAnother paragraph", nil];
  52. }
  53. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleTextBeforeDirectivesBasedOnSettings {
  54. // setup
  55. GBStore *store = [GBTestObjectsRegistry store];
  56. GBCommentsProcessor *processor1 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:YES]];
  57. GBCommentsProcessor *processor2 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:NO]];
  58. GBComment *comment1 = [GBComment commentWithStringValue:@"Some text\n\nAnother paragraph\n\n@warning Description"];
  59. GBComment *comment2 = [GBComment commentWithStringValue:comment1.stringValue];
  60. // execute
  61. [processor1 processComment:comment1 withContext:nil store:store];
  62. [processor2 processComment:comment2 withContext:nil store:store];
  63. // verify
  64. [self assertComment:comment1 matchesShortDesc:@"Some text" longDesc:@"Some text\n\nAnother paragraph", @"@warning Description", nil];
  65. [self assertComment:comment2 matchesShortDesc:@"Some text" longDesc:@"Another paragraph", @"@warning Description", nil];
  66. }
  67. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleTextAfterDescriptionDirectiveRegardlessOfSettings {
  68. // setup
  69. GBStore *store = [GBTestObjectsRegistry store];
  70. GBCommentsProcessor *processor1 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:YES]];
  71. GBCommentsProcessor *processor2 = [GBCommentsProcessor processorWithSettingsProvider:[self settingsProviderRepeatFirst:NO]];
  72. GBComment *comment1 = [GBComment commentWithStringValue:@"@warning Some text\n\nAnother paragraph"];
  73. GBComment *comment2 = [GBComment commentWithStringValue:comment1.stringValue];
  74. // execute
  75. [processor1 processComment:comment1 withContext:nil store:store];
  76. [processor2 processComment:comment2 withContext:nil store:store];
  77. // verify - all text after directive is considered part of that directive, but short text is still properly detected.
  78. [self assertComment:comment1 matchesShortDesc:@"Some text" longDesc:@"@warning Some text\n\nAnother paragraph", nil];
  79. [self assertComment:comment2 matchesShortDesc:@"Some text" longDesc:@"@warning Some text\n\nAnother paragraph", nil];
  80. }
  81. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleMultipleDescriptionDirectivesProperly {
  82. // setup
  83. GBStore *store = [GBTestObjectsRegistry store];
  84. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  85. GBComment *comment1 = [GBComment commentWithStringValue:@"@warning Paragraph 1.1\n\nParagraph 1.2\n\n@warning Paragraph 2.1\n\nParagraph 2.2"];
  86. GBComment *comment2 = [GBComment commentWithStringValue:@"@warning Warning\n\n@bug Bug"];
  87. GBComment *comment3 = [GBComment commentWithStringValue:@"@bug Bug\n\n@warning Warning"];
  88. // execute
  89. [processor processComment:comment1 withContext:nil store:store];
  90. [processor processComment:comment2 withContext:nil store:store];
  91. [processor processComment:comment3 withContext:nil store:store];
  92. // verify
  93. [self assertComment:comment1 matchesShortDesc:@"Paragraph 1.1" longDesc:@"@warning Paragraph 1.1\n\nParagraph 1.2", @"@warning Paragraph 2.1\n\nParagraph 2.2", nil];
  94. [self assertComment:comment2 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", @"@bug Bug", nil];
  95. [self assertComment:comment3 matchesShortDesc:@"Bug" longDesc:@"@bug Bug", @"@warning Warning", nil];
  96. }
  97. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleDescriptionForParamDirectiveRegardlessOfSettings {
  98. // setup
  99. GBStore *store = [GBTestObjectsRegistry store];
  100. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  101. GBComment *comment1 = [GBComment commentWithStringValue:@"@param name Description\n\nParagraph"];
  102. GBComment *comment2 = [GBComment commentWithStringValue:@"@param name Description\n\nParagraph\n\n@warning Warning"];
  103. GBComment *comment3 = [GBComment commentWithStringValue:@"@param name1 Description1\n@param name2 Description2"];
  104. GBComment *comment4 = [GBComment commentWithStringValue:@"Prefix\n\n@param name Description\n\nParagraph"];
  105. // execute
  106. [processor processComment:comment1 withContext:nil store:store];
  107. [processor processComment:comment2 withContext:nil store:store];
  108. [processor processComment:comment3 withContext:nil store:store];
  109. [processor processComment:comment4 withContext:nil store:store];
  110. // verify - we only use parameter description if there is nothing else found in the comment.
  111. [self assertComment:comment1 matchesShortDesc:@"Description" longDesc:nil];
  112. [self assertComment:comment2 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  113. [self assertComment:comment3 matchesShortDesc:@"Description1" longDesc:nil];
  114. [self assertComment:comment4 matchesShortDesc:@"Prefix" longDesc:@"Prefix", nil];
  115. }
  116. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleDescriptionForExceptionDirectiveRegardlessOfSettings {
  117. // setup
  118. GBStore *store = [GBTestObjectsRegistry store];
  119. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  120. GBComment *comment1 = [GBComment commentWithStringValue:@"@exception name Description\n\nParagraph"];
  121. GBComment *comment2 = [GBComment commentWithStringValue:@"@exception name Description\n\nParagraph\n\n@warning Warning"];
  122. GBComment *comment3 = [GBComment commentWithStringValue:@"@exception name Description1\n@exception name2 Description2"];
  123. GBComment *comment4 = [GBComment commentWithStringValue:@"Prefix\n\n@exception name Description\n\nParagraph"];
  124. // execute
  125. [processor processComment:comment1 withContext:nil store:store];
  126. [processor processComment:comment2 withContext:nil store:store];
  127. [processor processComment:comment3 withContext:nil store:store];
  128. [processor processComment:comment4 withContext:nil store:store];
  129. // verify - we only use parameter description if there is nothing else found in the comment.
  130. [self assertComment:comment1 matchesShortDesc:@"Description" longDesc:nil];
  131. [self assertComment:comment2 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  132. [self assertComment:comment3 matchesShortDesc:@"Description1" longDesc:nil];
  133. [self assertComment:comment4 matchesShortDesc:@"Prefix" longDesc:@"Prefix", nil];
  134. }
  135. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleDescriptionForReturnDirectiveRegardlessOfSettings {
  136. // setup
  137. GBStore *store = [GBTestObjectsRegistry store];
  138. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  139. GBComment *comment1 = [GBComment commentWithStringValue:@"@return Description\n\nParagraph"];
  140. GBComment *comment2 = [GBComment commentWithStringValue:@"@return Description\n\nParagraph\n\n@warning Warning"];
  141. GBComment *comment3 = [GBComment commentWithStringValue:@"Prefix\n\n@return Description\n\nParagraph"];
  142. // execute
  143. [processor processComment:comment1 withContext:nil store:store];
  144. [processor processComment:comment2 withContext:nil store:store];
  145. [processor processComment:comment3 withContext:nil store:store];
  146. // verify - we only use parameter description if there is nothing else found in the comment.
  147. [self assertComment:comment1 matchesShortDesc:@"Description" longDesc:nil];
  148. [self assertComment:comment2 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  149. [self assertComment:comment3 matchesShortDesc:@"Prefix" longDesc:@"Prefix", nil];
  150. }
  151. - (void)testProcessCommentWithContextStore_descriptions_shouldHandleRelatedSymbolsForReturnDirectiveRegardlessOfSettings {
  152. // setup
  153. GBStore *store = [GBTestObjectsRegistry store];
  154. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  155. GBComment *comment1 = [GBComment commentWithStringValue:@"@see Description\n\nParagraph"];
  156. GBComment *comment2 = [GBComment commentWithStringValue:@"@see Description\n\nParagraph\n\n@warning Warning"];
  157. GBComment *comment3 = [GBComment commentWithStringValue:@"Prefix\n\n@see Description\n\nParagraph"];
  158. // execute
  159. [processor processComment:comment1 withContext:nil store:store];
  160. [processor processComment:comment2 withContext:nil store:store];
  161. [processor processComment:comment3 withContext:nil store:store];
  162. // verify - we only use parameter description if there is nothing else found in the comment.
  163. [self assertComment:comment1 matchesShortDesc:@"Description" longDesc:nil];
  164. [self assertComment:comment2 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  165. [self assertComment:comment3 matchesShortDesc:@"Prefix" longDesc:@"Prefix", nil];
  166. }
  167. - (void)testProcessCommentWithContextStore_descriptions_shouldAssignSettingsToAllCommentComponents {
  168. // setup
  169. id settings = [GBTestObjectsRegistry realSettingsProvider];
  170. GBStore *store = [GBTestObjectsRegistry storeWithObjects:[GBClassData classDataWithName:@"Class"], nil];
  171. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:settings];
  172. GBComment *comment = [GBComment commentWithStringValue:
  173. @"Short\n\n"
  174. @"Long\n\n"
  175. @"@warning Warning\n\n"
  176. @"@bug Bug\n\n"
  177. @"@param name Desc\n"
  178. @"@exception name Desc\n"
  179. @"@return Desc"
  180. @"@see Class"
  181. @"@since Version 1.0"];
  182. // execute
  183. [processor processComment:comment withContext:nil store:store];
  184. // verify
  185. assertThat(comment.shortDescription.settings, is(settings));
  186. assertThat(comment.shortDescription.sourceInfo, isNot(nil));
  187. for (GBCommentComponent *c in comment.longDescription.components) {
  188. assertThat(c.settings, is(settings));
  189. assertThat(c.sourceInfo, isNot(nil));
  190. }
  191. for (GBCommentArgument *a in comment.methodParameters) {
  192. for (GBCommentComponent *c in a.argumentDescription.components) {
  193. assertThat(c.settings, is(settings));
  194. assertThat(c.sourceInfo, isNot(nil));
  195. }
  196. }
  197. for (GBCommentArgument *a in comment.methodExceptions) {
  198. for (GBCommentComponent *c in a.argumentDescription.components) {
  199. assertThat(c.settings, is(settings));
  200. assertThat(c.sourceInfo, isNot(nil));
  201. }
  202. }
  203. for (GBCommentComponent *c in comment.methodResult.components) {
  204. assertThat(c.settings, is(settings));
  205. assertThat(c.sourceInfo, isNot(nil));
  206. }
  207. for (GBCommentComponent *c in comment.relatedItems.components) {
  208. assertThat(c.settings, is(settings));
  209. assertThat(c.sourceInfo, isNot(nil));
  210. }
  211. for (GBCommentComponent *c in comment.availability.components) {
  212. assertThat(c.settings, is(settings));
  213. assertThat(c.sourceInfo, isNot(nil));
  214. }
  215. }
  216. #pragma mark Method data testing
  217. - (void)testProcessCommentWithContextStore_methods_shouldRegisterAllParametersDescriptionsProperly {
  218. // setup
  219. GBStore *store = [GBTestObjectsRegistry store];
  220. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  221. GBComment *comment = [GBComment commentWithStringValue:@"@param name1 Description1\nLine2\n\nParagraph2\n@param name2 Description2"];
  222. // execute
  223. [processor processComment:comment withContext:nil store:store];
  224. // verify - we only use parameter description if there is nothing else found in the comment.
  225. [self assertMethodArguments:comment.methodParameters matches:@"name1", @"Description1\nLine2\n\nParagraph2", GBEND, @"name2", @"Description2", GBEND, nil];
  226. }
  227. - (void)testProcessCommentWithContextStore_methods_shouldRegisterAllParametersRegardlessOfEmptyLinesGaps {
  228. // setup
  229. GBStore *store = [GBTestObjectsRegistry store];
  230. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  231. GBComment *comment1 = [GBComment commentWithStringValue:@"@param name1 Description1\n@param name2 Description2"];
  232. GBComment *comment2 = [GBComment commentWithStringValue:@"@param name1 Description1\n\n\n\n\n\n@param name2 Description2"];
  233. // execute
  234. [processor processComment:comment1 withContext:nil store:store];
  235. [processor processComment:comment2 withContext:nil store:store];
  236. // verify - we only use parameter description if there is nothing else found in the comment.
  237. [self assertMethodArguments:comment1.methodParameters matches:@"name1", @"Description1", GBEND, @"name2", @"Description2", GBEND, nil];
  238. [self assertMethodArguments:comment2.methodParameters matches:@"name1", @"Description1", GBEND, @"name2", @"Description2", GBEND, nil];
  239. }
  240. - (void)testProcessCommentWithContextStore_methods_shouldRegisterAllExceptionsRegardlessOfEmptyLinesGaps {
  241. // setup
  242. GBStore *store = [GBTestObjectsRegistry store];
  243. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  244. GBComment *comment1 = [GBComment commentWithStringValue:@"@exception name1 Description1\n@exception name2 Description2"];
  245. GBComment *comment2 = [GBComment commentWithStringValue:@"@exception name1 Description1\n\n\n\n\n\n@exception name2 Description2"];
  246. // execute
  247. [processor processComment:comment1 withContext:nil store:store];
  248. [processor processComment:comment2 withContext:nil store:store];
  249. // verify - we only use parameter description if there is nothing else found in the comment.
  250. [self assertMethodArguments:comment1.methodExceptions matches:@"name1", @"Description1", GBEND, @"name2", @"Description2", GBEND, nil];
  251. [self assertMethodArguments:comment2.methodExceptions matches:@"name1", @"Description1", GBEND, @"name2", @"Description2", GBEND, nil];
  252. }
  253. - (void)testProcessCommentWithContextStore_methods_shouldRegisterResultDescriptionProperly {
  254. // setup
  255. GBStore *store = [GBTestObjectsRegistry store];
  256. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  257. GBComment *comment1 = [GBComment commentWithStringValue:@"@return Description"];
  258. GBComment *comment2 = [GBComment commentWithStringValue:@"@return Description1\nLine2\n\nParagraph2"];
  259. // execute
  260. [processor processComment:comment1 withContext:nil store:store];
  261. [processor processComment:comment2 withContext:nil store:store];
  262. // verify - we only use parameter description if there is nothing else found in the comment.
  263. [self assertCommentComponents:comment1.methodResult matchesStringValues:@"Description", nil];
  264. [self assertCommentComponents:comment2.methodResult matchesStringValues:@"Description1\nLine2\n\nParagraph2", nil];
  265. }
  266. - (void)testProcessCommentWithContextStore_methods_shouldRegisterAvailabilityDescriptionProperly {
  267. // setup
  268. GBStore *store = [GBTestObjectsRegistry store];
  269. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  270. GBComment *comment1 = [GBComment commentWithStringValue:@"@since Description"];
  271. GBComment *comment2 = [GBComment commentWithStringValue:@"@available Description1\nLine2\n\nParagraph2"];
  272. // execute
  273. [processor processComment:comment1 withContext:nil store:store];
  274. [processor processComment:comment2 withContext:nil store:store];
  275. // verify - we only use parameter description if there is nothing else found in the comment.
  276. [self assertCommentComponents:comment1.availability matchesStringValues:@"Description", nil];
  277. [self assertCommentComponents:comment2.availability matchesStringValues:@"Description1\nLine2\n\nParagraph2", nil];
  278. }
  279. #pragma mark Common directives testing
  280. - (void)testProcessCommentWithContextStore_directives_shouldRegisterRelatedItemsForKnownTopLevelObjects {
  281. // setup
  282. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  283. GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
  284. GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
  285. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, category, protocol, nil];
  286. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  287. GBComment *comment1 = [GBComment commentWithStringValue:@"@see Class"];
  288. GBComment *comment2 = [GBComment commentWithStringValue:@"@see Class(Category)"];
  289. GBComment *comment3 = [GBComment commentWithStringValue:@"@see Protocol"];
  290. GBComment *comment4 = [GBComment commentWithStringValue:@"@see Unknown"];
  291. // execute
  292. [processor processComment:comment1 withContext:nil store:store];
  293. [processor processComment:comment2 withContext:nil store:store];
  294. [processor processComment:comment3 withContext:nil store:store];
  295. [processor processComment:comment4 withContext:nil store:store];
  296. // verify - we only use parameter description if there is nothing else found in the comment.
  297. [self assertCommentComponents:comment1.relatedItems matchesStringValues:@"Class", nil];
  298. [self assertCommentComponents:comment2.relatedItems matchesStringValues:@"Class(Category)", nil];
  299. [self assertCommentComponents:comment3.relatedItems matchesStringValues:@"Protocol", nil];
  300. [self assertCommentComponents:comment4.relatedItems matchesStringValues:nil];
  301. }
  302. - (void)testProcessCommentWithContextStore_directives_shouldRegisterRelatedItemsForKnownDocuments {
  303. // setup
  304. GBDocumentData *document1 = [GBDocumentData documentDataWithContents:@"c" path:@"Document1.html"];
  305. GBDocumentData *document2 = [GBDocumentData documentDataWithContents:@"c" path:@"Document2.html"];
  306. GBStore *store = [GBTestObjectsRegistry storeWithObjects:document1, document2, nil];
  307. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  308. GBComment *comment1 = [GBComment commentWithStringValue:@"@see Document1"];
  309. GBComment *comment2 = [GBComment commentWithStringValue:@"@see Document2"];
  310. GBComment *comment3 = [GBComment commentWithStringValue:@"@see Unknown"];
  311. // execute
  312. [processor processComment:comment1 withContext:nil store:store];
  313. [processor processComment:comment2 withContext:nil store:store];
  314. [processor processComment:comment3 withContext:nil store:store];
  315. // verify - we only use parameter description if there is nothing else found in the comment.
  316. [self assertCommentComponents:comment1.relatedItems matchesStringValues:@"Document1", nil];
  317. [self assertCommentComponents:comment2.relatedItems matchesStringValues:@"Document2", nil];
  318. [self assertCommentComponents:comment3.relatedItems matchesStringValues:nil];
  319. }
  320. - (void)testProcessCommentWithContextStore_directives_shouldRegisterRelatedItemsForKnownLocalMembers {
  321. // setup
  322. GBClassData *class = [GBTestObjectsRegistry classWithName:@"Class" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  323. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  324. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  325. GBComment *comment1 = [GBComment commentWithStringValue:@"@see method:"];
  326. GBComment *comment2 = [GBComment commentWithStringValue:@"@see unknown:"];
  327. // execute
  328. [processor processComment:comment1 withContext:class store:store];
  329. [processor processComment:comment2 withContext:class store:store];
  330. // verify - we only use parameter description if there is nothing else found in the comment.
  331. [self assertCommentComponents:comment1.relatedItems matchesStringValues:@"method:", nil];
  332. [self assertCommentComponents:comment2.relatedItems matchesStringValues:nil];
  333. }
  334. - (void)testProcessCommentWithContextStore_directives_shouldRegisterRelatedItemsForKnownRemoteMembers {
  335. // setup
  336. GBClassData *class = [GBTestObjectsRegistry classWithName:@"Class" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  337. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  338. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  339. GBComment *comment1 = [GBComment commentWithStringValue:@"@see [Class method:]"];
  340. GBComment *comment2 = [GBComment commentWithStringValue:@"@see [Class unknown:]"];
  341. GBComment *comment3 = [GBComment commentWithStringValue:@"@see [Unknown method:]"];
  342. // execute
  343. [processor processComment:comment1 withContext:nil store:store];
  344. [processor processComment:comment2 withContext:nil store:store];
  345. [processor processComment:comment3 withContext:nil store:store];
  346. // verify - we only use parameter description if there is nothing else found in the comment.
  347. [self assertCommentComponents:comment1.relatedItems matchesStringValues:@"[Class method:]", nil];
  348. [self assertCommentComponents:comment2.relatedItems matchesStringValues:nil];
  349. [self assertCommentComponents:comment3.relatedItems matchesStringValues:nil];
  350. }
  351. #pragma mark Combinations testing
  352. - (void)testProcessCommentWithContextStore_combinations_shouldRegisterMethodDescriptionBlock {
  353. // setup
  354. GBStore *store = [GBTestObjectsRegistry store];
  355. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  356. GBComment *comment = [GBComment commentWithStringValue:
  357. @"@param name1 Description1\nLine2\n\nParagraph2\n"
  358. @"@exception exc Exception\n"
  359. @"@param name2 Description2\n"
  360. @"@return Return\n"
  361. @"@param name3 Description3\n"
  362. @"@since Version 1.0\n"];
  363. // execute
  364. [processor processComment:comment withContext:nil store:store];
  365. // verify - we only use parameter description if there is nothing else found in the comment.
  366. [self assertMethodArguments:comment.methodParameters matches:
  367. @"name1", @"Description1\nLine2\n\nParagraph2", GBEND,
  368. @"name2", @"Description2", GBEND,
  369. @"name3", @"Description3", GBEND, nil];
  370. [self assertMethodArguments:comment.methodExceptions matches:@"exc", @"Exception", GBEND, nil];
  371. [self assertCommentComponents:comment.methodResult matchesStringValues:@"Return", nil];
  372. [self assertCommentComponents:comment.availability matchesStringValues:@"Version 1.0", nil];
  373. }
  374. - (void)testProcessCommentWithContextStore_combinations_shouldRegisterWarningAfterMethodBlockAsMainDescription {
  375. // setup
  376. GBStore *store = [GBTestObjectsRegistry store];
  377. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  378. GBComment *comment1 = [GBComment commentWithStringValue:@"@param name Description\n@warning Warning"];
  379. GBComment *comment2 = [GBComment commentWithStringValue:@"@exception name Description\n@warning Warning"];
  380. GBComment *comment3 = [GBComment commentWithStringValue:@"@return Description\n@warning Warning"];
  381. GBComment *comment4 = [GBComment commentWithStringValue:@"@since Description\n@warning Warning"];
  382. // execute
  383. [processor processComment:comment1 withContext:nil store:store];
  384. [processor processComment:comment2 withContext:nil store:store];
  385. [processor processComment:comment3 withContext:nil store:store];
  386. [processor processComment:comment4 withContext:nil store:store];
  387. // verify - we only use parameter description if there is nothing else found in the comment.
  388. [self assertMethodArguments:comment1.methodParameters matches:@"name", @"Description", GBEND, nil];
  389. [self assertMethodArguments:comment2.methodExceptions matches:@"name", @"Description", GBEND, nil];
  390. [self assertCommentComponents:comment3.methodResult matchesStringValues:@"Description", nil];
  391. [self assertCommentComponents:comment4.availability matchesStringValues:@"Description", nil];
  392. [self assertComment:comment1 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  393. [self assertComment:comment2 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  394. [self assertComment:comment3 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  395. [self assertComment:comment4 matchesShortDesc:@"Warning" longDesc:@"@warning Warning", nil];
  396. }
  397. #pragma mark Miscellaneous handling
  398. - (void)testProcessCommentWithContextStore_misc_shouldSetIsProcessed {
  399. // setup
  400. GBStore *store = [GBTestObjectsRegistry store];
  401. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  402. GBComment *comment = [GBComment commentWithStringValue:@""];
  403. // execute
  404. [processor processComment:comment withContext:nil store:store];
  405. // verify
  406. assertThatBool(comment.isProcessed, equalToBool(YES));
  407. }
  408. #pragma mark Private methods testing
  409. - (void)testFindCommentBlockInLinesBlockRangeShortRange_shouldDetectSingleComponent {
  410. [self assertFindCommentWithString:@"line" matchesBlockRange:NSMakeRange(0, 1) shortRange:NSMakeRange(0, 1)];
  411. [self assertFindCommentWithString:@"line1\nline2" matchesBlockRange:NSMakeRange(0, 2) shortRange:NSMakeRange(0, 2)];
  412. [self assertFindCommentWithString:@"para1\n\npara" matchesBlockRange:NSMakeRange(0, 3) shortRange:NSMakeRange(0, 1)];
  413. [self assertFindCommentWithString:@"para1\n\npara2\n\npara3" matchesBlockRange:NSMakeRange(0, 5) shortRange:NSMakeRange(0, 1)];
  414. }
  415. - (void)testFindCommentBlockInLinesBlockRangeShortRange_shouldDetectSingleComponentUpToDirective {
  416. [self assertFindCommentWithString:@"line\n@warning desc" matchesBlockRange:NSMakeRange(0, 1) shortRange:NSMakeRange(0, 1)];
  417. [self assertFindCommentWithString:@"line\n\n@warning desc" matchesBlockRange:NSMakeRange(0, 2) shortRange:NSMakeRange(0, 1)];
  418. [self assertFindCommentWithString:@"para1\n\npara2\n@warning desc" matchesBlockRange:NSMakeRange(0, 3) shortRange:NSMakeRange(0, 1)];
  419. [self assertFindCommentWithString:@"para1\n\npara2\n\n@warning desc" matchesBlockRange:NSMakeRange(0, 4) shortRange:NSMakeRange(0, 1)];
  420. }
  421. - (void)testFindCommentBlockInLinesBlockRangeShortRange_shouldDetectDirectiveComponentUpToEndOfLines {
  422. [self assertFindCommentWithString:@"@warning desc" matchesBlockRange:NSMakeRange(0, 1) shortRange:NSMakeRange(0, 1)];
  423. [self assertFindCommentWithString:@"@warning line1\nline2" matchesBlockRange:NSMakeRange(0, 2) shortRange:NSMakeRange(0, 2)];
  424. [self assertFindCommentWithString:@"@warning para1\n\npara2" matchesBlockRange:NSMakeRange(0, 3) shortRange:NSMakeRange(0, 1)];
  425. }
  426. - (void)testFindCommentBlockInLinesBlockRangeShortRange_shouldDetectDirectiveComponentUpToNextDirective {
  427. [self assertFindCommentWithString:@"@warning desc\n@warning next" matchesBlockRange:NSMakeRange(0, 1) shortRange:NSMakeRange(0, 1)];
  428. [self assertFindCommentWithString:@"@warning desc\n\n@warning next" matchesBlockRange:NSMakeRange(0, 2) shortRange:NSMakeRange(0, 1)];
  429. [self assertFindCommentWithString:@"@warning line1\nline2\n@warning next" matchesBlockRange:NSMakeRange(0, 2) shortRange:NSMakeRange(0, 2)];
  430. [self assertFindCommentWithString:@"@warning line1\nline2\n\n@warning next" matchesBlockRange:NSMakeRange(0, 3) shortRange:NSMakeRange(0, 2)];
  431. [self assertFindCommentWithString:@"@warning para1\n\npara2\n@warning next" matchesBlockRange:NSMakeRange(0, 3) shortRange:NSMakeRange(0, 1)];
  432. [self assertFindCommentWithString:@"@warning para1\n\npara2\n\n@warning next" matchesBlockRange:NSMakeRange(0, 4) shortRange:NSMakeRange(0, 1)];
  433. }
  434. - (void)testFindCommentBlockInLinesBlockRangeShortRange_shouldStopAtAnyDirective {
  435. NSRange blockRange = NSMakeRange(0, 1);
  436. NSRange shortRange = NSMakeRange(0, 1);
  437. [self assertFindCommentWithString:@"line\n@warning desc" matchesBlockRange:blockRange shortRange:shortRange];
  438. [self assertFindCommentWithString:@"line\n@bug desc" matchesBlockRange:blockRange shortRange:shortRange];
  439. [self assertFindCommentWithString:@"line\n@param name desc" matchesBlockRange:blockRange shortRange:shortRange];
  440. [self assertFindCommentWithString:@"line\n@return desc" matchesBlockRange:blockRange shortRange:shortRange];
  441. [self assertFindCommentWithString:@"line\n@returns desc" matchesBlockRange:blockRange shortRange:shortRange];
  442. [self assertFindCommentWithString:@"line\n@exception name desc" matchesBlockRange:blockRange shortRange:shortRange];
  443. [self assertFindCommentWithString:@"line\n@see desc" matchesBlockRange:blockRange shortRange:shortRange];
  444. [self assertFindCommentWithString:@"line\n@sa desc" matchesBlockRange:blockRange shortRange:shortRange];
  445. }
  446. #pragma Creation & assertion methods
  447. - (OCMockObject *)settingsProviderRepeatFirst:(BOOL)repeat {
  448. OCMockObject *result = [GBTestObjectsRegistry mockSettingsProvider];
  449. [[[result stub] andReturnValue:[NSNumber numberWithBool:repeat]] repeatFirstParagraphForMemberDescription];
  450. return result;
  451. }
  452. - (void)assertFindCommentWithString:(NSString *)string matchesBlockRange:(NSRange)b shortRange:(NSRange)s {
  453. // setup
  454. GBCommentsProcessor *processor = [GBCommentsProcessor processorWithSettingsProvider:[GBTestObjectsRegistry realSettingsProvider]];
  455. // execute
  456. NSRange blockRange = NSMakeRange(0, 0);
  457. NSRange shortRange = NSMakeRange(0, 0);
  458. [processor findCommentBlockInLines:[string arrayOfLines] blockRange:&blockRange shortRange:&shortRange];
  459. // verify
  460. assertThatInteger(blockRange.location, equalToInteger(b.location));
  461. assertThatInteger(blockRange.length, equalToInteger(b.length));
  462. assertThatInteger(shortRange.location, equalToInteger(s.location));
  463. assertThatInteger(shortRange.length, equalToInteger(s.length));
  464. }
  465. @end