[macruby-changes] [2424] MacRuby/trunk/spec/macruby/core/gcd_spec.rb
source_changes at macosforge.org
source_changes at macosforge.org
Fri Aug 28 21:41:42 PDT 2009
Revision: 2424
http://trac.macosforge.org/projects/ruby/changeset/2424
Author: lsansonetti at apple.com
Date: 2009-08-28 21:41:42 -0700 (Fri, 28 Aug 2009)
Log Message:
-----------
adding GCD specs (still a work in progress)
Added Paths:
-----------
MacRuby/trunk/spec/macruby/core/gcd_spec.rb
Added: MacRuby/trunk/spec/macruby/core/gcd_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd_spec.rb (rev 0)
+++ MacRuby/trunk/spec/macruby/core/gcd_spec.rb 2009-08-29 04:41:42 UTC (rev 2424)
@@ -0,0 +1,139 @@
+require File.dirname(__FILE__) + "/../spec_helper"
+
+describe "Dispatch::Queue.concurrent" do
+ it "returns an instance of Queue" do
+ o = Dispatch::Queue.concurrent
+ o.should be_kind_of(Dispatch::Queue)
+ end
+
+ it "can accept a symbol argument which represents the priority" do
+ o = Dispatch::Queue.concurrent(:low)
+ o.should be_kind_of(Dispatch::Queue)
+
+ o = Dispatch::Queue.concurrent(:default)
+ o.should be_kind_of(Dispatch::Queue)
+
+ o = Dispatch::Queue.concurrent(:high)
+ o.should be_kind_of(Dispatch::Queue)
+
+ lambda { Dispatch::Queue.concurrent(42) }.should raise_error(TypeError)
+ end
+
+ it "raises an ArgumentError if the given argument is not a valid priority symvol" do
+ lambda { Dispatch::Queue.concurrent(:foo) }.should raise_error(ArgumentError)
+ end
+end
+
+describe "Dispatch::Queue.current" do
+ it "returns an instance of Queue" do
+ o = Dispatch::Queue.current
+ o.should be_kind_of(Dispatch::Queue)
+ end
+end
+
+describe "Dispatch::Queue.main" do
+ it "returns an instance of Queue" do
+ o = Dispatch::Queue.main
+ o.should be_kind_of(Dispatch::Queue)
+ end
+end
+
+describe "Dispatch::Queue.new" do
+ it "accepts a name and returns an instance of Queue" do
+ o = Dispatch::Queue.new('foo')
+ o.should be_kind_of(Dispatch::Queue)
+
+ lambda { Dispatch::Queue.new('foo', 42) }.should raise_error(ArgumentError)
+ lambda { Dispatch::Queue.new(42) }.should raise_error(TypeError)
+ end
+end
+
+describe "Dispatch::Queue#dispatch" do
+ it "accepts a block and yields it asynchronously" do
+ o = Dispatch::Queue.new('foo')
+ i = 0
+ o.dispatch { i = 42 }
+ while i == 0 do; end
+ i.should == 42
+ end
+
+ it "accepts a block and yields it synchronously if the given argument is true" do
+ o = Dispatch::Queue.new('foo')
+ i = 0
+ o.dispatch(true) { i = 42 }
+ i.should == 42
+ end
+
+ it "raises an ArgumentError if no block is given" do
+ o = Dispatch::Queue.new('foo')
+ lambda { o.dispatch }.should raise_error(ArgumentError)
+ lambda { o.dispatch(true) }.should raise_error(ArgumentError)
+ end
+end
+
+describe "Dispatch::Queue#apply" do
+ it "accepts an input size and a block and yields it as many times" do
+ o = Dispatch::Queue.new('foo')
+ i = 0
+ o.apply(10) { i += 1 }
+ i.should == 10
+ i = 42
+ o.apply(0) { i += 1 }
+ i.should == 42
+
+ lambda { o.apply(nil) {} }.should raise_error(TypeError)
+ end
+
+ it "raises an ArgumentError if no block is given" do
+ o = Dispatch::Queue.new('foo')
+ lambda { o.apply(42) }.should raise_error(ArgumentError)
+ end
+end
+
+describe "Dispatch::Queue#after" do
+ it "accepts a given time (in seconds) and a block and yields it after" do
+ o = Dispatch::Queue.new('foo')
+ i = 0
+ t = Time.now
+ o.after(0.2) { i = 42 }
+ while i == 0 do; end
+ t2 = Time.now - t
+ t2.should >= 0.2
+ t2.should < 0.5
+ i.should == 42
+
+ lambda { o.after(nil) {} }.should raise_error(TypeError)
+ end
+
+ it "raises an ArgumentError if no block is given" do
+ o = Dispatch::Queue.new('foo')
+ lambda { o.after(42) }.should raise_error(ArgumentError)
+ end
+end
+
+describe "Dispatch::Queue#label" do
+ it "returns the name of the queue" do
+ o = Dispatch::Queue.new('foo')
+ o.label.should == 'foo'
+
+ o = Dispatch::Queue.main
+ o.label.should == 'com.apple.main-thread'
+ end
+end
+
+describe "Dispatch::Queue#suspend!" do
+ it "suspends the queue which can be resumed by calling #resume!" do
+ o = Dispatch::Queue.new('foo')
+ o.dispatch { sleep 1 }
+ o.suspended?.should == false
+ o.suspend!
+ o.suspended?.should == true
+ o.resume!
+ o.suspended?.should == false
+ end
+end
+
+# TODO:
+# Dispatch::Queue.main.run
+# Dispatch::Group
+# Dispatch::Source
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090828/853dd0ff/attachment.html>
More information about the macruby-changes
mailing list