Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Fix parsing of predicate string #456

Closed
wants to merge 1 commit into from
Closed
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ Resources/WebDriverAgent.bundle

# Modules map recreated on each build
Modules/module.modulemap

# test run
*.trace
10 changes: 5 additions & 5 deletions WebDriverAgentLib/Categories/NSExpression+FBFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ + (instancetype)fb_wdExpressionWithExpression:(NSExpression *)input
if ([input expressionType] != NSKeyPathExpressionType) {
return input;
}
NSString *actualPropName = [input keyPath];
NSUInteger dotPos = [actualPropName rangeOfString:@"."].location;
NSString *propName = [input keyPath];
NSUInteger dotPos = [propName rangeOfString:@"."].location;
if (NSNotFound != dotPos) {
actualPropName = [actualPropName substringToIndex:dotPos];
NSString *suffix = [actualPropName substringFromIndex:dotPos];
NSString *actualPropName = [propName substringToIndex:dotPos];
NSString *suffix = [propName substringFromIndex:(dotPos + 1)];
return [NSExpression expressionForKeyPath:[NSString stringWithFormat:@"%@.%@", [FBElementUtils wdAttributeNameForAttributeName:actualPropName], suffix]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add unit test for such case? The tests container is located in UnitTests folder, NSExpressionFBFormatTests.m file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the existing unit tests to make useful assertions.

}
return [NSExpression expressionForKeyPath:[FBElementUtils wdAttributeNameForAttributeName:actualPropName]];
return [NSExpression expressionForKeyPath:[FBElementUtils wdAttributeNameForAttributeName:propName]];
}

@end
15 changes: 10 additions & 5 deletions WebDriverAgentTests/UnitTests/NSExpressionFBFormatTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,36 @@ @implementation NSExpressionFBFormatTests
- (void)testFormattingForExistingProperty
{
NSExpression *expr = [NSExpression expressionWithFormat:@"wdName"];
XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]);
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"wdName");
}

- (void)testFormattingForExistingPropertyShortcut
{
NSExpression *expr = [NSExpression expressionWithFormat:@"visible"];
XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]);
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"isWDVisible");
}

- (void)testFormattingForValidExpressionWOKeys
{
NSExpression *expr = [NSExpression expressionWithFormat:@"1"];
XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]);
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop constantValue], [NSNumber numberWithInt:1]);
}

- (void)testFormattingForExistingComplexProperty
{
NSExpression *expr = [NSExpression expressionWithFormat:@"wdRect.x"];
XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]);
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"wdRect.x");
}

- (void)testFormattingForExistingComplexPropertyWOPrefix
{
NSExpression *expr = [NSExpression expressionWithFormat:@"rect.x"];
XCTAssertNotNil([NSExpression fb_wdExpressionWithExpression:expr]);
NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
XCTAssertEqualObjects([prop keyPath], @"wdRect.x");
}

- (void)testFormattingForPredicateWithUnknownKey
Expand Down