xcfit 2.0.4 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -9
  3. data/Docs/InitialVersion.md +340 -0
  4. data/Package.swift +5 -0
  5. data/README.md +348 -145
  6. data/XCFit.gemspec +1 -1
  7. data/XCFit.podspec +17 -9
  8. data/XCFit/Classes/Cucumberish/Core/CCIBlockDefinitions.h +400 -0
  9. data/XCFit/Classes/Cucumberish/Core/Managers/CCIFeaturesManager.h +72 -0
  10. data/XCFit/Classes/Cucumberish/Core/Managers/CCIFeaturesManager.m +141 -0
  11. data/XCFit/Classes/Cucumberish/Core/Managers/CCIStepsManager.h +51 -0
  12. data/XCFit/Classes/Cucumberish/Core/Managers/CCIStepsManager.m +245 -0
  13. data/XCFit/Classes/Cucumberish/Core/Models/CCIArgument.h +62 -0
  14. data/XCFit/Classes/Cucumberish/Core/Models/CCIArgument.m +117 -0
  15. data/XCFit/Classes/Cucumberish/Core/Models/CCIAroundHock.h +37 -0
  16. data/XCFit/Classes/Cucumberish/Core/Models/CCIAroundHock.m +37 -0
  17. data/XCFit/Classes/Cucumberish/Core/Models/CCIBackground.h +46 -0
  18. data/XCFit/Classes/Cucumberish/Core/Models/CCIBackground.m +117 -0
  19. data/XCFit/Classes/Cucumberish/Core/Models/CCIExample.h +89 -0
  20. data/XCFit/Classes/Cucumberish/Core/Models/CCIExample.m +128 -0
  21. data/XCFit/Classes/Cucumberish/Core/Models/CCIFeature.h +49 -0
  22. data/XCFit/Classes/Cucumberish/Core/Models/CCIFeature.m +174 -0
  23. data/XCFit/Classes/Cucumberish/Core/Models/CCIHock.h +36 -0
  24. data/XCFit/Classes/Cucumberish/Core/Models/CCIHock.m +34 -0
  25. data/XCFit/Classes/Cucumberish/Core/Models/CCILocation.h +61 -0
  26. data/XCFit/Classes/Cucumberish/Core/Models/CCILocation.m +91 -0
  27. data/XCFit/Classes/Cucumberish/Core/Models/CCIScenarioDefinition.h +97 -0
  28. data/XCFit/Classes/Cucumberish/Core/Models/CCIScenarioDefinition.m +224 -0
  29. data/XCFit/Classes/Cucumberish/Core/Models/CCIStep.h +85 -0
  30. data/XCFit/Classes/Cucumberish/Core/Models/CCIStep.m +98 -0
  31. data/XCFit/Classes/Cucumberish/Core/Models/CCIStepDefinition.h +43 -0
  32. data/XCFit/Classes/Cucumberish/Core/Models/CCIStepDefinition.m +65 -0
  33. data/XCFit/Classes/Cucumberish/Cucumberish.h +133 -0
  34. data/XCFit/Classes/Cucumberish/Cucumberish.m +604 -0
  35. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHAstBuilder.h +15 -0
  36. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHAstBuilder.m +312 -0
  37. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHAstNode.h +20 -0
  38. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHAstNode.m +79 -0
  39. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHBackground.h +12 -0
  40. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHBackground.m +18 -0
  41. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHComment.h +11 -0
  42. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHComment.m +27 -0
  43. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHDataTable.h +14 -0
  44. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHDataTable.m +30 -0
  45. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHDocString.h +14 -0
  46. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHDocString.m +29 -0
  47. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHExamples.h +24 -0
  48. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHExamples.m +49 -0
  49. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHFeature.h +24 -0
  50. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHFeature.m +50 -0
  51. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinDialect.h +25 -0
  52. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinDialect.m +64 -0
  53. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinDialectProvider.h +9 -0
  54. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinDialectProvider.m +124 -0
  55. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinDialectProviderProtocol.h +10 -0
  56. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLanguageConstants.h +9 -0
  57. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLanguageConstants.m +10 -0
  58. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLanguageSetting.h +17 -0
  59. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLanguageSetting.m +18 -0
  60. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLine.h +12 -0
  61. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLine.m +179 -0
  62. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLineProtocol.h +64 -0
  63. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLineSpan.h +9 -0
  64. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHGherkinLineSpan.m +26 -0
  65. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHHasDescriptionProtocol.h +8 -0
  66. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHHasLocationProtocol.h +8 -0
  67. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHHasRowsProtocol.h +8 -0
  68. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHHasStepsProtocol.h +8 -0
  69. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHHasTagsProtocol.h +8 -0
  70. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHLocation.h +12 -0
  71. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHLocation.m +41 -0
  72. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHNode.h +4 -0
  73. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHNode.m +5 -0
  74. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHParser+Extensions.h +10 -0
  75. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHParser+Extensions.m +18 -0
  76. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHParser.h +132 -0
  77. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHParser.m +2735 -0
  78. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHParserException.h +55 -0
  79. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHParserException.m +192 -0
  80. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenario.h +14 -0
  81. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenario.m +18 -0
  82. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenarioDefinition.h +23 -0
  83. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenarioDefinition.m +41 -0
  84. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenarioDefinition_Private.h +6 -0
  85. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenarioOutline.h +15 -0
  86. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHScenarioOutline.m +26 -0
  87. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHStep.h +16 -0
  88. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHStep.m +35 -0
  89. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHStepArgument.h +4 -0
  90. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHStepArgument.m +5 -0
  91. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTableCell.h +13 -0
  92. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTableCell.m +28 -0
  93. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTableRow.h +13 -0
  94. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTableRow.m +29 -0
  95. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTag.h +13 -0
  96. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTag.m +28 -0
  97. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHToken.h +26 -0
  98. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHToken.m +50 -0
  99. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTokenMatcher.h +29 -0
  100. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTokenMatcher.m +283 -0
  101. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTokenScanner.h +12 -0
  102. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHTokenScanner.m +59 -0
  103. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/NSString+Trim.h +7 -0
  104. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/NSString+Trim.m +28 -0
  105. data/XCFit/Classes/Cucumberish/Dependencies/Gherkin/gherkin-languages.json +2969 -0
  106. data/XCFit/Classes/Cucumberish/Utils/NSArray+Hashes.h +24 -0
  107. data/XCFit/Classes/Cucumberish/Utils/NSArray+Hashes.m +44 -0
  108. data/XCFit/Classes/Cucumberish/Utils/NSObject+Dictionary.h +7 -0
  109. data/XCFit/Classes/Cucumberish/Utils/NSObject+Dictionary.m +83 -0
  110. data/XCFit/Classes/Cucumberish/Utils/NSString+Formatter.h +32 -0
  111. data/XCFit/Classes/Cucumberish/Utils/NSString+Formatter.m +70 -0
  112. data/Xcode7-Templates/XCFit/Cucumberish UI Test Bundle Base.xctemplate/TemplateInfo.plist +13 -0
  113. data/Xcode7-Templates/XCFit/iOS UI Cucumberish Testing Bundle.xctemplate/TemplateInfo.plist +11 -0
  114. data/lib/XCFit/version.rb +1 -1
  115. metadata +108 -38
  116. data/XCFit/Assets/.gitkeep +0 -0
  117. data/XCFit/Assets/Gherkin/Cucumber Feature.xctemplate/TemplateIcon.png +0 -0
  118. data/XCFit/Assets/Gherkin/Cucumber Feature.xctemplate/TemplateIcon@2x.png +0 -0
  119. data/XCFit/Assets/Gherkin/Cucumber Feature.xctemplate/TemplateInfo.plist +0 -22
  120. data/XCFit/Assets/Gherkin/Cucumber Feature.xctemplate/___FILEBASENAME___.feature +0 -20
  121. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/AcceptanceTests-Bridging-Header.h +0 -1
  122. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/FixtureExample.swift +0 -31
  123. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/SlimTables.h +0 -28
  124. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/TemplateIcon.png +0 -0
  125. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/TemplateIcon@2x.png +0 -0
  126. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/TemplateInfo.plist +0 -150
  127. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/___PACKAGENAMEASIDENTIFIER___-Bridging-Header.h +0 -1
  128. data/XCFit/Assets/XCFit/Base Acceptance Tests.xctemplate/___PACKAGENAMEASIDENTIFIER___.m +0 -15
  129. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/TemplateIcon.png +0 -0
  130. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/TemplateIcon@2x.png +0 -0
  131. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/TemplateInfo.plist +0 -123
  132. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___-Bridging-Header.h +0 -7
  133. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.feature +0 -11
  134. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.h +0 -14
  135. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.m +0 -17
  136. data/XCFit/Assets/XCFit/Cucumberish API Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.swift +0 -23
  137. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/TemplateIcon.png +0 -0
  138. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/TemplateIcon@2x.png +0 -0
  139. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/TemplateInfo.plist +0 -123
  140. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___-Bridging-Header.h +0 -7
  141. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.feature +0 -11
  142. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.h +0 -14
  143. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.m +0 -17
  144. data/XCFit/Assets/XCFit/Cucumberish UI Test Bundle Base.xctemplate/___PACKAGENAMEASIDENTIFIER___.swift +0 -25
  145. data/XCFit/Assets/XCFit/Mac Acceptance Tests.xctemplate/Empty.xib +0 -12
  146. data/XCFit/Assets/XCFit/Mac Acceptance Tests.xctemplate/TemplateInfo.plist +0 -54
  147. data/XCFit/Assets/XCFit/MacOS API Cucumberish Testing Bundle.xctemplate/TemplateInfo.plist +0 -39
  148. data/XCFit/Assets/XCFit/MacOS UI Cucumberish Testing Bundle.xctemplate/TemplateInfo.plist +0 -39
  149. data/XCFit/Assets/XCFit/iOS API Cucumberish Testing Bundle.xctemplate/TemplateInfo.plist +0 -39
  150. data/XCFit/Assets/XCFit/iOS Acceptance Tests.xctemplate/TemplateInfo.plist +0 -52
  151. data/XCFit/Assets/XCFit/iOS UI Cucumberish Testing Bundle.xctemplate/TemplateInfo.plist +0 -39
@@ -0,0 +1,15 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "GHAstNode.h"
3
+ #import "GHParser.h"
4
+ @protocol GHAstBuilderProtocol;
5
+ @class GHToken;
6
+
7
+ @interface GHAstBuilder<GHAstBuilderProtocol> : NSObject
8
+
9
+ - (id)init;
10
+ - (void)reset;
11
+ - (void)buildWithToken:(GHToken *)theToken;
12
+ - (void)startRuleWithType:(GHRuleType)theRuleType;
13
+ - (void)endRuleWithType:(GHRuleType)theRuleType;
14
+
15
+ @end
@@ -0,0 +1,312 @@
1
+ #import "GHAstBuilder.h"
2
+
3
+ #import "GHTag.h"
4
+ #import "GHToken.h"
5
+ #import "GHComment.h"
6
+ #import "GHTableRow.h"
7
+ #import "GHStep.h"
8
+ #import "GHDataTable.h"
9
+ #import "GHDocString.h"
10
+ #import "GHBackground.h"
11
+ #import "GHScenario.h"
12
+ #import "GHScenarioOutline.h"
13
+ #import "GHExamples.h"
14
+ #import "GHGherkinDialect.h"
15
+ #import "GHFeature.h"
16
+ #import "GHLocation.h"
17
+ #import "GHGherkinLanguageConstants.h"
18
+ #import "GHTableCell.h"
19
+ #import "GHGherkinLineSpan.h"
20
+
21
+ #import "GHParser.h"
22
+
23
+ @interface GHAstBuilder ()
24
+
25
+ + (NSString *)descriptionForScenarioDefinitionNode:(GHAstNode *)theScenarioDefinitionNode;
26
+ + (NSArray<GHStep *> *)stepsWithScenarioDefinitionNode:(GHAstNode *)theScenarioDefinitionNode;
27
+ - (NSArray<GHTableCell *> *)cellsWithToken:(GHToken *)theTableRowToken;
28
+ - (NSArray<GHTableRow *> *)tableRowsForNode:(GHAstNode *)theNode;
29
+ - (NSArray<GHTag *> *)tagsForNode:(GHAstNode *)theNode;
30
+ - (GHLocation *)locationForToken:(GHToken *)theToken column:(NSUInteger)column;
31
+ - (GHLocation *)locationForToken:(GHToken *)theToken;
32
+
33
+ @end
34
+
35
+ @implementation GHAstBuilder
36
+ {
37
+ NSMutableArray<GHAstNode *> * stack;
38
+ NSMutableArray<GHComment *> * comments;
39
+ }
40
+
41
+ - (id)init
42
+ {
43
+ if (self = [super init])
44
+ {
45
+ [self reset];
46
+ }
47
+
48
+ return self;
49
+ }
50
+
51
+ - (void)reset
52
+ {
53
+ stack = [[NSMutableArray alloc] init];
54
+ [stack addObject: [[GHAstNode alloc] initWithRuleType: GHRuleTypeNone]];
55
+ comments = [[NSMutableArray alloc] init];
56
+ }
57
+
58
+ - (void)buildWithToken:(GHToken *)theToken
59
+ {
60
+ if ([theToken matchedType] == GHTokenTypeComment)
61
+ {
62
+ [comments addObject: [[GHComment alloc] initWithLocation: [theToken location] text: [theToken matchedText]]];
63
+ }
64
+ else
65
+ {
66
+ [[stack lastObject] addObject: theToken withRuleType: (GHRuleType)[theToken matchedType]];
67
+ }
68
+ }
69
+
70
+ - (void)startRuleWithType:(GHRuleType)theRuleType
71
+ {
72
+ [stack addObject: [[GHAstNode alloc] initWithRuleType: theRuleType]];
73
+ }
74
+
75
+ - (void)endRuleWithType:(GHRuleType)theRuleType
76
+ {
77
+ GHAstNode * node = [stack lastObject];
78
+ [stack removeLastObject];
79
+ id transformedNode = [self transformNode: node];
80
+
81
+ [[stack lastObject] addObject: transformedNode withRuleType: [node ruleType]];
82
+ }
83
+
84
+ - (id)result
85
+ {
86
+ return [[stack lastObject] singleWithRuleType: GHRuleTypeFeature];
87
+ }
88
+
89
+ - (id)transformNode:(GHAstNode *)theNode
90
+ {
91
+ switch ([theNode ruleType])
92
+ {
93
+ case GHRuleTypeStep:
94
+ {
95
+ GHToken * stepLine = [theNode tokenWithType: GHTokenTypeStepLine];
96
+ GHStepArgument * dataTableStepArgument = [theNode singleWithRuleType: GHRuleTypeDataTable];
97
+ GHStepArgument * stepArg = nil;
98
+ if (dataTableStepArgument)
99
+ stepArg = dataTableStepArgument;
100
+ else
101
+ stepArg = [theNode singleWithRuleType: GHRuleTypeDocString];
102
+
103
+ return [[GHStep alloc] initWithLocation: [stepLine location] keyword: [stepLine matchedKeyword] text: [stepLine matchedText] stepArgument:stepArg];
104
+ }
105
+ case GHRuleTypeDocString:
106
+ {
107
+ GHToken * separatorToken = [[theNode tokensWithType: GHTokenTypeDocStringSeparator] firstObject];
108
+ NSString * contentType = [[separatorToken matchedText] length] == 0 ? nil : [separatorToken matchedText];
109
+ NSArray<GHToken *> * lineTokens = [theNode tokensWithType: GHTokenTypeOther];
110
+
111
+ NSString * content = [[lineTokens valueForKey: @"matchedText"] componentsJoinedByString: @"\n"];
112
+
113
+ return [[GHDocString alloc] initWithLocation: [separatorToken location] contentType: contentType content: content];
114
+ }
115
+ case GHRuleTypeDataTable:
116
+ {
117
+ NSArray<GHTableRow *> * rows = [self tableRowsForNode: theNode];
118
+
119
+ return [[GHDataTable alloc] initWithTableRows: rows];
120
+ }
121
+ case GHRuleTypeBackground:
122
+ {
123
+ GHToken * backgroundLine = [theNode tokenWithType: GHTokenTypeBackgroundLine];
124
+ NSString * description = [GHAstBuilder descriptionForScenarioDefinitionNode: theNode];
125
+ NSArray<GHStep *> * steps = [GHAstBuilder stepsWithScenarioDefinitionNode: theNode];
126
+
127
+ return [[GHBackground alloc] initWithLocation: [backgroundLine location] keyword: [backgroundLine matchedKeyword] name: [backgroundLine matchedText] description: description steps: steps];
128
+ }
129
+ case GHRuleTypeScenario_Definition:
130
+ {
131
+ NSArray<GHTag *> * tags = [self tagsForNode: theNode];
132
+
133
+ id scenarioNode = [theNode singleWithRuleType: GHRuleTypeScenario];
134
+ if (scenarioNode != nil)
135
+ {
136
+ GHToken * scenarioLine = [scenarioNode tokenWithType: GHTokenTypeScenarioLine];
137
+
138
+ NSString * description = [GHAstBuilder descriptionForScenarioDefinitionNode: scenarioNode];
139
+ NSArray<GHStep *> * steps = [GHAstBuilder stepsWithScenarioDefinitionNode: scenarioNode];
140
+
141
+ return [[GHScenario alloc] initWithTags: tags location: [scenarioLine location] keyword: [scenarioLine matchedKeyword] name: [scenarioLine matchedText] description: description steps: steps];
142
+ }
143
+ else
144
+ {
145
+ id scenarioOutlineNode = [theNode singleWithRuleType: GHRuleTypeScenarioOutline];
146
+ if (scenarioOutlineNode == nil)
147
+ @throw [NSException exceptionWithName: NSParseErrorException reason: @"Internal gramar error" userInfo: nil];
148
+
149
+ GHToken * scenarioOutlineLine = [scenarioOutlineNode tokenWithType: GHTokenTypeScenarioOutlineLine];
150
+
151
+ NSString * description = [GHAstBuilder descriptionForScenarioDefinitionNode: scenarioOutlineNode];
152
+ NSArray<GHStep *> * steps = [GHAstBuilder stepsWithScenarioDefinitionNode: scenarioOutlineNode];
153
+ NSArray<GHExamples *> * examples = (NSArray<GHExamples *> *)[scenarioOutlineNode itemsWithRuleType: GHRuleTypeExamples_Definition];
154
+
155
+ return [[GHScenarioOutline alloc] initWithTags: tags location: [scenarioOutlineLine location] keyword: [scenarioOutlineLine matchedKeyword] name: [scenarioOutlineLine matchedText] description: description steps: steps examples: examples];
156
+ }
157
+ }
158
+ case GHRuleTypeExamples_Definition:
159
+ {
160
+ NSArray<GHTag *> * tags = [self tagsForNode: theNode];
161
+ id examplesNode = [theNode singleWithRuleType: GHRuleTypeExamples];
162
+
163
+ GHToken * examplesLine = [examplesNode tokenWithType: GHTokenTypeExamplesLine];
164
+ NSString * description = [GHAstBuilder descriptionForScenarioDefinitionNode: examplesNode];
165
+
166
+ NSArray<GHTableRow *> * allRows = [examplesNode singleWithRuleType: GHRuleTypeExamples_Table];
167
+
168
+ GHTableRow * header = nil;
169
+ NSArray<GHTableRow *> * rows = nil;
170
+ if (allRows)
171
+ {
172
+ header = [allRows firstObject];
173
+ NSMutableArray<GHTableRow *> * allRowsBuffer = [allRows mutableCopy];
174
+ [allRowsBuffer removeObject: header];
175
+ rows = [[NSArray<GHTableRow *> alloc] initWithArray: allRowsBuffer];
176
+ }
177
+
178
+ return [[GHExamples alloc] initWithTags: tags location: [examplesLine location] keyword: [examplesLine matchedKeyword] name: [examplesLine matchedText] description: description header: header body: rows];
179
+ }
180
+ case GHRuleTypeExamples_Table:
181
+ {
182
+ NSArray<GHTableRow *> * allRows = [self tableRowsForNode: theNode];
183
+
184
+ return allRows;
185
+ }
186
+ case GHRuleTypeDescription:
187
+ {
188
+ NSArray<GHToken *> * lineTokens = (NSArray<GHToken *> *)[theNode tokensWithType: GHTokenTypeOther];
189
+
190
+ NSMutableArray<GHToken *> * lineTokensBuffer = [lineTokens mutableCopy];
191
+ NSEnumerator * reverseObjectEnumerator = [lineTokens reverseObjectEnumerator];
192
+ for (GHToken * lineToken in reverseObjectEnumerator)
193
+ {
194
+ if (![[[lineToken matchedText] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] length])
195
+ [lineTokensBuffer removeObject: lineToken];
196
+ else
197
+ break;
198
+ }
199
+ return [[lineTokensBuffer valueForKey: @"matchedText"] componentsJoinedByString: @"\n"];
200
+ }
201
+ case GHRuleTypeFeature:
202
+ {
203
+ id header = [theNode singleWithRuleType: GHRuleTypeFeature_Header];
204
+ if (!header)
205
+ return nil;
206
+
207
+ NSArray<GHTag *> * tags = [self tagsForNode: header];
208
+ GHToken * featureLine = [header tokenWithType: GHTokenTypeFeatureLine];
209
+ if (featureLine == nil)
210
+ return nil;
211
+
212
+ GHBackground * background = [theNode singleWithRuleType: GHRuleTypeBackground];
213
+ NSMutableArray<GHScenarioDefinition *> * children = [(NSArray<GHScenarioDefinition *> *)[theNode itemsWithRuleType: GHRuleTypeScenario_Definition] mutableCopy];
214
+ if(background != nil){
215
+ [children insertObject:background atIndex:0];
216
+ }
217
+ NSString * description = [GHAstBuilder descriptionForScenarioDefinitionNode: header];
218
+
219
+ if ([featureLine matchedGherkinDialect] == nil)
220
+ return nil;
221
+
222
+ NSString * language = [[featureLine matchedGherkinDialect] language];
223
+
224
+ return [[GHFeature alloc] initWithTags: tags location: [featureLine location] language: language keyword: [featureLine matchedKeyword] name: [featureLine matchedText] description: description children: children comments: comments];
225
+ }
226
+ }
227
+
228
+ return theNode;
229
+ }
230
+
231
+ - (GHLocation *)locationForToken:(GHToken *)theToken
232
+ {
233
+ return [self locationForToken: theToken column: 0];
234
+ }
235
+
236
+ - (GHLocation *)locationForToken:(GHToken *)theToken column:(NSUInteger)column
237
+ {
238
+ return column == 0 ? [theToken location] : [[GHLocation alloc] initWithLine: [[theToken location] line] column: column];
239
+ }
240
+
241
+ - (NSArray<GHTag *> *)tagsForNode:(GHAstNode *)theNode
242
+ {
243
+ GHAstNode * tagsNode = [theNode singleWithRuleType: GHRuleTypeTags];
244
+ if (tagsNode == nil)
245
+ return [[NSArray<GHTag *> alloc] init];
246
+
247
+
248
+ NSArray<GHToken *> * tokens = [tagsNode tokensWithType: GHTokenTypeTagLine];
249
+
250
+ NSMutableArray<GHTag *> * tagsBuffer = [[NSMutableArray<GHTag *> alloc] init];
251
+ for (GHToken * token in tokens)
252
+ {
253
+ for (GHGherkinLineSpan * lineSpan in [token matchedItems])
254
+ {
255
+ [tagsBuffer addObject: [[GHTag alloc] initWithLocation: [self locationForToken: token column: [lineSpan column]] name: [lineSpan text]]];
256
+ }
257
+ }
258
+ return [[NSArray<GHTag *> alloc] initWithArray: tagsBuffer];
259
+ }
260
+
261
+ - (NSArray<GHTableRow *> *)tableRowsForNode:(GHAstNode *)theNode
262
+ {
263
+ NSArray<GHToken *> * tokens = [theNode tokensWithType: GHTokenTypeTableRow];
264
+ NSMutableArray<GHTableRow *> * tableRowsBuffer = [[NSMutableArray<GHTableRow *> alloc] initWithCapacity: [tokens count]];
265
+ for (GHToken * token in tokens)
266
+ {
267
+ [tableRowsBuffer addObject: [[GHTableRow alloc] initWithLocation: [self locationForToken: token] cells: [self cellsWithToken: token]]];
268
+ }
269
+ NSArray<GHTableRow *> * tableRows = [[NSArray<GHTableRow *> alloc] initWithArray: tableRowsBuffer];
270
+
271
+ [self ensureCellCountForRows: tableRows];
272
+
273
+ return tableRows;
274
+ }
275
+
276
+ - (void)ensureCellCountForRows:(NSArray<GHTableRow *> *)theRows
277
+ {
278
+ if ([theRows count])
279
+ {
280
+ NSUInteger cellCount = [[theRows[0] cells] count];
281
+ for (GHTableRow * row in theRows)
282
+ {
283
+ if ([[row cells] count] != cellCount)
284
+ {
285
+ @throw [[GHAstBuilderException alloc] initWithMessage: @"inconsistent cell count within the table" location: [row location]];
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ - (NSArray<GHTableCell *> *)cellsWithToken:(GHToken *)theTableRowToken
292
+ {
293
+ NSArray<GHGherkinLineSpan *> * matchedItems = [theTableRowToken matchedItems];
294
+ NSMutableArray<GHTableCell *> * cellsBuffer = [[NSMutableArray<GHTableCell *> alloc] initWithCapacity: [matchedItems count]];
295
+ for (GHGherkinLineSpan * matchedItem in matchedItems)
296
+ {
297
+ [cellsBuffer addObject: [[GHTableCell alloc] initWithLocation: [self locationForToken: theTableRowToken column: [matchedItem column]] value: [matchedItem text]]];
298
+ }
299
+ return [[NSArray<GHTableCell *> alloc] initWithArray: cellsBuffer];
300
+ }
301
+
302
+ + (NSArray<GHStep *> *)stepsWithScenarioDefinitionNode:(GHAstNode *)theScenarioDefinitionNode
303
+ {
304
+ return (NSArray<GHStep *> *)[theScenarioDefinitionNode itemsWithRuleType: GHRuleTypeStep];
305
+ }
306
+
307
+ + (NSString *)descriptionForScenarioDefinitionNode:(GHAstNode *)theScenarioDefinitionNode
308
+ {
309
+ return [theScenarioDefinitionNode singleWithRuleType: GHRuleTypeDescription];
310
+ }
311
+
312
+ @end
@@ -0,0 +1,20 @@
1
+ #import <Foundation/Foundation.h>
2
+ @class GHToken;
3
+
4
+ typedef enum GHRuleType GHRuleType;
5
+ typedef enum GHTokenType GHTokenType;
6
+
7
+ @interface GHAstNode<ObjectType> : NSObject
8
+
9
+ @property (nonatomic, readonly) GHRuleType ruleType;
10
+
11
+ - (id)initWithRuleType:(GHRuleType)theRuleType;
12
+ - (GHToken *)tokenWithType:(GHTokenType)theTokenType;
13
+ - (NSArray<GHToken *> *)tokensWithType:(GHTokenType)theTokenType;
14
+ - (id)singleWithRuleType:(GHRuleType)theRuleType;
15
+ - (NSArray<NSObject *> *)itemsWithRuleType:(GHRuleType)theRuleType;
16
+ - (void)setSingleWithRuleType:(GHRuleType)theRuleType value:(ObjectType)theValue;
17
+ - (void)addRange:(GHRuleType)theRuleType values:(NSArray<NSObject *> *)theValues;
18
+ - (void)addObject:(NSObject *)theObject withRuleType:(GHRuleType)theRuleType;
19
+
20
+ @end
@@ -0,0 +1,79 @@
1
+ #import "GHAstNode.h"
2
+
3
+ #import "GHToken.h"
4
+ #import "GHParser.h"
5
+
6
+ @interface GHAstNode ()
7
+
8
+ @property (nonatomic, assign) GHRuleType ruleType;
9
+
10
+ @end
11
+
12
+ @implementation GHAstNode
13
+ {
14
+ NSMutableDictionary<NSNumber *, NSMutableArray<NSObject *> *> * subitems;
15
+ }
16
+
17
+ @synthesize ruleType;
18
+
19
+ - (id)initWithRuleType:(GHRuleType)theRuleType
20
+ {
21
+ if (self = [super init])
22
+ {
23
+ ruleType = theRuleType;
24
+ subitems = [[NSMutableDictionary<NSNumber *, NSMutableArray<NSObject *> *> alloc] init];
25
+ }
26
+ return self;
27
+ }
28
+
29
+ - (GHToken *)tokenWithType:(GHTokenType)theTokenType
30
+ {
31
+ return [self singleWithRuleType: (GHRuleType)theTokenType];
32
+ }
33
+
34
+ - (NSArray<GHToken *> *)tokensWithType:(GHTokenType)theTokenType
35
+ {
36
+ return (NSArray<GHToken *> *)[self itemsWithRuleType: (GHRuleType)theTokenType];
37
+ }
38
+
39
+ - (id)singleWithRuleType:(GHRuleType)theRuleType
40
+ {
41
+ return [[self itemsWithRuleType: theRuleType] firstObject];
42
+ }
43
+
44
+ - (NSArray<NSObject *> *)itemsWithRuleType:(GHRuleType)theRuleType
45
+ {
46
+ NSArray<NSObject *> * items = subitems[@(theRuleType)];
47
+ if (items)
48
+ return items;
49
+
50
+ return [[NSArray<NSObject *> alloc] init];
51
+ }
52
+
53
+ - (void)setSingleWithRuleType:(GHRuleType)theRuleType value:(NSObject *)theValue
54
+ {
55
+ NSMutableArray<NSObject *> * valueArray = [[NSMutableArray<NSObject *> alloc] initWithObjects: theValue ? theValue : [NSNull null], nil];
56
+
57
+ subitems[@(theRuleType)] = valueArray;
58
+ }
59
+
60
+ - (void)addRange:(GHRuleType)theRuleType values:(NSArray<NSObject *> *)theValues
61
+ {
62
+ for (id value in theValues)
63
+ {
64
+ [self addObject: value withRuleType: theRuleType];
65
+ }
66
+ }
67
+
68
+ - (void)addObject:(NSObject *)theObject withRuleType:(GHRuleType)theRuleType
69
+ {
70
+ NSMutableArray<NSObject *> * items = subitems[@(theRuleType)];
71
+ if (!items)
72
+ {
73
+ items = [[NSMutableArray<NSObject *> alloc] init];
74
+ subitems[@(theRuleType)] = items;
75
+ }
76
+ [items addObject: theObject ? theObject : [NSNull null]];
77
+ }
78
+
79
+ @end
@@ -0,0 +1,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "GHHasDescriptionProtocol.h"
3
+ #import "GHHasLocationProtocol.h"
4
+ #import "GHHasStepsProtocol.h"
5
+ #import "GHScenarioDefinition.h"
6
+ @class GHLocation;
7
+
8
+ @interface GHBackground : GHScenarioDefinition
9
+
10
+
11
+
12
+ @end
@@ -0,0 +1,18 @@
1
+ #import "GHBackground.h"
2
+
3
+ #import "GHLocation.h"
4
+
5
+ @interface GHBackground ()
6
+
7
+
8
+ @end
9
+
10
+ @implementation GHBackground
11
+
12
+ - (id)initWithLocation:(GHLocation *)theLocation keyword:(NSString *)theKeyword name:(NSString *)theName description:(NSString *)theDescription steps:(NSArray *)theSteps
13
+ {
14
+ self = [super initWithLocation:theLocation keyword:theKeyword name:theName description:theDescription steps:theSteps];
15
+ return self;
16
+ }
17
+
18
+ @end