Created
April 26, 2023 22:21
-
-
Save bartekpacia/977a81f3bf57aa99a130054aca949e0d to your computer and use it in GitHub Desktop.
$ clang -framework Foundation file.m -o file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface PatrolIntegrationTestRunner : NSObject | |
+ (NSString *)createMethodNameFromPatrolGeneratedGroup:(NSString *)dartTestGroup; | |
@end | |
@implementation PatrolIntegrationTestRunner | |
- (instancetype)init { | |
self = [super init]; | |
return self; | |
} | |
+ (NSString *)createMethodNameFromPatrolGeneratedGroup:(NSString *)dartGroupName { | |
NSMutableString *temp = [NSMutableString stringWithString:dartGroupName]; | |
// Separate directories from the file name | |
// Split the string by dot | |
NSArray<NSString *> *components = [[temp componentsSeparatedByString:@"."] mutableCopy]; | |
NSLog(@"Components: %@", components); | |
// Convert the filename from snake_case to camelCase | |
NSMutableString *fileName = [components.lastObject mutableCopy]; | |
NSArray *words = [fileName componentsSeparatedByString:@"_"]; | |
[fileName setString:words[0]]; | |
for (NSUInteger i = 1; i < words.count; i++) { | |
NSString *word = words[i]; | |
NSString *firstLetter = [[word substringToIndex:1] capitalizedString]; | |
NSString *restOfWord = [word substringFromIndex:1]; | |
NSString *camelCaseWord = [firstLetter stringByAppendingString:restOfWord]; | |
[fileName appendString:camelCaseWord]; | |
} | |
NSMutableArray<NSString * > *pathComponents = [[components subarrayWithRange:NSMakeRange(0, components.count - 1)] mutableCopy]; | |
if (pathComponents.count > 0) { | |
NSString *path = [pathComponents componentsJoinedByString:@"_"]; | |
return [NSString stringWithFormat:@"%@_%@", path, fileName]; | |
} else { | |
return fileName; | |
} | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSLog(@"Hello, World!"); | |
NSLog(@"Test case 1: %@", [PatrolIntegrationTestRunner createMethodNameFromPatrolGeneratedGroup:@""]); | |
NSLog(@"Test case 2: %@", [PatrolIntegrationTestRunner createMethodNameFromPatrolGeneratedGroup:@"example_test"]); | |
NSLog(@"Test case 3: %@", [PatrolIntegrationTestRunner createMethodNameFromPatrolGeneratedGroup:@"example.example_test"]); | |
NSLog(@"Test case 4: %@", [PatrolIntegrationTestRunner createMethodNameFromPatrolGeneratedGroup:@"very.deep.example_test"]); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment