/Testing/GBCommentsProcessor-PreprocessingTesting.m

https://github.com/SinnerSchraderMobileMirrors/appledoc · Objective C · 631 lines · 468 code · 54 blank · 109 comment · 0 complexity · 39758e267e6acdcc03d9090fe6571c2f MD5 · raw file

  1. //
  2. // GBCommentsProcessor-PreprocessingTesting.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. - (NSString *)stringByPreprocessingString:(NSString *)string withFlags:(NSUInteger)flags;
  14. - (NSString *)stringByConvertingCrossReferencesInString:(NSString *)string withFlags:(NSUInteger)flags;
  15. @end
  16. #pragma mark -
  17. @interface GBCommentsProcessorPreprocessingTesting : GBObjectsAssertor
  18. - (GBCommentsProcessor *)defaultProcessor;
  19. - (GBCommentsProcessor *)processorWithStore:(id)store;
  20. - (GBCommentsProcessor *)processorWithStore:(id)store context:(id)context;
  21. @end
  22. #pragma mark -
  23. @implementation GBCommentsProcessorPreprocessingTesting
  24. #pragma mark Formatting markers conversion
  25. - (void)testStringByPreprocessingString_shouldConvertAppledocBoldMarkersToTemporarySyntax {
  26. // setup
  27. GBCommentsProcessor *processor = [self defaultProcessor];
  28. // execute
  29. NSString *result1 = [processor stringByPreprocessingString:@"*bold1* *bold text* * bolder text *" withFlags:0];
  30. NSString *result2 = [processor stringByPreprocessingString:@"*bold1* Middle *bold text*" withFlags:0];
  31. // verify
  32. assertThat(result1, is(@"**~!#bold1#!~** **~!#bold text#!~** **~!# bolder text #!~**"));
  33. assertThat(result2, is(@"**~!#bold1#!~** Middle **~!#bold text#!~**"));
  34. }
  35. - (void)testStringByPreprocessingString_shouldLeaveItalicsMarkers {
  36. // setup
  37. GBCommentsProcessor *processor = [self defaultProcessor];
  38. // execute
  39. NSString *result1 = [processor stringByPreprocessingString:@"_bold1_ _bold text_ _ bolder text _" withFlags:0];
  40. NSString *result2 = [processor stringByPreprocessingString:@"_bold1_ Middle _bold text_" withFlags:0];
  41. // verify
  42. assertThat(result1, is(@"_bold1_ _bold text_ _ bolder text _"));
  43. assertThat(result2, is(@"_bold1_ Middle _bold text_"));
  44. }
  45. - (void)testStringByPreprocessingString_shouldLeaveBoldItalicsMarkers {
  46. // setup
  47. GBCommentsProcessor *processor = [self defaultProcessor];
  48. // execute
  49. NSString *result = [processor stringByPreprocessingString:@"_*text1*_ *_marked text_* _* text2 *_" withFlags:0];
  50. // verify
  51. assertThat(result, is(@"_*text1*_ *_marked text_* _* text2 *_"));
  52. }
  53. - (void)testStringByPreprocessingString_shouldHandleMonospaceMarkers {
  54. // setup
  55. GBCommentsProcessor *processor = [self defaultProcessor];
  56. // execute
  57. NSString *result = [processor stringByPreprocessingString:@"`mono` ` monoer `" withFlags:0];
  58. // verify
  59. assertThat(result, is(@"`mono` ` monoer `"));
  60. }
  61. - (void)testStringByPreprocessingString_shouldHandleMarkdownBoldMarkers {
  62. // setup
  63. GBCommentsProcessor *processor = [self defaultProcessor];
  64. // execute
  65. NSString *result1 = [processor stringByPreprocessingString:@"__text1__ __ marked __" withFlags:0];
  66. NSString *result2 = [processor stringByPreprocessingString:@"**text1** ** marked **" withFlags:0];
  67. // verify
  68. assertThat(result1, is(@"__text1__ __ marked __"));
  69. assertThat(result2, is(@"**text1** ** marked **"));
  70. }
  71. - (void)testStringByPreprocessingString_shouldLeaveMarkdownBoldItalicsMarkers {
  72. // setup
  73. GBCommentsProcessor *processor = [self defaultProcessor];
  74. // execute
  75. NSString *result1 = [processor stringByPreprocessingString:@"__*text1*__ __* marked *__" withFlags:0];
  76. NSString *result2 = [processor stringByPreprocessingString:@"_**text1**_ _** marked **_" withFlags:0];
  77. NSString *result3 = [processor stringByPreprocessingString:@"*__text1__* *__ marked __*" withFlags:0];
  78. NSString *result4 = [processor stringByPreprocessingString:@"**_text1_** **_ marked _**" withFlags:0];
  79. NSString *result5 = [processor stringByPreprocessingString:@"___text1___ ___ marked ___" withFlags:0];
  80. NSString *result6 = [processor stringByPreprocessingString:@"***text1*** *** marked ***" withFlags:0];
  81. // verify
  82. assertThat(result1, is(@"__*text1*__ __* marked *__"));
  83. assertThat(result2, is(@"_**text1**_ _** marked **_"));
  84. assertThat(result3, is(@"*__text1__* *__ marked __*"));
  85. assertThat(result4, is(@"**_text1_** **_ marked _**"));
  86. assertThat(result5, is(@"___text1___ ___ marked ___"));
  87. assertThat(result6, is(@"***text1*** *** marked ***"));
  88. }
  89. #pragma mark Class, category and protocol cross references detection
  90. - (void)testStringByConvertingCrossReferencesInString_shouldConvertClass {
  91. // setup
  92. GBStore *store = [GBTestObjectsRegistry storeWithObjects:[GBClassData classDataWithName:@"Class"], nil];
  93. GBCommentsProcessor *processor = [self processorWithStore:store];
  94. // execute
  95. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Class" withFlags:0];
  96. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<Class>" withFlags:0];
  97. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"Unknown" withFlags:0];
  98. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<Unknown>" withFlags:0];
  99. // verify
  100. assertThat(result1, is(@"[Class](Classes/Class.html)"));
  101. assertThat(result2, is(@"[Class](Classes/Class.html)"));
  102. assertThat(result3, is(@"Unknown"));
  103. assertThat(result4, is(@"<Unknown>"));
  104. }
  105. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategory {
  106. // setup
  107. GBStore *store = [GBTestObjectsRegistry storeWithObjects:[GBCategoryData categoryDataWithName:@"Category" className:@"Class"], nil];
  108. GBCommentsProcessor *processor = [self processorWithStore:store];
  109. // execute
  110. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Class(Category)" withFlags:0];
  111. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<Class(Category)>" withFlags:0];
  112. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"Class(Unknown)" withFlags:0];
  113. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<Class(Unknown)>" withFlags:0];
  114. // verify
  115. assertThat(result1, is(@"[Class(Category)](Categories/Class(Category).html)"));
  116. assertThat(result2, is(@"[Class(Category)](Categories/Class(Category).html)"));
  117. assertThat(result3, is(@"Class(Unknown)"));
  118. assertThat(result4, is(@"<Class(Unknown)>"));
  119. }
  120. - (void)testStringByConvertingCrossReferencesInString_shouldConvertProtocol {
  121. // setup
  122. GBStore *store = [GBTestObjectsRegistry storeWithObjects:[GBProtocolData protocolDataWithName:@"Protocol"], nil];
  123. GBCommentsProcessor *processor = [self processorWithStore:store];
  124. // execute
  125. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Protocol" withFlags:0];
  126. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<Protocol>" withFlags:0];
  127. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"Unknown" withFlags:0];
  128. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<Unknown>" withFlags:0];
  129. // verify
  130. assertThat(result1, is(@"[Protocol](Protocols/Protocol.html)"));
  131. assertThat(result2, is(@"[Protocol](Protocols/Protocol.html)"));
  132. assertThat(result3, is(@"Unknown"));
  133. assertThat(result4, is(@"<Unknown>"));
  134. }
  135. #pragma mark Local members cross references detection
  136. - (void)testStringByConvertingCrossReferencesInString_shouldConvertClassLocalInstanceMethod {
  137. // setup
  138. GBClassData *class = [GBTestObjectsRegistry classWithName:@"Class" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  139. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  140. GBCommentsProcessor *processor = [self processorWithStore:store context:class];
  141. // execute
  142. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"method:" withFlags:0];
  143. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<method:>" withFlags:0];
  144. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"-method:" withFlags:0];
  145. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<-method:>" withFlags:0];
  146. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"another:" withFlags:0];
  147. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"<another:>" withFlags:0];
  148. // verify
  149. assertThat(result1, is(@"[method:](#//api/name/method:)"));
  150. assertThat(result2, is(@"[method:](#//api/name/method:)"));
  151. assertThat(result3, is(@"[method:](#//api/name/method:)"));
  152. assertThat(result4, is(@"[method:](#//api/name/method:)"));
  153. assertThat(result5, is(@"another:"));
  154. assertThat(result6, is(@"<another:>"));
  155. }
  156. - (void)testStringByConvertingCrossReferencesInString_shouldConvertClassLocalClassMethod {
  157. // setup
  158. GBClassData *class = [GBTestObjectsRegistry classWithName:@"Class" methods:[GBTestObjectsRegistry classMethodWithNames:@"method", nil], nil];
  159. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  160. GBCommentsProcessor *processor = [self processorWithStore:store context:class];
  161. // execute
  162. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"method:" withFlags:0];
  163. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<method:>" withFlags:0];
  164. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"+method:" withFlags:0];
  165. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<+method:>" withFlags:0];
  166. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"another:" withFlags:0];
  167. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"<another:>" withFlags:0];
  168. // verify
  169. assertThat(result1, is(@"[method:](#//api/name/method:)"));
  170. assertThat(result2, is(@"[method:](#//api/name/method:)"));
  171. assertThat(result3, is(@"[method:](#//api/name/method:)"));
  172. assertThat(result4, is(@"[method:](#//api/name/method:)"));
  173. assertThat(result5, is(@"another:"));
  174. assertThat(result6, is(@"<another:>"));
  175. }
  176. - (void)testStringByConvertingCrossReferencesInString_shouldConvertClassLocalProperty {
  177. // setup
  178. GBClassData *class = [GBTestObjectsRegistry classWithName:@"Class" methods:[GBTestObjectsRegistry propertyMethodWithArgument:@"method"], nil];
  179. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  180. GBCommentsProcessor *processor = [self processorWithStore:store context:class];
  181. // execute
  182. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"method" withFlags:0];
  183. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<method>" withFlags:0];
  184. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"method:" withFlags:0];
  185. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<method:>" withFlags:0];
  186. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"another" withFlags:0];
  187. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"<another>" withFlags:0];
  188. // verify
  189. assertThat(result1, is(@"[method](#//api/name/method)"));
  190. assertThat(result2, is(@"[method](#//api/name/method)"));
  191. assertThat(result3, is(@"method:"));
  192. assertThat(result4, is(@"<method:>"));
  193. assertThat(result5, is(@"another"));
  194. assertThat(result6, is(@"<another>"));
  195. }
  196. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategoryAndProtocolLocalInstanceMethod {
  197. // setup
  198. id method1 = [GBTestObjectsRegistry instanceMethodWithNames:@"method1", nil];
  199. id method2 = [GBTestObjectsRegistry instanceMethodWithNames:@"method2", nil];
  200. GBCategoryData *category = [GBTestObjectsRegistry categoryWithName:@"Category" className:@"Class" methods:method1, nil];
  201. GBProtocolData *protocol = [GBTestObjectsRegistry protocolWithName:@"Protocol" methods:method2, nil];
  202. GBStore *store = [GBTestObjectsRegistry storeWithObjects:category, protocol, nil];
  203. GBCommentsProcessor *processor1 = [self processorWithStore:store context:category];
  204. GBCommentsProcessor *processor2 = [self processorWithStore:store context:protocol];
  205. // execute
  206. NSString *result1 = [processor1 stringByConvertingCrossReferencesInString:@"method1:" withFlags:0];
  207. NSString *result2 = [processor1 stringByConvertingCrossReferencesInString:@"<method1:>" withFlags:0];
  208. NSString *result3 = [processor1 stringByConvertingCrossReferencesInString:@"method2:" withFlags:0];
  209. NSString *result4 = [processor2 stringByConvertingCrossReferencesInString:@"method2:" withFlags:0];
  210. NSString *result5 = [processor2 stringByConvertingCrossReferencesInString:@"<method2:>" withFlags:0];
  211. NSString *result6 = [processor2 stringByConvertingCrossReferencesInString:@"method1:" withFlags:0];
  212. // verify
  213. assertThat(result1, is(@"[method1:](#//api/name/method1:)"));
  214. assertThat(result2, is(@"[method1:](#//api/name/method1:)"));
  215. assertThat(result3, is(@"method2:"));
  216. assertThat(result4, is(@"[method2:](#//api/name/method2:)"));
  217. assertThat(result5, is(@"[method2:](#//api/name/method2:)"));
  218. assertThat(result6, is(@"method1:"));
  219. }
  220. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategoryAndProtocolLocalClassMethod {
  221. // setup
  222. id method1 = [GBTestObjectsRegistry classMethodWithNames:@"method1", nil];
  223. id method2 = [GBTestObjectsRegistry classMethodWithNames:@"method2", nil];
  224. GBCategoryData *category = [GBTestObjectsRegistry categoryWithName:@"Category" className:@"Class" methods:method1, nil];
  225. GBProtocolData *protocol = [GBTestObjectsRegistry protocolWithName:@"Protocol" methods:method2, nil];
  226. GBStore *store = [GBTestObjectsRegistry storeWithObjects:category, protocol, nil];
  227. GBCommentsProcessor *processor1 = [self processorWithStore:store context:category];
  228. GBCommentsProcessor *processor2 = [self processorWithStore:store context:protocol];
  229. // execute
  230. NSString *result1 = [processor1 stringByConvertingCrossReferencesInString:@"method1:" withFlags:0];
  231. NSString *result2 = [processor1 stringByConvertingCrossReferencesInString:@"<method1:>" withFlags:0];
  232. NSString *result3 = [processor1 stringByConvertingCrossReferencesInString:@"method2:" withFlags:0];
  233. NSString *result4 = [processor2 stringByConvertingCrossReferencesInString:@"method2:" withFlags:0];
  234. NSString *result5 = [processor2 stringByConvertingCrossReferencesInString:@"<method2:>" withFlags:0];
  235. NSString *result6 = [processor2 stringByConvertingCrossReferencesInString:@"method1:" withFlags:0];
  236. // verify
  237. assertThat(result1, is(@"[method1:](#//api/name/method1:)"));
  238. assertThat(result2, is(@"[method1:](#//api/name/method1:)"));
  239. assertThat(result3, is(@"method2:"));
  240. assertThat(result4, is(@"[method2:](#//api/name/method2:)"));
  241. assertThat(result5, is(@"[method2:](#//api/name/method2:)"));
  242. assertThat(result6, is(@"method1:"));
  243. }
  244. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategoryAndProtocolLocalProperty {
  245. // setup
  246. id method1 = [GBTestObjectsRegistry propertyMethodWithArgument:@"method1"];
  247. id method2 = [GBTestObjectsRegistry propertyMethodWithArgument:@"method2"];
  248. GBCategoryData *category = [GBTestObjectsRegistry categoryWithName:@"Category" className:@"Class" methods:method1, nil];
  249. GBProtocolData *protocol = [GBTestObjectsRegistry protocolWithName:@"Protocol" methods:method2, nil];
  250. GBStore *store = [GBTestObjectsRegistry storeWithObjects:category, protocol, nil];
  251. GBCommentsProcessor *processor1 = [self processorWithStore:store context:category];
  252. GBCommentsProcessor *processor2 = [self processorWithStore:store context:protocol];
  253. // execute
  254. NSString *result1 = [processor1 stringByConvertingCrossReferencesInString:@"method1" withFlags:0];
  255. NSString *result2 = [processor1 stringByConvertingCrossReferencesInString:@"<method1>" withFlags:0];
  256. NSString *result3 = [processor1 stringByConvertingCrossReferencesInString:@"method2" withFlags:0];
  257. NSString *result4 = [processor2 stringByConvertingCrossReferencesInString:@"method2" withFlags:0];
  258. NSString *result5 = [processor2 stringByConvertingCrossReferencesInString:@"<method2>" withFlags:0];
  259. NSString *result6 = [processor2 stringByConvertingCrossReferencesInString:@"method1" withFlags:0];
  260. // verify
  261. assertThat(result1, is(@"[method1](#//api/name/method1)"));
  262. assertThat(result2, is(@"[method1](#//api/name/method1)"));
  263. assertThat(result3, is(@"method2"));
  264. assertThat(result4, is(@"[method2](#//api/name/method2)"));
  265. assertThat(result5, is(@"[method2](#//api/name/method2)"));
  266. assertThat(result6, is(@"method1"));
  267. }
  268. #pragma mark Remote members cross references detection
  269. - (void)testStringByConvertingCrossReferencesInString_shouldConvertClassRemoteInstanceMethod {
  270. // setup
  271. GBClassData *class1 = [GBTestObjectsRegistry classWithName:@"Class1" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  272. GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
  273. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class1, class2, nil];
  274. GBCommentsProcessor *processor = [self processorWithStore:store context:class2];
  275. // execute
  276. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[Class1 method:]" withFlags:0];
  277. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<[Class1 method:]>" withFlags:0];
  278. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"-[Class1 method:]" withFlags:0];
  279. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<-[Class1 method:]>" withFlags:0];
  280. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"[Unknown method:]" withFlags:0];
  281. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"method:" withFlags:0];
  282. // verify
  283. assertThat(result1, is(@"[[Class1 method:]](../Classes/Class1.html#//api/name/method:)"));
  284. assertThat(result2, is(@"[[Class1 method:]](../Classes/Class1.html#//api/name/method:)"));
  285. assertThat(result3, is(@"[[Class1 method:]](../Classes/Class1.html#//api/name/method:)"));
  286. assertThat(result4, is(@"[[Class1 method:]](../Classes/Class1.html#//api/name/method:)"));
  287. assertThat(result5, is(@"[Unknown method:]"));
  288. assertThat(result6, is(@"method:"));
  289. }
  290. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategoryRemoteInstanceMethod {
  291. // setup
  292. GBCategoryData *category = [GBTestObjectsRegistry categoryWithName:@"Category" className:@"Class" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  293. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  294. GBStore *store = [GBTestObjectsRegistry storeWithObjects:category, class, nil];
  295. GBCommentsProcessor *processor = [self processorWithStore:store context:class];
  296. // execute
  297. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[Class(Category) method:]" withFlags:0];
  298. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<[Class(Category) method:]>" withFlags:0];
  299. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"-[Class(Category) method:]" withFlags:0];
  300. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<-[Class(Category) method:]>" withFlags:0];
  301. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"[Class(Unknown) method:]" withFlags:0];
  302. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"[Unknown(Category) method:]" withFlags:0];
  303. // verify
  304. assertThat(result1, is(@"[[Class(Category) method:]](../Categories/Class(Category).html#//api/name/method:)"));
  305. assertThat(result2, is(@"[[Class(Category) method:]](../Categories/Class(Category).html#//api/name/method:)"));
  306. assertThat(result3, is(@"[[Class(Category) method:]](../Categories/Class(Category).html#//api/name/method:)"));
  307. assertThat(result4, is(@"[[Class(Category) method:]](../Categories/Class(Category).html#//api/name/method:)"));
  308. assertThat(result5, is(@"[Class(Unknown) method:]"));
  309. assertThat(result6, is(@"[Unknown(Category) method:]"));
  310. }
  311. - (void)testStringByConvertingCrossReferencesInString_shouldConvertProtocolRemoteInstanceMethod {
  312. // setup
  313. GBProtocolData *protocol = [GBTestObjectsRegistry protocolWithName:@"Protocol" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  314. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  315. GBStore *store = [GBTestObjectsRegistry storeWithObjects:protocol, class, nil];
  316. GBCommentsProcessor *processor = [self processorWithStore:store context:class];
  317. // execute
  318. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[Protocol method:]" withFlags:0];
  319. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<[Protocol method:]>" withFlags:0];
  320. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"-[Protocol method:]" withFlags:0];
  321. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<-[Protocol method:]>" withFlags:0];
  322. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"[Unknown method:]" withFlags:0];
  323. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"method:" withFlags:0];
  324. // verify
  325. assertThat(result1, is(@"[[Protocol method:]](../Protocols/Protocol.html#//api/name/method:)"));
  326. assertThat(result2, is(@"[[Protocol method:]](../Protocols/Protocol.html#//api/name/method:)"));
  327. assertThat(result3, is(@"[[Protocol method:]](../Protocols/Protocol.html#//api/name/method:)"));
  328. assertThat(result4, is(@"[[Protocol method:]](../Protocols/Protocol.html#//api/name/method:)"));
  329. assertThat(result5, is(@"[Unknown method:]"));
  330. assertThat(result6, is(@"method:"));
  331. }
  332. - (void)testStringByConvertingCrossReferencesInString_shouldKeepUnknownRemoteMemberEvenIfObjectIsKnown {
  333. // setup
  334. GBClassData *class1 = [GBTestObjectsRegistry classWithName:@"Class1" methods:[GBTestObjectsRegistry instanceMethodWithNames:@"method", nil], nil];
  335. GBClassData *class2 = [GBClassData classDataWithName:@"Class2"];
  336. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class1, class2, nil];
  337. GBCommentsProcessor *processor = [self processorWithStore:store context:class2];
  338. // execute
  339. NSString *result = [processor stringByConvertingCrossReferencesInString:@"[Class1 unknown:]" withFlags:0];
  340. // verify
  341. assertThat(result, is(@"[Class1 unknown:]"));
  342. }
  343. #pragma mark Document references detection
  344. - (void)testStringByConvertingCrossReferencesInString_shouldConvertDocument {
  345. // setup
  346. GBDocumentData *document = [GBDocumentData documentDataWithContents:@"c" path:@"Document1.html"];
  347. GBStore *store = [GBTestObjectsRegistry storeWithObjects:document, nil];
  348. GBCommentsProcessor *processor = [self processorWithStore:store context:nil];
  349. // execute
  350. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Document1" withFlags:0];
  351. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<Document1>" withFlags:0];
  352. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"Document12" withFlags:0];
  353. // verify
  354. assertThat(result1, is(@"[Document1](docs/Document1.html)"));
  355. assertThat(result2, is(@"[Document1](docs/Document1.html)"));
  356. assertThat(result3, is(@"Document12"));
  357. }
  358. #pragma mark URL cross references detection
  359. - (void)testStringByConvertingCrossReferencesInString_shouldConvertHTML {
  360. // setup
  361. GBCommentsProcessor *processor = [self defaultProcessor];
  362. // execute
  363. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"http://gentlebytes.com" withFlags:0];
  364. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"https://gentlebytes.com" withFlags:0];
  365. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"<http://gentlebytes.com>" withFlags:0];
  366. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<https://gentlebytes.com>" withFlags:0];
  367. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"http://gentlebytes.com https://gentlebytes.com" withFlags:0];
  368. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"https://gentlebytes.com http://gentlebytes.com" withFlags:0];
  369. // verify
  370. assertThat(result1, is(@"[http://gentlebytes.com](http://gentlebytes.com)"));
  371. assertThat(result2, is(@"[https://gentlebytes.com](https://gentlebytes.com)"));
  372. assertThat(result3, is(@"[http://gentlebytes.com](http://gentlebytes.com)"));
  373. assertThat(result4, is(@"[https://gentlebytes.com](https://gentlebytes.com)"));
  374. assertThat(result5, is(@"[http://gentlebytes.com](http://gentlebytes.com) [https://gentlebytes.com](https://gentlebytes.com)"));
  375. assertThat(result6, is(@"[https://gentlebytes.com](https://gentlebytes.com) [http://gentlebytes.com](http://gentlebytes.com)"));
  376. }
  377. - (void)testStringByConvertingCrossReferencesInString_shouldConvertFTP {
  378. // setup
  379. GBCommentsProcessor *processor = [self defaultProcessor];
  380. // execute
  381. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"ftp://gentlebytes.com" withFlags:0];
  382. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"ftps://gentlebytes.com" withFlags:0];
  383. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"<ftp://gentlebytes.com>" withFlags:0];
  384. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<ftps://gentlebytes.com>" withFlags:0];
  385. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"ftp://gentlebytes.com ftps://gentlebytes.com" withFlags:0];
  386. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"ftps://gentlebytes.com ftp://gentlebytes.com" withFlags:0];
  387. // verify
  388. assertThat(result1, is(@"[ftp://gentlebytes.com](ftp://gentlebytes.com)"));
  389. assertThat(result2, is(@"[ftps://gentlebytes.com](ftps://gentlebytes.com)"));
  390. assertThat(result3, is(@"[ftp://gentlebytes.com](ftp://gentlebytes.com)"));
  391. assertThat(result4, is(@"[ftps://gentlebytes.com](ftps://gentlebytes.com)"));
  392. assertThat(result5, is(@"[ftp://gentlebytes.com](ftp://gentlebytes.com) [ftps://gentlebytes.com](ftps://gentlebytes.com)"));
  393. assertThat(result6, is(@"[ftps://gentlebytes.com](ftps://gentlebytes.com) [ftp://gentlebytes.com](ftp://gentlebytes.com)"));
  394. }
  395. - (void)testStringByConvertingCrossReferencesInString_shouldConvertNewsAndRSS {
  396. // setup
  397. GBCommentsProcessor *processor = [self defaultProcessor];
  398. // execute
  399. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"news://gentlebytes.com" withFlags:0];
  400. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"rss://gentlebytes.com" withFlags:0];
  401. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"<news://gentlebytes.com>" withFlags:0];
  402. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"<rss://gentlebytes.com>" withFlags:0];
  403. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"rss://gentlebytes.com news://gentlebytes.com" withFlags:0];
  404. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"news://gentlebytes.com rss://gentlebytes.com" withFlags:0];
  405. // verify
  406. assertThat(result1, is(@"[news://gentlebytes.com](news://gentlebytes.com)"));
  407. assertThat(result2, is(@"[rss://gentlebytes.com](rss://gentlebytes.com)"));
  408. assertThat(result3, is(@"[news://gentlebytes.com](news://gentlebytes.com)"));
  409. assertThat(result4, is(@"[rss://gentlebytes.com](rss://gentlebytes.com)"));
  410. assertThat(result5, is(@"[rss://gentlebytes.com](rss://gentlebytes.com) [news://gentlebytes.com](news://gentlebytes.com)"));
  411. assertThat(result6, is(@"[news://gentlebytes.com](news://gentlebytes.com) [rss://gentlebytes.com](rss://gentlebytes.com)"));
  412. }
  413. - (void)testStringByConvertingCrossReferencesInString_shouldConvertFile {
  414. // setup
  415. GBCommentsProcessor *processor = [self defaultProcessor];
  416. // execute
  417. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"file://gentlebytes.com" withFlags:0];
  418. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<file://gentlebytes.com>" withFlags:0];
  419. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"file://first file://second" withFlags:0];
  420. // verify
  421. assertThat(result1, is(@"[file://gentlebytes.com](file://gentlebytes.com)"));
  422. assertThat(result2, is(@"[file://gentlebytes.com](file://gentlebytes.com)"));
  423. assertThat(result3, is(@"[file://first](file://first) [file://second](file://second)"));
  424. }
  425. - (void)testStringByConvertingCrossReferencesInString_shouldConvertMailto {
  426. // setup
  427. GBCommentsProcessor *processor = [self defaultProcessor];
  428. // execute
  429. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"mailto:appledoc@gentlebytes.com" withFlags:0];
  430. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"<mailto:appledoc@gentlebytes.com>" withFlags:0];
  431. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"mailto:a@b.com mailto:c@d.com" withFlags:0];
  432. // verify
  433. assertThat(result1, is(@"[appledoc@gentlebytes.com](mailto:appledoc@gentlebytes.com)"));
  434. assertThat(result2, is(@"[appledoc@gentlebytes.com](mailto:appledoc@gentlebytes.com)"));
  435. assertThat(result3, is(@"[a@b.com](mailto:a@b.com) [c@d.com](mailto:c@d.com)"));
  436. }
  437. #pragma mark Combinations detection testing
  438. - (void)testStringByConvertingCrossReferencesInString_shouldConvertClassAndProtocol {
  439. // setup
  440. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  441. GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
  442. GBStore *store = [GBTestObjectsRegistry storeWithObjects:protocol, class, nil];
  443. GBCommentsProcessor *processor = [self processorWithStore:store];
  444. // execute
  445. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Class Protocol" withFlags:0];
  446. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"Protocol Class" withFlags:0];
  447. // verify
  448. assertThat(result1, is(@"[Class](Classes/Class.html) [Protocol](Protocols/Protocol.html)"));
  449. assertThat(result2, is(@"[Protocol](Protocols/Protocol.html) [Class](Classes/Class.html)"));
  450. }
  451. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategoryAndClass {
  452. // setup
  453. GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
  454. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  455. GBStore *store = [GBTestObjectsRegistry storeWithObjects:category, class, nil];
  456. GBCommentsProcessor *processor = [self processorWithStore:store];
  457. // execute
  458. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Class(Category) Class" withFlags:0];
  459. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"Class Class(Category)" withFlags:0];
  460. // verify
  461. assertThat(result1, is(@"[Class(Category)](Categories/Class(Category).html) [Class](Classes/Class.html)"));
  462. assertThat(result2, is(@"[Class](Classes/Class.html) [Class(Category)](Categories/Class(Category).html)"));
  463. }
  464. - (void)testStringByConvertingCrossReferencesInString_shouldConvertCategoryAndProtocol {
  465. // setup - although it's not possible to do categories on protocols, we still test to properly cover these...
  466. GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Protocol"];
  467. GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
  468. GBStore *store = [GBTestObjectsRegistry storeWithObjects:category, protocol, nil];
  469. GBCommentsProcessor *processor = [self processorWithStore:store];
  470. // execute
  471. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"Protocol(Category) Protocol" withFlags:0];
  472. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"Protocol Protocol(Category)" withFlags:0];
  473. // verify
  474. assertThat(result1, is(@"[Protocol(Category)](Categories/Protocol(Category).html) [Protocol](Protocols/Protocol.html)"));
  475. assertThat(result2, is(@"[Protocol](Protocols/Protocol.html) [Protocol(Category)](Categories/Protocol(Category).html)"));
  476. }
  477. #pragma mark Manual links detection testing
  478. - (void)testStringByConvertingCrossReferencesInString_shouldKeepManualLinks {
  479. // setup
  480. GBCommentsProcessor *processor = [self processorWithStore:nil];
  481. // execute
  482. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[text](something)" withFlags:0];
  483. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"[multi word](more words)" withFlags:0];
  484. // verify
  485. assertThat(result1, is(@"[text](something)"));
  486. assertThat(result2, is(@"[multi word](more words)"));
  487. }
  488. - (void)testStringByConvertingCrossReferencesInString_shouldKeepManualURLLinks {
  489. // setup
  490. GBCommentsProcessor *processor = [self processorWithStore:nil];
  491. // execute
  492. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[text](http://ab.com)" withFlags:0];
  493. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"[text](https://ab.com)" withFlags:0];
  494. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"[text](ftp://ab.com)" withFlags:0];
  495. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"[text](ftps://ab.com)" withFlags:0];
  496. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"[text](news://ab.com)" withFlags:0];
  497. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"[text](rss://ab.com)" withFlags:0];
  498. NSString *result7 = [processor stringByConvertingCrossReferencesInString:@"[text](mailto:a@b.com)" withFlags:0];
  499. // verify
  500. assertThat(result1, is(@"[text](http://ab.com)"));
  501. assertThat(result2, is(@"[text](https://ab.com)"));
  502. assertThat(result3, is(@"[text](ftp://ab.com)"));
  503. assertThat(result4, is(@"[text](ftps://ab.com)"));
  504. assertThat(result5, is(@"[text](news://ab.com)"));
  505. assertThat(result6, is(@"[text](rss://ab.com)"));
  506. assertThat(result7, is(@"[text](mailto:a@b.com)"));
  507. }
  508. - (void)testStringByConvertingCrossReferencesInString_shouldKeepManualObjectLinksAndUpdateAddress {
  509. // setup
  510. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  511. GBCategoryData *category = [GBCategoryData categoryDataWithName:@"Category" className:@"Class"];
  512. GBProtocolData *protocol = [GBProtocolData protocolDataWithName:@"Protocol"];
  513. GBDocumentData *document = [GBDocumentData documentDataWithContents:@"c" path:@"document.ext"];
  514. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, category, protocol, document, nil];
  515. GBCommentsProcessor *processor = [self processorWithStore:store];
  516. // setup
  517. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[text](Class)" withFlags:0];
  518. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"[text](Class(Category))" withFlags:0];
  519. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"[text](Protocol)" withFlags:0];
  520. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"[text](document)" withFlags:0];
  521. // verify
  522. assertThat(result1, is(@"[text](Classes/Class.html)"));
  523. assertThat(result2, is(@"[text](Categories/Class(Category).html)"));
  524. assertThat(result3, is(@"[text](Protocols/Protocol.html)"));
  525. assertThat(result4, is(@"[text](docs/document.html)"));
  526. }
  527. - (void)testStringByConvertingCrossReferencesInString_shouldIgnoreKnownObjectsInManualLinkDescriptionOrTitle {
  528. // setup
  529. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  530. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  531. GBCommentsProcessor *processor = [self processorWithStore:store];
  532. // setup
  533. NSString *result = [processor stringByConvertingCrossReferencesInString:@"[Class](Class \"Class\")" withFlags:0];
  534. // verify
  535. assertThat(result, is(@"[Class](Classes/Class.html \"Class\")"));
  536. }
  537. - (void)testStringByConvertingCrossReferencesInString_shouldHandleMarkdownLinkReferences {
  538. // setup
  539. GBClassData *class = [GBClassData classDataWithName:@"Class"];
  540. GBStore *store = [GBTestObjectsRegistry storeWithObjects:class, nil];
  541. GBCommentsProcessor *processor = [self processorWithStore:store];
  542. // setup
  543. NSString *result1 = [processor stringByConvertingCrossReferencesInString:@"[1]: http://ab.com" withFlags:0];
  544. NSString *result2 = [processor stringByConvertingCrossReferencesInString:@"[1]: http://ab.com \"title\"" withFlags:0];
  545. NSString *result3 = [processor stringByConvertingCrossReferencesInString:@"[1]: Class" withFlags:0];
  546. NSString *result4 = [processor stringByConvertingCrossReferencesInString:@"[1]: Class \"title\"" withFlags:0];
  547. NSString *result5 = [processor stringByConvertingCrossReferencesInString:@"[Class]: something" withFlags:0];
  548. NSString *result6 = [processor stringByConvertingCrossReferencesInString:@"[1]: something \"Class\"" withFlags:0];
  549. // verify
  550. assertThat(result1, is(@"[1]: http://ab.com"));
  551. assertThat(result2, is(@"[1]: http://ab.com \"title\""));
  552. assertThat(result3, is(@"[1]: Classes/Class.html"));
  553. assertThat(result4, is(@"[1]: Classes/Class.html \"title\""));
  554. assertThat(result5, is(@"[Class]: something"));
  555. assertThat(result6, is(@"[1]: something \"Class\""));
  556. }
  557. #pragma mark Creation methods
  558. - (GBCommentsProcessor *)defaultProcessor {
  559. // Creates a new GBCommentsProcessor using real settings. Note that we disable embedding cross references to make test strings more readable.
  560. id settings = [GBTestObjectsRegistry realSettingsProvider];
  561. [settings setEmbedCrossReferencesWhenProcessingMarkdown:NO];
  562. return [GBCommentsProcessor processorWithSettingsProvider:settings];
  563. }
  564. - (GBCommentsProcessor *)processorWithStore:(id)store {
  565. // Creates a new GBCommentsProcessor using real settings and the given store.
  566. return [self processorWithStore:store context:nil];
  567. }
  568. - (GBCommentsProcessor *)processorWithStore:(id)store context:(id)context {
  569. // Creates a new GBCommentsProcessor using real settings and the given store and context. Note that we disable embedding cross references to make test strings more readable.
  570. id settings = [GBTestObjectsRegistry realSettingsProvider];
  571. [settings setEmbedCrossReferencesWhenProcessingMarkdown:NO];
  572. GBCommentsProcessor *result = [self defaultProcessor];
  573. [result setValue:store forKey:@"store"];
  574. [result setValue:context forKey:@"currentContext"];
  575. return result;
  576. }
  577. @end