Revision: 788 http://trac.macosforge.org/projects/ruby/changeset/788 Author: eloy.de.enige@gmail.com Date: 2009-01-13 07:34:04 -0800 (Tue, 13 Jan 2009) Log Message: ----------- Added accessor methods for x, y, width, height to NSRect. Modified Paths: -------------- MacRuby/trunk/test-macruby/test_objc_ext.rb Added Paths: ----------- MacRuby/trunk/lib/objc_ext/ns_rect.rb Added: MacRuby/trunk/lib/objc_ext/ns_rect.rb =================================================================== --- MacRuby/trunk/lib/objc_ext/ns_rect.rb (rev 0) +++ MacRuby/trunk/lib/objc_ext/ns_rect.rb 2009-01-13 15:34:04 UTC (rev 788) @@ -0,0 +1,47 @@ +class MacRuby + module ObjcExt + module NSRect + # Returns the `x' coordinate of the rects origin instance. + def x + origin.x + end + + # Assigns the `x' coordinate on the rects origin instance. + def x=(x) + origin.x = x + end + + # Returns the `y' coordinate of the rects origin instance. + def x + origin.x + end + + # Assigns the `y' coordinate on the rects origin instance. + def x=(x) + origin.x = x + end + + # Returns the `height' of the rects size instance. + def height + size.height + end + + # Sets the `height' on the rects size instance. + def height=(height) + size.height = height + end + + # Returns the `width' of the rects size instance. + def width + size.width + end + + # Sets the `width' on the rects size instance. + def width=(width) + size.width = width + end + end + end +end + +NSRect.send(:include, MacRuby::ObjcExt::NSRect) \ No newline at end of file Modified: MacRuby/trunk/test-macruby/test_objc_ext.rb =================================================================== --- MacRuby/trunk/test-macruby/test_objc_ext.rb 2009-01-13 14:26:28 UTC (rev 787) +++ MacRuby/trunk/test-macruby/test_objc_ext.rb 2009-01-13 15:34:04 UTC (rev 788) @@ -1,5 +1,8 @@ #!/usr/bin/env macruby +$: << File.expand_path('../../lib', __FILE__) +framework 'Cocoa' + require 'test/unit' class Test::Unit::TestCase class << self @@ -9,23 +12,22 @@ end end -$: << File.expand_path('../../lib', __FILE__) +# These tests should probably move to the macruby part of rubyspec once we get to that point. + require 'objc_ext/ns_user_defaults' -# These tests should probably move to the macruby part of rubyspec once we get to that point. - -class TestNSUserDefaults < Test::Unit::TestCase - it "returns a value for a given key through the #[] reader method" do +class TestNSUserDefaultsExtensions < Test::Unit::TestCase + it "should returns a value for a given key through the #[] reader method" do defaults.setValue('foo', forKey: 'key') assert_equal 'foo', defaults['key'] end - it "assigns a value for a given key through the #[]= writer method" do + it "should assign a value for a given key through the #[]= writer method" do defaults['key'] = 'foo' assert_equal 'foo', defaults.valueForKey('key') end - it "removes an object for a given key with the #delete method" do + it "should remove an object for a given key with the #delete method" do defaults.setValue('foo', forKey: 'key') defaults.delete('key') assert_nil defaults.valueForKey('key') @@ -36,4 +38,48 @@ def defaults NSUserDefaults.standardUserDefaults end +end + +require 'objc_ext/ns_rect' + +class TestNSRectExtensions < Test::Unit::TestCase + def setup + @rect = NSRect.new([100, 100], [200, 200]) + end + + it "should return its size instance's height with #height" do + assert_equal 200, @rect.height + end + + it "should assign the height to its size instance with #height=" do + @rect.height = 300 + assert_equal 300, @rect.height + end + + it "should return its size instance's width with #width" do + assert_equal 200, @rect.width + end + + it "should assign the width to its size instance with #width=" do + @rect.width = 300 + assert_equal 300, @rect.width + end + + it "should return its origin instance's x coord with #x" do + assert_equal 100, @rect.x + end + + it "should assign the x coord to its origin instance with #x=" do + @rect.x = 200 + assert_equal 200, @rect.x + end + + it "should return its origin instance's y coord with #y" do + assert_equal 100, @rect.y + end + + it "should assign the y coord to its origin instance with #y=" do + @rect.y = 200 + assert_equal 200, @rect.y + end end \ No newline at end of file
participants (1)
-
source_changes@macosforge.org