forked from onevcat/VVDocumenter-Xcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVVTestHelper.m
More file actions
executable file
·147 lines (118 loc) · 6.09 KB
/
VVTestHelper.m
File metadata and controls
executable file
·147 lines (118 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// VVTestHelper.m
// VVDocumenter-Xcode
//
// Created by 王 巍 on 13-7-19.
// Copyright (c) 2013年 OneV's Den. All rights reserved.
//
#import "VVTestHelper.h"
@interface NSArray(vv_Removing)
-(NSArray*)arrayByRemovingObject:(id)obj;
@end
@implementation NSArray (vv_Removing)
-(NSArray*)arrayByRemovingObject:(id)obj
{
NSArray* newArray = [NSArray array];
NSUInteger indexOfObj = [self indexOfObject:obj];
newArray = [self subarrayWithRange:NSMakeRange(0, indexOfObj)];
newArray = [newArray arrayByAddingObjectsFromArray:[self subarrayWithRange:NSMakeRange(indexOfObj+1, self.count - indexOfObj-1)]];
return newArray;
}
@end
static NSArray *_typeStrings;
@implementation VVTestHelper
+(NSArray *) testCodes
{
NSArray *methods = @[@"+ (ADTransition *)nullTransition;",
@" - (BOOL) application: (UIApplication *) application \n didFinishLaunchingWithOptions: (NSDictionary *) launchOptions;",
@"- (id)initWithDuration:(CFTimeInterval)duration sourceRect:(CGRect)sourceRect {"];
NSArray *functions = @[@"void dosomething ( int x, int y );",
@"int main(int argc, char *argv[]) \n {",
@"void NoParamFunc();",
@"typeof void(^IBLShareSuccessBlock)(ShareType type, SSPublishContentState state, id<ISSStatusInfo> statusInfo, BOOL end);"];
NSArray *properties = @[@"@property (nonatomic, copy ) NSString *code;",
@" @property ( nonatomic, strong ) Miao* test;",
@"@property ( assign, strong ) int test;"];
NSArray *macros = @[@"#define MAX(A,B) ({",
@"#define MIN(A,B) ((A) < (B) ? (A) : (B))",
@"#define ABS(A) ((A) < 0 ? (-(A)) : (A))"];
NSArray *structs = @[@"struct Foo \n {",
@" struct node {",
@"struct objc_object {"];
NSArray *enums = @[@"typedef NS_ENUM {",
@"typedef NS_ENUM \n {",
@" typedef NS_ENUM{"];
NSArray *unions = @[@"union {",
@" union \n {",
@" union{"];
NSArray *others = @[@"options = options | NSRegularExpressionDotMatchesLineSeparators;",
@"if (resultUntilSemiColon && resultUntilBrace) {",
@"static dispatch_once_t once;"];
NSArray *compileKeywords = @[@"@interface VVDocumenter : NSObject \n {",
@"@interface SyntaxTests()\n@property (nonatomic, retain) NSArray* inputs;",
@"@implementation SyntaxTests\n\n- (void)setUp\n{",
@"@interface A (a)\n- (id) foo;"];
return @[methods,functions,properties,macros,structs,enums,unions,others,compileKeywords];
}
+(NSArray *) uniformCodes
{
NSArray *methods = @[@"+(ADTransition *)nullTransition;",
@" -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;",
@"-(id)initWithDuration:(CFTimeInterval)duration sourceRect:(CGRect)sourceRect {"];
NSArray *functions = @[@"void dosomething( int x, int y );",
@"int main(int argc, char *argv[]){",
@"void NoParamFunc();",
@"typeof void(^IBLShareSuccessBlock)(ShareType type, SSPublishContentState state, id<ISSStatusInfo> statusInfo, BOOL end);"];
NSArray *properties = @[@"@property(nonatomic, copy )NSString *code;",
@" @property( nonatomic, strong )Miao* test;",
@"@property( assign, strong )int test;"];
NSArray *macros = @[@"#define MAX(A,B)({",
@"#define MIN(A,B)((A)<(B)?(A):(B))",
@"#define ABS(A)((A)< 0 ?(-(A)) :(A))"];
NSArray *structs = @[@"struct Foo {",
@" struct node {",
@"struct objc_object {"];
NSArray *enums = @[@"typedef NS_ENUM {",
@"typedef NS_ENUM {",
@" typedef NS_ENUM{"];
NSArray *unions = @[@"union {",
@" union {",
@" union{"];
NSArray *others = @[@"options = options | NSRegularExpressionDotMatchesLineSeparators;",
@"if(resultUntilSemiColon && resultUntilBrace){",
@"static dispatch_once_t once;"];
NSArray *compileKeywords = @[@"@interface VVDocumenter : NSObject {",
@"@interface SyntaxTests()@property(nonatomic, retain)NSArray* inputs;",
@"@implementation SyntaxTests -(void)setUp {",
@"@interface A(a)-(id)foo;"];
return @[methods,functions,properties,macros,structs,enums,unions,others,compileKeywords];
}
+(NSArray *) arrayOfExceptCodeType:(NSString *)type
{
if (!_typeStrings) {
//Save all type specify method names in NSString+VVSyntax
_typeStrings = @[@"vv_isObjCMethod",
@"vv_isCFunction",
@"vv_isProperty",
@"vv_isMacro",
@"vv_isStruct",
@"vv_isEnum",
@"vv_isUnion",
@"vv_isComplieKeyword"];
}
return [_typeStrings arrayByRemovingObject:type];
}
+(BOOL) performSyntaxMethod:(NSString *)selectorString onString:(NSString *)codestring {
SEL selector =NSSelectorFromString(selectorString);
BOOL returnValue = NO;
if ([codestring respondsToSelector:selector]) {
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[[codestring class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:codestring];
[invocation invoke];
[invocation getReturnValue:&returnValue];
}
return returnValue;
}
@end