Revision: 796 http://trac.macosforge.org/projects/ruby/changeset/796 Author: eloy.de.enige@gmail.com Date: 2009-01-20 06:44:47 -0800 (Tue, 20 Jan 2009) Log Message: ----------- Move HotCocoa tests to MacRuby suite Added Paths: ----------- MacRuby/trunk/test-macruby/cases/hotcocoa/ MacRuby/trunk/test-macruby/cases/hotcocoa/test_helper.rb MacRuby/trunk/test-macruby/cases/hotcocoa/test_mapper.rb MacRuby/trunk/test-macruby/cases/hotcocoa/test_mappings.rb MacRuby/trunk/test-macruby/cases/hotcocoa/test_plist.rb Removed Paths: ------------- MacRuby/trunk/test/hotcocoa/test_mapper.rb MacRuby/trunk/test/hotcocoa/test_mappings.rb MacRuby/trunk/test/hotcocoa/test_plist.rb MacRuby/trunk/test/test_helper.rb Deleted: MacRuby/trunk/test/hotcocoa/test_mapper.rb =================================================================== --- MacRuby/trunk/test/hotcocoa/test_mapper.rb 2009-01-20 14:44:35 UTC (rev 795) +++ MacRuby/trunk/test/hotcocoa/test_mapper.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -1,63 +0,0 @@ -require 'hotcocoa' -require File.join(File.dirname(__FILE__), '..', 'test_helper') - -class SampleClass -end - -class TestMapper < Test::Unit::TestCase - - include HotCocoa::Mappings - - it "should have two hash attributes named #bindings and #delegate" do - assert Mapper.bindings_modules.is_a?(Hash) - assert Mapper.delegate_modules.is_a?(Hash) - end - - [ :control_class, :builder_method, :control_module, - :map_bindings, :map_bindings= ].each do |method| - - it "should have a #{method} attribute" do - assert_respond_to(sample_mapper, method) - end - - end - - it "should set it's control class on initialization" do - assert_equal(sample_mapper(true).control_class, SampleClass) - end - - it "should convert from camelcase to underscore" do - assert sample_mapper.underscore("SampleCamelCasedWord"), 'sample_camel_cased_word' - end - - def test_include_in_class - - m = sample_mapper(true) - m.include_in_class - - assert_equal m.instance_variable_get('@extension_method'), :include - - flunk 'Pending.' - - end - - def test_each_control_ancestor - flunk 'Pending.' - end - - def test_map_class - flunk 'Pending.' - end - - def test_map_instances_of - flunk 'Pending.' - end - - private - - def sample_mapper(flush = false) - @mapper = nil if flush - @mapper || Mapper.new(SampleClass) - end - -end Deleted: MacRuby/trunk/test/hotcocoa/test_mappings.rb =================================================================== --- MacRuby/trunk/test/hotcocoa/test_mappings.rb 2009-01-20 14:44:35 UTC (rev 795) +++ MacRuby/trunk/test/hotcocoa/test_mappings.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -1,76 +0,0 @@ -require 'hotcocoa' -require File.join(File.dirname(__FILE__), '..', 'test_helper') - -class SampleClass - def self.val; @val || false; end - def self.val= (v); @val = v; end -end - -class TestMappings < Test::Unit::TestCase - - include HotCocoa - - it "should have two Hash attributes named #mappings and #frameworks" do - assert Mappings.mappings.is_a?(Hash) - assert Mappings.frameworks.is_a?(Hash) - end - - it "should register callbacks for the point of time when a framework is loaded with #on_framework" do - p = Proc.new {} - Mappings.on_framework(:Foo, &p) - assert_equal(Mappings.frameworks['foo'].last, p) - end - - it "should create a mapping to a class with #map" do - - block = Proc.new do - def alloc_with_options(options); options; end - end - - HotCocoa::Mappings.map({:foo => :SampleClass}, &block) - - m = HotCocoa::Mappings.mappings[:foo] - - assert_equal(m.control_class, SampleClass) - assert_equal(m.builder_method, :foo) - assert(m.control_module.instance_methods.include?(:alloc_with_options)) - - end - - it "should create a mapping to a class for a framework with #map" do - - p = Proc.new {} - - HotCocoa::Mappings.map({:foo => :SampleClass, :framework => :Anonymous}, &p) - - require 'pp'; pp HotCocoa::Mappings - - # FIXME: This is not really nice. We test that the result exists, but not what it is. - assert_equal Mappings.frameworks["anonymous"].size, 1 - - end - - it "should call the framework's callbacks if it's passed to #framework_loaded" do - - p = Proc.new { SampleClass.val = true } - - Mappings.on_framework(:Foo, &p) - Mappings.framework_loaded(:Foo) - - assert_equal SampleClass.val, true - - end - - it "should raise nothing if there's no entry for the framework passed to #framework_loaded" do - - assert_nothing_raised do - Mappings.framework_loaded(:FrameworkDoesNotExist) - end - - end - - def test_reload - flunk 'Pending.' - end - -end \ No newline at end of file Deleted: MacRuby/trunk/test/hotcocoa/test_plist.rb =================================================================== --- MacRuby/trunk/test/hotcocoa/test_plist.rb 2009-01-20 14:44:35 UTC (rev 795) +++ MacRuby/trunk/test/hotcocoa/test_plist.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -1,29 +0,0 @@ -require 'test/unit' -require 'hotcocoa' - -class TestPlist < Test::Unit::TestCase - include HotCocoa - - def test_to_plist - assert_plist(123) - assert_plist(true) - assert_plist(false) - assert_plist('foo') - assert_plist('aiueo'.transform('latin-hiragana')) - assert_plist(:foo, 'foo') - assert_plist([1,2,3]) - assert_plist({'un' => 1, 'deux' => 2}) - end - - def test_to_plist_with_invalid_objects - assert_plist(nil, nil) - assert_plist(Object.new, nil) - assert_plist(/foo/, nil) - end - - private - - def assert_plist(val, expected=val) - assert_equal(expected, read_plist(val.to_plist)) - end -end Deleted: MacRuby/trunk/test/test_helper.rb =================================================================== --- MacRuby/trunk/test/test_helper.rb 2009-01-20 14:44:35 UTC (rev 795) +++ MacRuby/trunk/test/test_helper.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -1,11 +0,0 @@ -require 'test/unit' - -class Test::Unit::TestCase - - class << self - def it(name, &block) - define_method("test_#{name}", &block) - end - end - -end \ No newline at end of file Copied: MacRuby/trunk/test-macruby/cases/hotcocoa/test_helper.rb (from rev 795, MacRuby/trunk/test/test_helper.rb) =================================================================== --- MacRuby/trunk/test-macruby/cases/hotcocoa/test_helper.rb (rev 0) +++ MacRuby/trunk/test-macruby/cases/hotcocoa/test_helper.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -0,0 +1,11 @@ +require 'test/unit' + +class Test::Unit::TestCase + + class << self + def it(name, &block) + define_method("test_#{name}", &block) + end + end + +end \ No newline at end of file Copied: MacRuby/trunk/test-macruby/cases/hotcocoa/test_mapper.rb (from rev 795, MacRuby/trunk/test/hotcocoa/test_mapper.rb) =================================================================== --- MacRuby/trunk/test-macruby/cases/hotcocoa/test_mapper.rb (rev 0) +++ MacRuby/trunk/test-macruby/cases/hotcocoa/test_mapper.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -0,0 +1,63 @@ +require 'hotcocoa' +require File.join(File.dirname(__FILE__), 'test_helper') + +class SampleClass +end + +class TestMapper < Test::Unit::TestCase + + include HotCocoa::Mappings + + it "should have two hash attributes named #bindings and #delegate" do + assert Mapper.bindings_modules.is_a?(Hash) + assert Mapper.delegate_modules.is_a?(Hash) + end + + [ :control_class, :builder_method, :control_module, + :map_bindings, :map_bindings= ].each do |method| + + it "should have a #{method} attribute" do + assert_respond_to(sample_mapper, method) + end + + end + + it "should set it's control class on initialization" do + assert_equal(sample_mapper(true).control_class, SampleClass) + end + + it "should convert from camelcase to underscore" do + assert sample_mapper.underscore("SampleCamelCasedWord"), 'sample_camel_cased_word' + end + + def test_include_in_class + + m = sample_mapper(true) + m.include_in_class + + assert_equal m.instance_variable_get('@extension_method'), :include + + flunk 'Pending.' + + end + + def test_each_control_ancestor + flunk 'Pending.' + end + + def test_map_class + flunk 'Pending.' + end + + def test_map_instances_of + flunk 'Pending.' + end + + private + + def sample_mapper(flush = false) + @mapper = nil if flush + @mapper || Mapper.new(SampleClass) + end + +end Copied: MacRuby/trunk/test-macruby/cases/hotcocoa/test_mappings.rb (from rev 795, MacRuby/trunk/test/hotcocoa/test_mappings.rb) =================================================================== --- MacRuby/trunk/test-macruby/cases/hotcocoa/test_mappings.rb (rev 0) +++ MacRuby/trunk/test-macruby/cases/hotcocoa/test_mappings.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -0,0 +1,76 @@ +require 'hotcocoa' +require File.join(File.dirname(__FILE__), 'test_helper') + +class SampleClass + def self.val; @val || false; end + def self.val= (v); @val = v; end +end + +class TestMappings < Test::Unit::TestCase + + include HotCocoa + + it "should have two Hash attributes named #mappings and #frameworks" do + assert Mappings.mappings.is_a?(Hash) + assert Mappings.frameworks.is_a?(Hash) + end + + it "should register callbacks for the point of time when a framework is loaded with #on_framework" do + p = Proc.new {} + Mappings.on_framework(:Foo, &p) + assert_equal(Mappings.frameworks['foo'].last, p) + end + + it "should create a mapping to a class with #map" do + + block = Proc.new do + def alloc_with_options(options); options; end + end + + HotCocoa::Mappings.map({:foo => :SampleClass}, &block) + + m = HotCocoa::Mappings.mappings[:foo] + + assert_equal(m.control_class, SampleClass) + assert_equal(m.builder_method, :foo) + assert(m.control_module.instance_methods.include?(:alloc_with_options)) + + end + + it "should create a mapping to a class for a framework with #map" do + + p = Proc.new {} + + HotCocoa::Mappings.map({:foo => :SampleClass, :framework => :Anonymous}, &p) + + require 'pp'; pp HotCocoa::Mappings + + # FIXME: This is not really nice. We test that the result exists, but not what it is. + assert_equal Mappings.frameworks["anonymous"].size, 1 + + end + + it "should call the framework's callbacks if it's passed to #framework_loaded" do + + p = Proc.new { SampleClass.val = true } + + Mappings.on_framework(:Foo, &p) + Mappings.framework_loaded(:Foo) + + assert_equal SampleClass.val, true + + end + + it "should raise nothing if there's no entry for the framework passed to #framework_loaded" do + + assert_nothing_raised do + Mappings.framework_loaded(:FrameworkDoesNotExist) + end + + end + + def test_reload + flunk 'Pending.' + end + +end \ No newline at end of file Copied: MacRuby/trunk/test-macruby/cases/hotcocoa/test_plist.rb (from rev 795, MacRuby/trunk/test/hotcocoa/test_plist.rb) =================================================================== --- MacRuby/trunk/test-macruby/cases/hotcocoa/test_plist.rb (rev 0) +++ MacRuby/trunk/test-macruby/cases/hotcocoa/test_plist.rb 2009-01-20 14:44:47 UTC (rev 796) @@ -0,0 +1,29 @@ +require 'test/unit' +require 'hotcocoa' + +class TestPlist < Test::Unit::TestCase + include HotCocoa + + def test_to_plist + assert_plist(123) + assert_plist(true) + assert_plist(false) + assert_plist('foo') + assert_plist('aiueo'.transform('latin-hiragana')) + assert_plist(:foo, 'foo') + assert_plist([1,2,3]) + assert_plist({'un' => 1, 'deux' => 2}) + end + + def test_to_plist_with_invalid_objects + assert_plist(nil, nil) + assert_plist(Object.new, nil) + assert_plist(/foo/, nil) + end + + private + + def assert_plist(val, expected=val) + assert_equal(expected, read_plist(val.to_plist)) + end +end
participants (1)
-
source_changes@macosforge.org