comparison dstep/foundation/NSScriptWhoseTests.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents 89f3c3ef1fd2
children b9de51448c6b
comparison
equal deleted inserted replaced
15:7ff919f595d5 16:19885b43130e
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */ 6 */
7 module dstep.foundation.NSScriptWhoseTests; 7 module dstep.foundation.NSScriptWhoseTests;
8 8
9 import dstep.foundation.NSArray; 9 import dstep.foundation.NSArray;
10 import dstep.foundation.NSCoder;
10 import dstep.foundation.NSObject; 11 import dstep.foundation.NSObject;
11 import dstep.foundation.NSScriptObjectSpecifier; 12 import dstep.foundation.NSObjCRuntime;
13 import dstep.foundation.NSScriptObjectSpecifiers;
12 import dstep.foundation.NSString; 14 import dstep.foundation.NSString;
13 import dstep.objc.bridge.Bridge; 15 import dstep.objc.bridge.Bridge;
14 import dstep.objc.objc : id; 16 import dstep.objc.objc;
15 17
16 alias NSUInteger NSTestComparisonOperation; 18 alias NSUInteger NSTestComparisonOperation;
17 19
18 enum 20 enum
19 { 21 {
25 NSBeginsWithComparison, 27 NSBeginsWithComparison,
26 NSEndsWithComparison, 28 NSEndsWithComparison,
27 NSContainsComparison 29 NSContainsComparison
28 } 30 }
29 31
32 const TNSComparisonMethods = `
33
34 bool isEqualTo (Object object)
35 {
36 return invokeObjcSelf!(bool, "isEqualTo:", Object)(object);
37 }
38
39 bool isLessThanOrEqualTo (Object object)
40 {
41 return invokeObjcSelf!(bool, "isLessThanOrEqualTo:", Object)(object);
42 }
43
44 bool isLessThan (Object object)
45 {
46 return invokeObjcSelf!(bool, "isLessThan:", Object)(object);
47 }
48
49 bool isGreaterThanOrEqualTo (Object object)
50 {
51 return invokeObjcSelf!(bool, "isGreaterThanOrEqualTo:", Object)(object);
52 }
53
54 bool isGreaterThan (Object object)
55 {
56 return invokeObjcSelf!(bool, "isGreaterThan:", Object)(object);
57 }
58
59 bool isNotEqualTo (Object object)
60 {
61 return invokeObjcSelf!(bool, "isNotEqualTo:", Object)(object);
62 }
63
64 bool doesContain (Object object)
65 {
66 return invokeObjcSelf!(bool, "doesContain:", Object)(object);
67 }
68
69 bool isLike (NSString object)
70 {
71 return invokeObjcSelf!(bool, "isLike:", NSString)(object);
72 }
73
74 bool isCaseInsensitiveLike (NSString object)
75 {
76 return invokeObjcSelf!(bool, "isCaseInsensitiveLike:", NSString)(object);
77 }
78
79 //mixin ObjcBindMethod!(isEqualTo, "isEqualTo:");
80 //mixin ObjcBindMethod!(isLessThanOrEqualTo, "isLessThanOrEqualTo:");
81 //mixin ObjcBindMethod!(isLessThan, "isLessThan:");
82 //mixin ObjcBindMethod!(isGreaterThanOrEqualTo, "isGreaterThanOrEqualTo:");
83 //mixin ObjcBindMethod!(isGreaterThan, "isGreaterThan:");
84 //mixin ObjcBindMethod!(isNotEqualTo, "isNotEqualTo:");
85 //mixin ObjcBindMethod!(doesContain, "doesContain:");
86 //mixin ObjcBindMethod!(isLike, "isLike:");
87 //mixin ObjcBindMethod!(isCaseInsensitiveLike, "isCaseInsensitiveLike:");
88 `;
89
90 const TNSScriptingComparisonMethods = `
91
92 bool scriptingIsEqualTo (Object object)
93 {
94 return invokeObjcSelf!(bool, "scriptingIsEqualTo:", Object)(object);
95 }
96
97 bool scriptingIsLessThanOrEqualTo (Object object)
98 {
99 return invokeObjcSelf!(bool, "scriptingIsLessThanOrEqualTo:", Object)(object);
100 }
101
102 bool scriptingIsLessThan (Object object)
103 {
104 return invokeObjcSelf!(bool, "scriptingIsLessThan:", Object)(object);
105 }
106
107 bool scriptingIsGreaterThanOrEqualTo (Object object)
108 {
109 return invokeObjcSelf!(bool, "scriptingIsGreaterThanOrEqualTo:", Object)(object);
110 }
111
112 bool scriptingIsGreaterThan (Object object)
113 {
114 return invokeObjcSelf!(bool, "scriptingIsGreaterThan:", Object)(object);
115 }
116
117 bool scriptingBeginsWith (Object object)
118 {
119 return invokeObjcSelf!(bool, "scriptingBeginsWith:", Object)(object);
120 }
121
122 bool scriptingEndsWith (Object object)
123 {
124 return invokeObjcSelf!(bool, "scriptingEndsWith:", Object)(object);
125 }
126
127 bool scriptingContains (Object object)
128 {
129 return invokeObjcSelf!(bool, "scriptingContains:", Object)(object);
130 }
131
132 //mixin ObjcBindMethod!(scriptingIsEqualTo, "scriptingIsEqualTo:");
133 //mixin ObjcBindMethod!(scriptingIsLessThanOrEqualTo, "scriptingIsLessThanOrEqualTo:");
134 //mixin ObjcBindMethod!(scriptingIsLessThan, "scriptingIsLessThan:");
135 //mixin ObjcBindMethod!(scriptingIsGreaterThanOrEqualTo, "scriptingIsGreaterThanOrEqualTo:");
136 //mixin ObjcBindMethod!(scriptingIsGreaterThan, "scriptingIsGreaterThan:");
137 //mixin ObjcBindMethod!(scriptingBeginsWith, "scriptingBeginsWith:");
138 //mixin ObjcBindMethod!(scriptingEndsWith, "scriptingEndsWith:");
139 //mixin ObjcBindMethod!(scriptingContains, "scriptingContains:");
140 `;
141
30 class NSLogicalTest : NSScriptWhoseTest 142 class NSLogicalTest : NSScriptWhoseTest
31 { 143 {
32 mixin ObjcWrap; 144 mixin (ObjcWrap);
145
146 this ()
147 {
148 super(typeof(this).alloc.init.objcObject);
149 }
150
151 typeof(this) init ()
152 {
153 return invokeObjcSelf!(typeof(this), "init");
154 }
33 155
34 Object initAndTestWithTests (NSArray subTests) 156 Object initAndTestWithTests (NSArray subTests)
35 { 157 {
36 return invokeObjcSelf!(Object, "initAndTestWithTests:", NSArray)(subTests); 158 return invokeObjcSelf!(Object, "initAndTestWithTests:", NSArray)(subTests);
37 } 159 }
38 160
39 this (NSArray subTests) 161 this (NSArray subTests)
40 { 162 {
41 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 163 typeof(this).alloc.initAndTestWithTests(subTests);
42 id result = Bridge.invokeObjcMethod!(id, "initAndTestWithTests:", NSArray)(objcObject, subTests);
43
44 if (result)
45 objcObject = ret;
46
47 dObject = this;
48 } 164 }
49 165
50 Object initOrTestWithTests (NSArray subTests) 166 Object initOrTestWithTests (NSArray subTests)
51 { 167 {
52 return invokeObjcSelf!(Object, "initOrTestWithTests:", NSArray)(subTests); 168 return invokeObjcSelf!(Object, "initOrTestWithTests:", NSArray)(subTests);
53 } 169 }
54 170
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) 171 Object initNotTestWithTest (NSScriptWhoseTest subTest)
67 { 172 {
68 return invokeObjcSelf!(Object, "initNotTestWithTest:", NSScriptWhoseTest)(subTest); 173 return invokeObjcSelf!(Object, "initNotTestWithTest:", NSScriptWhoseTest)(subTest);
69 } 174 }
70 175
71 this (NSScriptWhoseTest subTest) 176 this (NSScriptWhoseTest subTest)
72 { 177 {
73 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 178 typeof(this).alloc.initNotTestWithTest(subTest);
74 id result = Bridge.invokeObjcMethod!(id, "initNotTestWithTest:", NSScriptWhoseTest)(objcObject, subTest);
75
76 if (result)
77 objcObject = ret;
78
79 dObject = this;
80 } 179 }
81 } 180 }
82 181
83 class NSSpecifierTest : NSScriptWhoseTest 182 class NSSpecifierTest : NSScriptWhoseTest
84 { 183 {
85 mixin ObjcWrap; 184 mixin (ObjcWrap);
185
186 this ()
187 {
188 super(typeof(this).alloc.init.objcObject);
189 }
190
191 typeof(this) init ()
192 {
193 return invokeObjcSelf!(typeof(this), "init");
194 }
86 195
87 Object initWithObjectSpecifier (NSScriptObjectSpecifier obj1, uint compOp, Object obj2) 196 Object initWithObjectSpecifier (NSScriptObjectSpecifier obj1, uint compOp, Object obj2)
88 { 197 {
89 return invokeObjcSelf!(Object, "initWithObjectSpecifier:comparisonOperator:testObject:", NSScriptObjectSpecifier, uint, Object)(obj1, compOp, obj2); 198 return invokeObjcSelf!(Object, "initWithObjectSpecifier:comparisonOperator:testObject:", NSScriptObjectSpecifier, uint, Object)(obj1, compOp, obj2);
90 } 199 }
91 200
92 this (NSScriptObjectSpecifier obj1, uint compOp, Object obj2) 201 this (NSScriptObjectSpecifier obj1, uint compOp, Object obj2)
93 { 202 {
94 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 203 typeof(this).alloc.initWithObjectSpecifier(obj1, compOp, obj2);
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 } 204 }
102 } 205 }
103 206
104 class NSScriptWhoseTest : NSObject, INSCoding 207 class NSScriptWhoseTest : NSObject, INSCoding
105 { 208 {
106 mixin ObjcWrap; 209 mixin (ObjcWrap);
210
211 this ()
212 {
213 super(typeof(this).alloc.init.objcObject);
214 }
215
216 typeof(this) init ()
217 {
218 return invokeObjcSelf!(typeof(this), "init");
219 }
107 220
108 bool isTrue () 221 bool isTrue ()
109 { 222 {
110 return invokeObjcSelf!(bool, "isTrue"); 223 return invokeObjcSelf!(bool, "isTrue");
111 } 224 }
120 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); 233 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
121 } 234 }
122 235
123 this (NSCoder aDecoder) 236 this (NSCoder aDecoder)
124 { 237 {
125 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); 238 typeof(this).alloc.initWithCoder(aDecoder);
126 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); 239 }
127 240 }
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