[macruby-changes] [1498] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 27 21:39:25 PDT 2009
Revision: 1498
http://trac.macosforge.org/projects/ruby/changeset/1498
Author: lsansonetti at apple.com
Date: 2009-04-27 21:39:25 -0700 (Mon, 27 Apr 2009)
Log Message:
-----------
rewrote the setFoo/foo= and isFoo/foo? specs to use a class in method.m + fixed a bug in the isFoo/foo? helper
Modified Paths:
--------------
MacRuby/branches/experimental/roxor.cpp
MacRuby/branches/experimental/spec/macruby/fixtures/method.bridgesupport
MacRuby/branches/experimental/spec/macruby/fixtures/method.m
MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb
Modified: MacRuby/branches/experimental/roxor.cpp
===================================================================
--- MacRuby/branches/experimental/roxor.cpp 2009-04-28 04:25:21 UTC (rev 1497)
+++ MacRuby/branches/experimental/roxor.cpp 2009-04-28 04:39:25 UTC (rev 1498)
@@ -7207,10 +7207,12 @@
helper_sel(SEL sel)
{
const char *p = sel_getName(sel);
- long len = strlen(p);
+ size_t len = strlen(p);
SEL new_sel = 0;
char buf[100];
+ assert(len < sizeof(buf));
+
if (len >= 3 && isalpha(p[len - 3]) && p[len - 2] == '=' && p[len - 1] == ':') {
/* foo=: -> setFoo: shortcut */
snprintf(buf, sizeof buf, "set%s", p);
@@ -7219,7 +7221,7 @@
buf[len + 2] = '\0';
new_sel = sel_registerName(buf);
}
- else if (isalpha(p[len - 2]) && p[len - 1] == '?') {
+ else if (len > 1 && p[len - 1] == '?') {
/* foo?: -> isFoo: shortcut */
snprintf(buf, sizeof buf, "is%s", p);
buf[2] = toupper(buf[2]);
Modified: MacRuby/branches/experimental/spec/macruby/fixtures/method.bridgesupport
===================================================================
--- MacRuby/branches/experimental/spec/macruby/fixtures/method.bridgesupport 2009-04-28 04:25:21 UTC (rev 1497)
+++ MacRuby/branches/experimental/spec/macruby/fixtures/method.bridgesupport 2009-04-28 04:39:25 UTC (rev 1498)
@@ -2,6 +2,12 @@
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='0.9'>
<class name='TestMethod'>
+ <method selector='isFoo'>
+ <retval type='B'/>
+ </method>
+ <method selector='isFoo2'>
+ <retval type='B'/>
+ </method>
<method selector='methodReturningYES'>
<retval type='B'/>
</method>
Modified: MacRuby/branches/experimental/spec/macruby/fixtures/method.m
===================================================================
--- MacRuby/branches/experimental/spec/macruby/fixtures/method.m 2009-04-28 04:25:21 UTC (rev 1497)
+++ MacRuby/branches/experimental/spec/macruby/fixtures/method.m 2009-04-28 04:39:25 UTC (rev 1498)
@@ -1,10 +1,33 @@
#import <Foundation/Foundation.h>
@interface TestMethod : NSObject
+{
+ id _foo;
+}
@end
@implementation TestMethod
+- (BOOL)isFoo
+{
+ return YES;
+}
+
+- (BOOL)isFoo2
+{
+ return NO;
+}
+
+- (void)setFoo:(id)foo
+{
+ _foo = foo;
+}
+
+- (id)foo
+{
+ return _foo;
+}
+
- (void)methodReturningVoid
{
}
Modified: MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb 2009-04-28 04:25:21 UTC (rev 1497)
+++ MacRuby/branches/experimental/spec/macruby/objc_method_spec.rb 2009-04-28 04:39:25 UTC (rev 1498)
@@ -23,23 +23,26 @@
end
it "can be called with #foo= if it matches the #setFoo pattern" do
- o = []
+ # Note: we cannot use #have_method here because pure Objective-C
+ # methods as well as convenience shortcuts are not exposed in #methods.
+ @o.respond_to?(:'setFoo').should == true
+ @o.respond_to?(:'foo=').should == true
+ @o.respond_to?(:'foo').should == true
- # TODO Stopped here: This should be sufficient, but doesn't work.
- # o.should have_method(:'setArray', true)
- # o.should have_method(:'array=', true)
-
- o.respond_to?(:'setArray').should == true
- o.respond_to?(:'array=').should == true
- o.array = [1, 2, 3]
- o.should == [1, 2, 3]
+ @o.setFoo(123)
+ @o.foo.should == 123
+ @o.foo = 456
+ @o.foo.should == 456
end
it "can be called with #foo? if it matches the #isFoo pattern" do
- o = NSBundle.mainBundle
- o.respond_to?(:'isLoaded').should == true
- o.respond_to?(:'loaded?').should == true
- o.loaded?.should == true
+ @o.respond_to?(:'isFoo').should == true
+ @o.respond_to?(:'foo?').should == true
+ @o.foo?.should == true
+
+ @o.respond_to?(:'isFoo2').should == true
+ @o.respond_to?(:'foo2?').should == true
+ @o.foo2?.should == false
end
it "is only exposed in #methods if the second argument is true" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090427/31a89f0e/attachment.html>
More information about the macruby-changes
mailing list