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,4 @@
1
+ #import <Foundation/Foundation.h>
2
+ @interface GHStepArgument : NSObject
3
+
4
+ @end
@@ -0,0 +1,5 @@
1
+ #import "GHStepArgument.h"
2
+
3
+ @implementation GHStepArgument
4
+
5
+ @end
@@ -0,0 +1,13 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "GHHasLocationProtocol.h"
3
+
4
+ @class GHLocation;
5
+
6
+ @interface GHTableCell : NSObject <GHHasLocationProtocol>
7
+
8
+ @property (nonatomic, readonly) GHLocation * location;
9
+ @property (nonatomic, readonly) NSString * value;
10
+
11
+ - (id)initWithLocation:(GHLocation *)theLocation value:(NSString *)theValue;
12
+
13
+ @end
@@ -0,0 +1,28 @@
1
+ #import "GHTableCell.h"
2
+
3
+ #import "GHLocation.h"
4
+
5
+ @interface GHTableCell ()
6
+
7
+ @property (nonatomic, strong) GHLocation * location;
8
+ @property (nonatomic, strong) NSString * value;
9
+
10
+ @end
11
+
12
+ @implementation GHTableCell
13
+
14
+ @synthesize location;
15
+ @synthesize value;
16
+
17
+ - (id)initWithLocation:(GHLocation *)theLocation value:(NSString *)theValue
18
+ {
19
+ if (self = [super init])
20
+ {
21
+ location = theLocation;
22
+ value = theValue;
23
+ }
24
+
25
+ return self;
26
+ }
27
+
28
+ @end
@@ -0,0 +1,13 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "GHHasLocationProtocol.h"
3
+
4
+ @class GHTableCell;
5
+
6
+ @interface GHTableRow : NSObject <GHHasLocationProtocol>
7
+
8
+ @property (nonatomic, readonly) GHLocation * location;
9
+ @property (nonatomic, readonly) NSArray<GHTableCell *> * cells;
10
+
11
+ - (id)initWithLocation:(GHLocation *)theLocation cells:(NSArray<GHTableCell *> *)theCells;
12
+
13
+ @end
@@ -0,0 +1,29 @@
1
+ #import "GHTableRow.h"
2
+
3
+ #import "GHLocation.h"
4
+ #import "GHStepArgument.h"
5
+
6
+ @interface GHTableRow ()
7
+
8
+ @property (nonatomic, strong) GHLocation * location;
9
+ @property (nonatomic, strong) NSArray<GHTableCell *> * cells;
10
+
11
+ @end
12
+
13
+ @implementation GHTableRow
14
+
15
+ @synthesize location;
16
+ @synthesize cells;
17
+
18
+ - (id)initWithLocation:(GHLocation *)theLocation cells:(NSArray<GHTableCell *> *)theCells
19
+ {
20
+ if (self = [super init])
21
+ {
22
+ location = theLocation;
23
+ cells = theCells;
24
+ }
25
+
26
+ return self;
27
+ }
28
+
29
+ @end
@@ -0,0 +1,13 @@
1
+ #import <Foundation/Foundation.h>
2
+ @class GHLocation;
3
+
4
+ #import "GHHasLocationProtocol.h"
5
+
6
+ @interface GHTag : NSObject <GHHasLocationProtocol>
7
+
8
+ @property (nonatomic, readonly) GHLocation * location;
9
+ @property (nonatomic, readonly) NSString * name;
10
+
11
+ - (id)initWithLocation:(GHLocation *)theLocation name:(NSString *)theName;
12
+
13
+ @end
@@ -0,0 +1,28 @@
1
+ #import "GHTag.h"
2
+
3
+ #import "GHLocation.h"
4
+
5
+ @interface GHTag ()
6
+
7
+ @property (nonatomic, strong) GHLocation * location;
8
+ @property (nonatomic, strong) NSString * name;
9
+
10
+ @end
11
+
12
+ @implementation GHTag
13
+
14
+ @synthesize location;
15
+ @synthesize name;
16
+
17
+ - (id)initWithLocation:(GHLocation *)theLocation name:(NSString *)theName
18
+ {
19
+ if (self = [super init])
20
+ {
21
+ location = theLocation;
22
+ name = theName;
23
+ }
24
+
25
+ return self;
26
+ }
27
+
28
+ @end
@@ -0,0 +1,26 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "GHGherkinLineProtocol.h"
3
+
4
+ @class GHGherkinLineSpan;
5
+ @class GHGherkinDialect;
6
+ @class GHLocation;
7
+
8
+ #import "GHAstNode.h"
9
+
10
+ @interface GHToken : NSObject
11
+
12
+ @property (nonatomic, readonly, getter=isEOF) BOOL eof;
13
+ @property (nonatomic, strong) id<GHGherkinLineProtocol> line;
14
+ @property (nonatomic, assign) GHTokenType matchedType;
15
+ @property (nonatomic, strong) NSString * matchedKeyword;
16
+ @property (nonatomic, strong) NSString * matchedText;
17
+ @property (nonatomic, strong) NSArray<GHGherkinLineSpan *> * matchedItems;
18
+ @property (nonatomic, assign) NSUInteger matchedIndent;
19
+ @property (nonatomic, strong) GHGherkinDialect * matchedGherkinDialect;
20
+ @property (nonatomic, strong) GHLocation * location;
21
+
22
+ - (id)initWithGherkinLine:(id<GHGherkinLineProtocol>)theGherkinLine location:(GHLocation *)theLocation;
23
+ - (void)detach;
24
+ - (NSString *)tokenValue;
25
+
26
+ @end
@@ -0,0 +1,50 @@
1
+ #import "GHToken.h"
2
+
3
+ #import "GHGherkinLineProtocol.h"
4
+
5
+ #import "GHParser.h"
6
+
7
+ @implementation GHToken
8
+
9
+ @synthesize eof;
10
+ @synthesize line;
11
+ @synthesize matchedType;
12
+ @synthesize matchedKeyword;
13
+ @synthesize matchedText;
14
+ @synthesize matchedItems;
15
+ @synthesize matchedIndent;
16
+ @synthesize matchedGherkinDialect;
17
+ @synthesize location;
18
+
19
+ - (id)initWithGherkinLine:(id<GHGherkinLineProtocol>)theGherkinLine location:(GHLocation *)theLocation
20
+ {
21
+ if (self = [super init])
22
+ {
23
+ line = theGherkinLine;
24
+ location = theLocation;
25
+ }
26
+
27
+ return self;
28
+ }
29
+
30
+ - (void)detach
31
+ {
32
+ [line detach];
33
+ }
34
+
35
+ - (BOOL)isEOF
36
+ {
37
+ return line == nil;
38
+ }
39
+
40
+ - (NSString *)tokenValue
41
+ {
42
+ return [self isEOF] ? @"EOF" : [line lineTextByRemovingIndent: -1];
43
+ }
44
+
45
+ - (NSString *)description
46
+ {
47
+ return [NSString stringWithFormat: @"%d: %@/%@", matchedType, matchedKeyword, matchedText];
48
+ }
49
+
50
+ @end
@@ -0,0 +1,29 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "GHParser.h"
3
+
4
+ @class GHToken;
5
+ @class GHGherkinDialect;
6
+ @class GHGherkinDialectProvider;
7
+
8
+ @interface GHTokenMatcher : NSObject <GHTokenMatcherProtocol>
9
+
10
+ - (GHGherkinDialect *)currentDialect;
11
+ - (id)initWithDialectProvider:(GHGherkinDialectProvider *)theDialectProvider;
12
+ - (id)initWithLanguage:(NSString *)theLanguage;
13
+ - (void)reset;
14
+ - (BOOL)matchEOFWithToken:(GHToken *)theToken;
15
+ - (BOOL)matchOtherWithToken:(GHToken *)theToken;
16
+ - (BOOL)matchEmptyWithToken:(GHToken *)theToken;
17
+ - (BOOL)matchCommentWithToken:(GHToken *)theToken;
18
+ - (BOOL)matchLanguageWithToken:(GHToken *)theToken;
19
+ - (BOOL)matchTagLineWithToken:(GHToken *)theToken;
20
+ - (BOOL)matchFeatureLineWithToken:(GHToken *)theToken;
21
+ - (BOOL)matchBackgroundLineWithToken:(GHToken *)theToken;
22
+ - (BOOL)matchScenarioLineWithToken:(GHToken *)theToken;
23
+ - (BOOL)matchScenarioOutlineLineWithToken:(GHToken *)theToken;
24
+ - (BOOL)matchExamplesLineWithToken:(GHToken *)theToken;
25
+ - (BOOL)matchDocStringSeparatorWithToken:(GHToken *)theToken;
26
+ - (BOOL)matchStepLineWithToken:(GHToken *)theToken;
27
+ - (BOOL)matchTableRowWithToken:(GHToken *)theToken;
28
+
29
+ @end
@@ -0,0 +1,283 @@
1
+ #import "GHTokenMatcher.h"
2
+
3
+ #import "GHGherkinDialectProvider.h"
4
+ #import "GHGherkinLineSpan.h"
5
+ #import "GHToken.h"
6
+ #import "GHAstNode.h"
7
+ #import "GHGherkinDialect.h"
8
+ #import "GHGherkinLanguageConstants.h"
9
+ #import "GHLocation.h"
10
+
11
+ #import "GHParser.h"
12
+
13
+ @interface GHTokenMatcher ()
14
+
15
+ - (NSString *)unescapeDocString:(NSString *)theText;
16
+ - (BOOL)matchDocStringSeparatorWithToken:(GHToken *)theToken separator:(NSString *)theSeparator open:(BOOL)isOpen;
17
+ - (BOOL)matchTitleLineWithToken:(GHToken *)theToken tokenType:(GHTokenType)theTokenType keywords:(NSArray<NSString *> *)theKeywords;
18
+ - (GHParserException *)matcherExceptionWithToken:(GHToken *)theToken message:(NSString *)theMessage;
19
+
20
+ - (void)setTokenMatched:(GHToken *)theToken tokenType:(GHTokenType)theMatchedType text:(NSString *)theText keyword:(NSString *)theKeyword indent:(NSNumber *)theIndent items:(NSArray<GHGherkinLineSpan *> *)theItems;
21
+
22
+ @end
23
+
24
+ @implementation GHTokenMatcher
25
+ {
26
+ id<GHGherkinDialectProviderProtocol> dialectProvider;
27
+ GHGherkinDialect * currentDialect;
28
+ NSString * activeDocStringSeparator;
29
+ NSInteger indentToRemove;
30
+ }
31
+
32
+ - (GHGherkinDialect *)currentDialect
33
+ {
34
+ if (!currentDialect)
35
+ currentDialect = [dialectProvider defaultDialect];
36
+
37
+ return currentDialect;
38
+ }
39
+
40
+ - (id)init
41
+ {
42
+ if (self = [super init])
43
+ {
44
+ dialectProvider = [[GHGherkinDialectProvider alloc] init];
45
+ }
46
+
47
+ return self;
48
+ }
49
+
50
+ - (id)initWithDialectProvider:(id<GHGherkinDialectProviderProtocol>)theDialectProvider
51
+ {
52
+ if (self = [super init])
53
+ {
54
+ dialectProvider = theDialectProvider;
55
+ }
56
+
57
+ return self;
58
+ }
59
+
60
+ - (id)initWithLanguage:(NSString *)theLanguage
61
+ {
62
+ return [self initWithDialectProvider: [[GHGherkinDialectProvider alloc] initWithLanguage: theLanguage]];
63
+ }
64
+
65
+ - (void)reset
66
+ {
67
+ activeDocStringSeparator = nil;
68
+ indentToRemove = 0;
69
+ if (currentDialect != [dialectProvider defaultDialect])
70
+ currentDialect = [dialectProvider defaultDialect];
71
+ }
72
+
73
+ - (void)setTokenMatched:(GHToken *)theToken tokenType:(GHTokenType)theMatchedType text:(NSString *)theText keyword:(NSString *)theKeyword indent:(NSNumber *)theIndent items:(NSArray<GHGherkinLineSpan *> *)theItems
74
+ {
75
+ [theToken setMatchedType: theMatchedType];
76
+ [theToken setMatchedKeyword: theKeyword];
77
+ [theToken setMatchedText: theText];
78
+ [theToken setMatchedItems: theItems];
79
+ [theToken setMatchedGherkinDialect: currentDialect];
80
+ [theToken setMatchedIndent: theIndent ? [theIndent integerValue] : [theToken line] ? [[theToken line] indent] : 0];
81
+
82
+ [theToken setLocation: [[GHLocation alloc] initWithLine: [[theToken location] line] column: [theToken matchedIndent] + 1]];
83
+ }
84
+
85
+ - (BOOL)matchEOFWithToken:(GHToken *)theToken
86
+ {
87
+ if ([theToken isEOF])
88
+ {
89
+ [self setTokenMatched: theToken tokenType: GHTokenTypeEOF text: nil keyword: nil indent: nil items: nil];
90
+
91
+ return YES;
92
+ }
93
+
94
+ return NO;
95
+ }
96
+
97
+ - (BOOL)matchOtherWithToken:(GHToken *)theToken
98
+ {
99
+ NSString * text = [[theToken line] lineTextByRemovingIndent: indentToRemove]; //take the entire line, except removing DocString indents
100
+ [self setTokenMatched: theToken tokenType: GHTokenTypeOther text: [self unescapeDocString: text] keyword: nil indent: @(0) items: nil];
101
+
102
+ return YES;
103
+ }
104
+
105
+ - (BOOL)matchEmptyWithToken:(GHToken *)theToken
106
+ {
107
+ if ([[theToken line] empty])
108
+ {
109
+ [self setTokenMatched: theToken tokenType: GHTokenTypeEmpty text: nil keyword: nil indent: nil items: nil];
110
+
111
+ return YES;
112
+ }
113
+
114
+ return NO;
115
+ }
116
+
117
+ - (BOOL)matchCommentWithToken:(GHToken *)theToken
118
+ {
119
+ if ([[theToken line] hasPrefix: GHCommentPrefix])
120
+ {
121
+ NSString * text = [[theToken line] lineTextByRemovingIndent: 0]; //take the entire line
122
+ [self setTokenMatched: theToken tokenType: GHTokenTypeComment text: text keyword: nil indent: @(0) items: nil];
123
+
124
+ return YES;
125
+ }
126
+ return NO;
127
+ }
128
+
129
+ - (GHParserException *)matcherExceptionWithToken:(GHToken *)theToken message:(NSString *)theMessage
130
+ {
131
+ GHLocation * exceptionLocation = [[GHLocation alloc] initWithLine: [[theToken location] line] column: [[theToken line] indent] + 1];
132
+ return [[GHAstBuilderException alloc] initWithMessage: theMessage location: exceptionLocation];
133
+ }
134
+
135
+ - (BOOL)matchLanguageWithToken:(GHToken *)theToken
136
+ {
137
+ NSRegularExpression * regularExpression = [NSRegularExpression regularExpressionWithPattern: @"^\\s*#\\s*language\\s*:\\s*([a-zA-Z\\-_]+)\\s*$" options: 0 error: nil];
138
+ NSString * lineText = [[theToken line] lineTextByRemovingIndent: 0];
139
+ NSArray<NSTextCheckingResult *> * matches = [regularExpression matchesInString: lineText options: 0 range: NSMakeRange(0, [lineText length])];
140
+ if ([matches count])
141
+ {
142
+ NSRange range = [[matches firstObject] rangeAtIndex: 1];
143
+ if (range.location != NSNotFound)
144
+ {
145
+ NSString * language = [lineText substringWithRange: range];
146
+ [self setTokenMatched: theToken tokenType: GHTokenTypeLanguage text: language keyword: nil indent: nil items: nil];
147
+
148
+ //@try
149
+ //{
150
+ currentDialect = [dialectProvider dialectWithLanguage: language location: [theToken location]];
151
+ //}
152
+ //@catch (NSException * exception)
153
+ //{
154
+ // @throw [self matcherExceptionWithToken: theToken message: [exception reason]];
155
+ //}
156
+
157
+ return YES;
158
+ }
159
+ }
160
+ return NO;
161
+ }
162
+
163
+ - (BOOL)matchTagLineWithToken:(GHToken *)theToken
164
+ {
165
+ if ([[theToken line] hasPrefix: GHTagPrefix])
166
+ {
167
+ [self setTokenMatched: theToken tokenType: GHTokenTypeTagLine text: nil keyword: nil indent: nil items: [[theToken line] tags]];
168
+
169
+ return YES;
170
+ }
171
+ return NO;
172
+ }
173
+
174
+ - (BOOL)matchFeatureLineWithToken:(GHToken *)theToken
175
+ {
176
+ return [self matchTitleLineWithToken: theToken tokenType: GHTokenTypeFeatureLine keywords: [currentDialect featureKeywords]];
177
+ }
178
+
179
+ - (BOOL)matchBackgroundLineWithToken:(GHToken *)theToken
180
+ {
181
+ return [self matchTitleLineWithToken: theToken tokenType: GHTokenTypeBackgroundLine keywords: [currentDialect backgroundKeywords]];
182
+ }
183
+
184
+ - (BOOL)matchScenarioLineWithToken:(GHToken *)theToken
185
+ {
186
+ return [self matchTitleLineWithToken: theToken tokenType: GHTokenTypeScenarioLine keywords: [currentDialect scenarioKeywords]];
187
+ }
188
+
189
+ - (BOOL)matchScenarioOutlineLineWithToken:(GHToken *)theToken
190
+ {
191
+ return [self matchTitleLineWithToken: theToken tokenType: GHTokenTypeScenarioOutlineLine keywords: [currentDialect scenarioOutlineKeywords]];
192
+ }
193
+
194
+ - (BOOL)matchExamplesLineWithToken:(GHToken *)theToken
195
+ {
196
+ return [self matchTitleLineWithToken: theToken tokenType: GHTokenTypeExamplesLine keywords: [currentDialect examplesKeywords]];
197
+ }
198
+
199
+ - (BOOL)matchTitleLineWithToken:(GHToken *)theToken tokenType:(GHTokenType)theTokenType keywords:(NSArray<NSString *> *)theKeywords
200
+ {
201
+ for (NSString * keyword in theKeywords)
202
+ {
203
+ if ([[theToken line] hasTitleKeywordPrefix: keyword])
204
+ {
205
+ NSString * title = [[theToken line] trimmedRest: ([keyword length] + [GHTitleKeywordSeparator length])];
206
+ [self setTokenMatched: theToken tokenType: theTokenType text: title keyword: keyword indent: nil items: nil];
207
+
208
+ return YES;
209
+ }
210
+ }
211
+ return NO;
212
+ }
213
+
214
+ - (BOOL)matchDocStringSeparatorWithToken:(GHToken *)theToken
215
+ {
216
+ return activeDocStringSeparator == nil
217
+ // open
218
+ ? ([self matchDocStringSeparatorWithToken: theToken separator: GHDocStringSeparator open: YES] ||
219
+ [self matchDocStringSeparatorWithToken: theToken separator: GHDocStringAlternativeSeparator open: YES])
220
+ // close
221
+ : [self matchDocStringSeparatorWithToken: theToken separator: activeDocStringSeparator open: NO];
222
+ }
223
+
224
+ - (BOOL)matchDocStringSeparatorWithToken:(GHToken *)theToken separator:(NSString *)theSeparator open:(BOOL)isOpen
225
+ {
226
+ if ([[theToken line] hasPrefix: theSeparator])
227
+ {
228
+ NSString * contentType = nil;
229
+ if (isOpen)
230
+ {
231
+ contentType = [[theToken line] trimmedRest: [theSeparator length]];
232
+ activeDocStringSeparator = theSeparator;
233
+ indentToRemove = [[theToken line] indent];
234
+ }
235
+ else
236
+ {
237
+ activeDocStringSeparator = nil;
238
+ indentToRemove = 0;
239
+ }
240
+
241
+ [self setTokenMatched: theToken tokenType: GHTokenTypeDocStringSeparator text: contentType keyword: nil indent: nil items: nil];
242
+
243
+ return YES;
244
+ }
245
+ return NO;
246
+ }
247
+
248
+
249
+ - (BOOL)matchStepLineWithToken:(GHToken *)theToken
250
+ {
251
+ NSArray<NSString *> * keywords = [currentDialect stepKeywords];
252
+ for (NSString * keyword in keywords)
253
+ {
254
+ if ([[theToken line] hasPrefix: keyword])
255
+ {
256
+ NSString * stepText = [[theToken line] trimmedRest: [keyword length]];
257
+ [self setTokenMatched: theToken tokenType: GHTokenTypeStepLine text: stepText keyword: keyword indent: nil items: nil];
258
+
259
+ return YES;
260
+ }
261
+ }
262
+
263
+ return NO;
264
+ }
265
+
266
+ - (BOOL)matchTableRowWithToken:(GHToken *)theToken
267
+ {
268
+ if ([[theToken line] hasPrefix: GHTableCellSeparator])
269
+ {
270
+ [self setTokenMatched: theToken tokenType: GHTokenTypeTableRow text: nil keyword: nil indent: nil items: [[theToken line] tableCells]];
271
+
272
+ return YES;
273
+ }
274
+
275
+ return NO;
276
+ }
277
+
278
+ - (NSString *)unescapeDocString:(NSString *)theText
279
+ {
280
+ return activeDocStringSeparator != nil ? [theText stringByReplacingOccurrencesOfString: @"\\\"\\\"\\\"" withString: @"\"\"\""] : theText;
281
+ }
282
+
283
+ @end