blob: eec76eef5661f2b038dcd9197b2436b678d7abde (
plain)
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
|
(defpackage #:mulk.objective-cl.tests
(:nicknames #:objcl-tests #:objective-cl-tests #:mulk.objcl-tests)
(:use #:lift #:mulk.objective-cl #:cl)
(:export #:run-all-tests))
(in-package #:mulk.objective-cl.tests)
(eval-when (:compile-toplevel)
(objcl:install-reader-syntax))
(defun run-all-tests ()
(objcl:initialise-runtime)
(run-tests :suite 'objective-cl))
(deftestsuite objective-cl ()
())
(defrandom-instance double objective-cl
(if (zerop (random 2))
(random most-positive-double-float)
(- (random (abs most-negative-double-float)))))
(deftestsuite base-functions (objective-cl)
()
(:equality-test #'objc-equal)
(:tests
((ensure-same (find-objc-class 'ns-object)
(find-objc-class "NSObject")))
((ensure-null (find-objc-class 'nsobject)))
((ensure-same (find-objc-class 'ns-method-invocation)
(find-objc-class "NSMethodInvocation")))
((ensure-null (find-selector "mulkyStuff:withMagic:")))
((ensure-same (find-selector "self")
(find-selector '(self))))
((ensure-same (find-selector "stringWithCString:")
(find-selector '(:string-with-c-string))))
((ensure-same (find-selector "stringWithCString:encoding:")
(find-selector '(:string-with-c-string :encoding))))))
(deftestsuite method-invocation (objective-cl)
()
(:equality-test #'objc-equal)
(:tests
((ensure-error [NSObject 300]))
((ensure-error [300 self]))
((ensure-error ["abc" self]))
((ensure-error [NSObject selph]))
((ensure-same [NSObject self]
[NSObject class]))
((ensure-different [NSObject self]
[NSNumber self]))
((ensure-same [NSString stringWithCString: "Mulk."]
[NSString stringWithCString: "Mulk."]))
((ensure-different [NSString stringWithCString: "Mulk."]
[NSString stringWithCString: "Klum."]))
((ensure [NSString isSubclassOfClass: [NSObject class]]))
((ensure [NSString performSelector:
(selector "isSubclassOfClass:")
withObject: [NSObject class]]))))
(deftestsuite data-coercion (objective-cl)
()
(:equality-test #'objc-equal)
(:tests
((ensure-same [NSString stringWithCString: "Mulk."]
[NSString stringWithCString: "Mulk." encoding: 4]))
((ensure-same [NSString respondsToSelector: (selector "new")]
[NSString respondsToSelector: 'new]))
((ensure-same [NSString respondsToSelector: (selector "new")]
[NSString respondsToSelector: "new"]))
((ensure (typep [NSString isEqual: [NSString self]] 'boolean)))
((ensure (typep [NSString isEqual: [NSObject self]] 'boolean)))))
(deftestsuite numbers (objective-cl)
()
(:equality-test #'objc-equal)
(:tests
((ensure-same [[NSDecimalNumber
decimalNumberWithString:
[NSString stringWithCString:
"-12345"]]
doubleValue]
-12345d0))))
(deftestsuite exception-handling (objective-cl)
()
(:equality-test #'objc-equal)
(:tests
((ensure (typep (handler-case
[NSString selph]
(exception (e) e))
'exception)))))
(deftestsuite reader-syntax (objective-cl)
()
(:equality-test #'objc-equal)
(:tests
((ensure-same [NSObject self]
(find-objc-class 'ns-object)))
((ensure-same [NSString stringWithCString: "Mulk."]
(invoke (find-objc-class 'ns-string)
:string-with-c-string "Mulk.")))
((ensure-same [NSString stringWithCString: "Mulk." encoding: 4]
(invoke (find-objc-class 'ns-string)
:string-with-c-string "Mulk." :encoding 4)))
((ensure-same [NSString performSelector:
(selector "isSubclassOfClass:")
withObject: [NSObject self]]
(invoke (find-objc-class 'ns-string)
:perform-selector (selector "isSubclassOfClass:")
:with-object (invoke
(find-objc-class 'ns-object)
'self))))))
|