[macruby-changes] [3171] MacRuby/trunk/spec/macruby/core/pointer_spec.rb

source_changes at macosforge.org source_changes at macosforge.org
Wed Dec 23 20:39:30 PST 2009


Revision: 3171
          http://trac.macosforge.org/projects/ruby/changeset/3171
Author:   lsansonetti at apple.com
Date:     2009-12-23 20:39:30 -0800 (Wed, 23 Dec 2009)
Log Message:
-----------
added more Pointer specs to cover the latest changes

Modified Paths:
--------------
    MacRuby/trunk/spec/macruby/core/pointer_spec.rb

Modified: MacRuby/trunk/spec/macruby/core/pointer_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/pointer_spec.rb	2009-12-24 04:39:04 UTC (rev 3170)
+++ MacRuby/trunk/spec/macruby/core/pointer_spec.rb	2009-12-24 04:39:30 UTC (rev 3171)
@@ -46,6 +46,15 @@
   it "accepts the type returned by NSRect" do
     Pointer.new(NSRect.type).type.should == NSRect.type
   end
+
+  it "accepts a non mandatory second argument that specifies the number of elements that should be allocated" do
+    lambda { Pointer.new('i', 1) }.should_not raise_error
+  end
+
+  it "raises an ArgumentError if the second argument (size) is not greater than 0" do
+    lambda { Pointer.new('i', -1) }.should raise_error(ArgumentError)
+    lambda { Pointer.new('i', 0) }.should raise_error(ArgumentError)
+  end
 end
 
 describe "Pointer, through #[] and #[]=" do
@@ -130,4 +139,34 @@
     ptr[2].class.should == Fixnum
     ptr[2].chr.should == 'y'
   end
+
+  it "will raise a TypeError exception in case the given index cannot be converted to a numeric type" do
+    pointer = Pointer.new('i')
+    lambda { pointer[nil] }.should raise_error(TypeError)
+    lambda { pointer[nil] = 42 }.should raise_error(TypeError)
+    lambda { pointer['omg'] }.should raise_error(TypeError)
+    lambda { pointer['omg'] = 42 }.should raise_error(TypeError)
+  end
+
+  it "will raise an ArgumentError exception in case the given index is negative" do
+    pointer = Pointer.new('i')
+    lambda { pointer[-1] }.should raise_error(ArgumentError)
+    lambda { pointer[-1] = 42 }.should raise_error(ArgumentError)
+  end
+
+  it "will raise an ArgumentError exception in case the given index is out of bounds" do
+    pointer = Pointer.new('i')
+    lambda { pointer[0] }.should_not raise_error
+    lambda { pointer[0] = 42 }.should_not raise_error
+    lambda { pointer[1] }.should raise_error(ArgumentError)
+    lambda { pointer[1] = 42 }.should raise_error(ArgumentError)
+
+    pointer = Pointer.new('i', 3)
+    3.times do |i|
+      lambda { pointer[i] }.should_not raise_error
+      lambda { pointer[i] = 42 }.should_not raise_error
+    end
+    lambda { pointer[3] }.should raise_error(ArgumentError)
+    lambda { pointer[3] = 42 }.should raise_error(ArgumentError)
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091223/97956510/attachment-0001.html>


More information about the macruby-changes mailing list