-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTestRuntimeParsing.m
More file actions
76 lines (56 loc) · 2.1 KB
/
TestRuntimeParsing.m
File metadata and controls
76 lines (56 loc) · 2.1 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
/**
Copyright (c) 2014 Quentin Mathe
License: MIT (see COPYING)
*/
#import "TestCommon.h"
@interface TestRuntimeParsing : TestCommon
@end
@implementation TestRuntimeParsing
- (SCKClass *)parsedClassForName: (NSString *)className
{
SCKClass *class = [SCKClass new];
return [class initWithClass: NSClassFromString(className)];
}
- (void)testClass
{
SCKClass *classA = [self parsedClassForName: @"A"];
UKNotNil(classA);
UKStringsEqual(@"A", [classA name]);
}
- (void)testMethod
{
SCKClass *classA = [self parsedClassForName: @"A"];
NSMutableDictionary *methods = [classA methods];
[methods removeObjectForKey: @".cxx_destruct"];
NSSet *methodNames = S(@"text", @"setText:", @"wakeUpAtDate:",
@"sleepLater:", @"methodInCategory");
UKObjectsEqual(methodNames, SA([methods allKeys]));
UKObjectsEqual(SA([methods allKeys]), SA((id)[[[methods allValues] mappedCollection] name]));
SCKMethod *sleepLater = [methods objectForKey: @"sleepLater:"];
/* The numbers in the signature encoding are platform-dependent, but the other characters
remain valid accross platforms */
NSCharacterSet *charset = [NSCharacterSet decimalDigitCharacterSet];
NSString *sleepLaterTypeEncoding = [[[sleepLater typeEncoding]
componentsSeparatedByCharactersInSet: charset] componentsJoinedByString: @""];
UKObjectsEqual(classA, [sleepLater parent]);
UKStringsEqual(@"v@:Q", sleepLaterTypeEncoding);
}
- (void)testProperty
{
SCKClass *classB = [self parsedClassForName: @"B"];
NSMutableArray *properties = [classB properties];
UKObjectsEqual(A(@"button", @"text2", @"text3"), [[properties mappedCollection] name]);
SCKProperty *button = [properties firstObject];
UKObjectsEqual(classB, [button parent]);
UKStringsEqual(@"T@\"NSButton\",&,N,Vbutton", [button typeEncoding]);
}
- (void)testIVar
{
SCKClass *classC = [self parsedClassForName: @"C"];
NSMutableArray *ivars = [classC ivars];
UKObjectsEqual(A(@"ivar1", @"ivar2", @"ivar3"), [[ivars mappedCollection] name]);
SCKIvar *ivar1 = [ivars firstObject];
UKObjectsEqual(classC, [ivar1 parent]);
UKStringsEqual(@"@\"NSString\"", [ivar1 typeEncoding]);
}
@end