test/struct_test.rb in must-0.2.4 vs test/struct_test.rb in must-0.2.5

- old
+ new

@@ -1,42 +1,49 @@ require 'test/unit' require 'rubygems' require File.join(File.dirname(__FILE__), '../init') class StructTest < Test::Unit::TestCase - def test_struct_test_successed - assert_equal true, [].must.struct?([]) - assert_equal true, 1.must.struct?(Integer) - assert_equal true, 1.must.struct?(Fixnum) - assert_equal true, 1.must.struct?(2) - assert_equal true, Fixnum.must.struct?(Fixnum) - assert_equal true, Fixnum.must.struct?(2) + def test_struct_basic_object + assert [].must.struct?([]) + assert ! [].must.struct?({}) - obj = {"foo" => 1} - assert_equal true, obj.must.struct?({String => Integer}) - - obj = {"foo" => [{:a=>1}, {:a=>3}]} - assert_equal true, obj.must.struct?(Hash) - assert_equal true, obj.must.struct?({String => Array}) - assert_equal true, obj.must.struct?({String => [Hash]}) + assert 1.must.struct?(Integer) + assert 1.must.struct?(Fixnum) + assert 1.must.struct?(2) + assert ! 1.must.struct?(String) + assert Fixnum.must.struct?(Fixnum) + assert Fixnum.must.struct?(2) + assert ! Integer.must.struct?(Fixnum) end - def test_struct_test_failed - assert_equal false, [].must.struct?({}) - assert_equal false, Integer.must.struct?(Fixnum) - + def test_struct_composite_objects obj = {"foo" => 1} - assert_equal false, obj.must.struct?(String) - assert_equal false, obj.must.struct?(Array) - assert_equal false, obj.must.struct?([String]) - assert_equal false, obj.must.struct?({String => String}) + assert obj.must.struct?({String => Integer}) + assert ! obj.must.struct?(String) + assert ! obj.must.struct?(Array) + assert ! obj.must.struct?([String]) + assert ! obj.must.struct?({String => String}) obj = [{:a=>1}, {:a=>3}] - assert_equal false, obj.must.struct?([Array]) + assert obj.must.struct?([Hash]) + assert ! obj.must.struct?([Array]) obj = {"foo" => [{:a=>1}, {:a=>3}]} - assert_equal false, obj.must.struct?({String => Hash}) - assert_equal false, obj.must.struct?({String => [Array]}) + assert obj.must.struct?(Hash) + assert ! obj.must.struct?(Array) + assert obj.must.struct?({String => Array}) + assert ! obj.must.struct?({Array => Array}) + assert obj.must.struct?({String => [Hash]}) + + obj = {"foo" => [{:a=>1}, {:a=>3}]} + assert obj.must.struct?({String => []}) + assert obj.must.struct?({String => Array}) + assert ! obj.must.struct?({String => Hash}) + assert obj.must.struct?({String => [Hash]}) + assert obj.must.struct?({String => Array(Hash)}) + assert ! obj.must.struct?({String => [Array]}) + assert ! obj.must.struct?({String => Array(String)}) end def test_struct_complicated def ok(obj) assert_equal obj, obj.must.struct({String => [Hash]})