Permalink
Browse files

add specs for variadic methods

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5161 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent e02a6c1 commit 54992f2fe2bc38fabf36bd74c6b38a2f1448d8d7 @lrz lrz committed Jan 13, 2011
@@ -37,6 +37,8 @@
<retval type='I'/>
</arg>
</method>
+ <method selector='methodAcceptingObjects:' variadic='true' sentinel='0'/>
+ <method selector='methodAcceptingObject:and:' variadic='true' sentinel='0'/>
</class>
<informal_protocol name='Foo'>
<method type="i@:i" selector="informalProtocolMethod1:"/>
@@ -808,6 +808,45 @@ - (int)callSavedBlockCopyWithArg:(int)x andArg:(int)y
return _my_block(x, y);
}
+- (NSArray *)methodAcceptingObjects:(id)obj1, ...
+{
+ NSMutableArray *ary = [NSMutableArray new];
+ [ary addObject:obj1];
+
+ va_list ar;
+ va_start(ar, obj1);
+ while (true) {
+ id val = va_arg(ar, id);
+ if (val == nil) {
+ break;
+ }
+ [ary addObject:val];
+ }
+ va_end(ar);
+
+ return ary;
+}
+
+- (NSArray *)methodAcceptingObject:(id)obj1 and:obj2, ...
+{
+ NSMutableArray *ary = [NSMutableArray new];
+ [ary addObject:obj1];
+ [ary addObject:obj2];
+
+ va_list ar;
+ va_start(ar, obj2);
+ while (true) {
+ id val = va_arg(ar, id);
+ if (val == nil) {
+ break;
+ }
+ [ary addObject:val];
+ }
+ va_end(ar);
+
+ return ary;
+}
+
@end
CFNumberRef functionMultiplicatingByTwoViaFctPtr(CFNumberRef nb, CFNumberRef (*multiplier)(CFNumberRef))
@@ -472,6 +472,13 @@ def o.to_ary
o.class.should == Method
o.should == NSString.method(:hash)
end
+
+ it "declared as variadic, can be messaged" do
+ @o.methodAcceptingObjects(1, nil).should == [1]
+ @o.methodAcceptingObjects(1, 2, 3, nil).should == [1, 2, 3]
+ @o.methodAcceptingObject(1, and:2, nil).should == [1, 2]
+ @o.methodAcceptingObject(1, and:2, 3, nil).should == [1, 2, 3]
+ end
end
describe "A pure MacRuby method" do

0 comments on commit 54992f2

Please sign in to comment.