Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes an issue with regex's matching exactly the beginning and end #26

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cucumberish/Core/Managers/CCIStepsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ - (CCIStepDefinition *)findDefinitionForStep:(CCIStep *)step amongDefinitions:(N
definition.matchedValues = values;
retDefinition = definition;
break;
} else if (match != nil && match.numberOfRanges == 1) {
//this case means there was a match of just the text. This can occur if the regex has the start and end characters ^foobar$
retDefinition = [d copy];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ @interface CucumberFeatureSteps()

@property (nonatomic,strong) NSMutableDictionary* savedValues;
@property (nonatomic,strong) NSMutableArray* savedAStepValues;
@property (nonatomic,assign) BOOL exactMatchTriggered;
@property (nonatomic,assign) BOOL inexactMatchTriggered;

@end

Expand Down Expand Up @@ -110,7 +112,7 @@ -(void)setup
}
});

Match(@[@"Given",@"And"],@"a step(?: has an optional match \"([a-z]+)\")?", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
Match(@[@"Given",@"And"],@"^a step(?: has an optional match \"([a-z]+)\")?$", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
if (args.count == 0) {
[self.savedAStepValues addObject:[NSNull null]];
} else {
Expand All @@ -128,7 +130,7 @@ -(void)setup
CCIAssert(found, @"Expected to find a NSNull, found @%",self.savedAStepValues);
});

Match(@[@"Then",@"And"],@"the step \"a step\" had \"([a-z]+) matched for the optional parameter", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
Match(@[@"Then",@"And"],@"the step \"a step\" had \"([a-z]+)\" matched for the optional parameter", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
__block BOOL found = NO;
for (id obj in self.savedAStepValues) {
if ([obj isKindOfClass:[NSString class]] && [obj isEqualToString:args[0]]) {
Expand All @@ -137,6 +139,24 @@ -(void)setup
}
CCIAssert(found, @"Expected to find a %@, found @%",args[0],self.savedAStepValues);
});

Given(@"^a step that matches beginning and end$", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
self.exactMatchTriggered = YES;
});

And(@"a step that just matches strings", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
self.inexactMatchTriggered = YES;
});


Then(@"the exact match passed", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
CCIAssert(self.exactMatchTriggered, @"Expected the exact match to be triggered");
});

And(@"the inexact match passed", ^(NSArray<NSString *> *args, NSDictionary *userInfo) {
CCIAssert(self.inexactMatchTriggered, @"Expected the inexact match to be triggered");
});


}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Feature: Handle Exact Matches
Cucumberish shall support matching exact strings, beginning and end

Scenario: Exact and Inexact Matches
Given a step that matches beginning and end
And a step that just matches strings
When cucumber is executed
Then the exact match passed
And the inexact match passed