Mercurial > projects > dstep
comparison dstep/foundation/NSScriptWhoseTests.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
comparison
equal
deleted
inserted
replaced
13:4f583f7e242e | 14:89f3c3ef1fd2 |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSScriptWhoseTests; | |
8 | |
9 import dstep.foundation.NSArray; | |
10 import dstep.foundation.NSObject; | |
11 import dstep.foundation.NSScriptObjectSpecifier; | |
12 import dstep.foundation.NSString; | |
13 import dstep.objc.bridge.Bridge; | |
14 import dstep.objc.objc : id; | |
15 | |
16 alias NSUInteger NSTestComparisonOperation; | |
17 | |
18 enum | |
19 { | |
20 NSEqualToComparison = 0, | |
21 NSLessThanOrEqualToComparison, | |
22 NSLessThanComparison, | |
23 NSGreaterThanOrEqualToComparison, | |
24 NSGreaterThanComparison, | |
25 NSBeginsWithComparison, | |
26 NSEndsWithComparison, | |
27 NSContainsComparison | |
28 } | |
29 | |
30 class NSLogicalTest : NSScriptWhoseTest | |
31 { | |
32 mixin ObjcWrap; | |
33 | |
34 Object initAndTestWithTests (NSArray subTests) | |
35 { | |
36 return invokeObjcSelf!(Object, "initAndTestWithTests:", NSArray)(subTests); | |
37 } | |
38 | |
39 this (NSArray subTests) | |
40 { | |
41 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
42 id result = Bridge.invokeObjcMethod!(id, "initAndTestWithTests:", NSArray)(objcObject, subTests); | |
43 | |
44 if (result) | |
45 objcObject = ret; | |
46 | |
47 dObject = this; | |
48 } | |
49 | |
50 Object initOrTestWithTests (NSArray subTests) | |
51 { | |
52 return invokeObjcSelf!(Object, "initOrTestWithTests:", NSArray)(subTests); | |
53 } | |
54 | |
55 this (NSArray subTests) | |
56 { | |
57 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
58 id result = Bridge.invokeObjcMethod!(id, "initOrTestWithTests:", NSArray)(objcObject, subTests); | |
59 | |
60 if (result) | |
61 objcObject = ret; | |
62 | |
63 dObject = this; | |
64 } | |
65 | |
66 Object initNotTestWithTest (NSScriptWhoseTest subTest) | |
67 { | |
68 return invokeObjcSelf!(Object, "initNotTestWithTest:", NSScriptWhoseTest)(subTest); | |
69 } | |
70 | |
71 this (NSScriptWhoseTest subTest) | |
72 { | |
73 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
74 id result = Bridge.invokeObjcMethod!(id, "initNotTestWithTest:", NSScriptWhoseTest)(objcObject, subTest); | |
75 | |
76 if (result) | |
77 objcObject = ret; | |
78 | |
79 dObject = this; | |
80 } | |
81 } | |
82 | |
83 class NSSpecifierTest : NSScriptWhoseTest | |
84 { | |
85 mixin ObjcWrap; | |
86 | |
87 Object initWithObjectSpecifier (NSScriptObjectSpecifier obj1, uint compOp, Object obj2) | |
88 { | |
89 return invokeObjcSelf!(Object, "initWithObjectSpecifier:comparisonOperator:testObject:", NSScriptObjectSpecifier, uint, Object)(obj1, compOp, obj2); | |
90 } | |
91 | |
92 this (NSScriptObjectSpecifier obj1, uint compOp, Object obj2) | |
93 { | |
94 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
95 id result = Bridge.invokeObjcMethod!(id, "initWithObjectSpecifier:comparisonOperator:testObject:", NSScriptObjectSpecifier, uint, Object)(objcObject, obj1, compOp, obj2); | |
96 | |
97 if (result) | |
98 objcObject = ret; | |
99 | |
100 dObject = this; | |
101 } | |
102 } | |
103 | |
104 class NSScriptWhoseTest : NSObject, INSCoding | |
105 { | |
106 mixin ObjcWrap; | |
107 | |
108 bool isTrue () | |
109 { | |
110 return invokeObjcSelf!(bool, "isTrue"); | |
111 } | |
112 | |
113 void encodeWithCoder (NSCoder aCoder) | |
114 { | |
115 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
116 } | |
117 | |
118 Object initWithCoder (NSCoder aDecoder) | |
119 { | |
120 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
121 } | |
122 | |
123 this (NSCoder aDecoder) | |
124 { | |
125 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
126 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
127 | |
128 if (result) | |
129 objcObject = ret; | |
130 | |
131 dObject = this; | |
132 } | |
133 } | |
134 | |
135 template TNSComparisonMethods () | |
136 { | |
137 bool isEqualTo (Object object); | |
138 bool isLessThanOrEqualTo (Object object); | |
139 bool isLessThan (Object object); | |
140 bool isGreaterThanOrEqualTo (Object object); | |
141 bool isGreaterThan (Object object); | |
142 bool isNotEqualTo (Object object); | |
143 bool doesContain (Object object); | |
144 bool isLike (NSString object); | |
145 bool isCaseInsensitiveLike (NSString object); | |
146 } | |
147 | |
148 template TNSScriptingComparisonMethods () | |
149 { | |
150 bool scriptingIsEqualTo (Object object); | |
151 bool scriptingIsLessThanOrEqualTo (Object object); | |
152 bool scriptingIsLessThan (Object object); | |
153 bool scriptingIsGreaterThanOrEqualTo (Object object); | |
154 bool scriptingIsGreaterThan (Object object); | |
155 bool scriptingBeginsWith (Object object); | |
156 bool scriptingEndsWith (Object object); | |
157 bool scriptingContains (Object object); | |
158 } | |
159 |