Skip to content

Commit

Permalink
完善关于函数返回值的TypeEncode判断以及单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFruity committed Dec 4, 2020
1 parent 317c987 commit 26f2de2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
3 changes: 0 additions & 3 deletions OCRunner/ORTypeVarPair+TypeEncode.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ - (const char *)typeEncode{
// Block的typeEncode
if (self.var.isBlock) {
return @"@?".UTF8String;
// 函数指针的typeEncode
}else if (self.var.ptCount > 0){
type = TypeUnKnown;
}
}
if (type == TypeStruct && self.var.ptCount == 0) {
Expand Down
21 changes: 17 additions & 4 deletions OCRunnerTests/ORTestWithObjc.m
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,27 @@ - (void)testMutiTypeCalculate{
- (void)testCFunctionReturnTypeEncode{
NSString * source =
@"CGFloat testFunctionReturnType(int arg);"
@"CGFloat (***testFunctionReturnType)(int arg);";
@"CGFloat (***testFunctionReturnType)(int arg);"
@"CGFloat *testFunctionReturnType(int arg);"
@"XCTestCase *testFunctionReturnType(int arg);"
@"XCTestCase *(^testFunctionReturnType)(int arg);"
;
AST *ast = [OCParser parseSource:source];
ORDeclareExpression *declare1 = ast.globalStatements.firstObject;
ORDeclareExpression *declare2 = ast.globalStatements.lastObject;
ORDeclareExpression *declare1 = ast.globalStatements[0];
ORDeclareExpression *declare2 = ast.globalStatements[1];
ORDeclareExpression *declare3 = ast.globalStatements[2];
ORDeclareExpression *declare4 = ast.globalStatements[3];
ORDeclareExpression *declare5 = ast.globalStatements[4];
NSString *returnType1 = [NSString stringWithUTF8String:declare1.pair.typeEncode];
XCTAssert([returnType1 isEqualToString:@"d"], @"%@", returnType1);
NSString *returnType2 = [NSString stringWithUTF8String:declare2.pair.typeEncode];
XCTAssert([returnType2 isEqualToString:@"^^^"], @"%@", returnType2);
XCTAssert([returnType2 isEqualToString:@"^^^d"], @"%@", returnType2);
NSString *returnType3 = [NSString stringWithUTF8String:declare3.pair.typeEncode];
XCTAssert([returnType3 isEqualToString:@"^d"], @"%@", returnType3);
NSString *returnType4 = [NSString stringWithUTF8String:declare4.pair.typeEncode];
XCTAssert([returnType4 isEqualToString:@"@"], @"%@", returnType4);
NSString *returnType5 = [NSString stringWithUTF8String:declare5.pair.typeEncode];
XCTAssert([returnType5 isEqualToString:@"@?"], @"%@", returnType5);
}
- (void)testOCRecursiveFunctionPerformanceExample {
[self measureBlock:^{
Expand Down

0 comments on commit 26f2de2

Please sign in to comment.