Sha256: 30d4ded63835583d19cf04e842155dc13334d26ff20d5b06d685870cfffd248c

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

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)

    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]})
  end

  def test_struct_test_failed
    assert_equal false, [].must.struct?({})
    assert_equal false, Integer.must.struct?(Fixnum)

    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})

    obj = [{:a=>1}, {:a=>3}]
    assert_equal false, 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]})
  end

  def test_struct_complicated
    def ok(obj)
      assert_equal obj, obj.must.struct({String => [Hash]})
    end
    def ng(obj)
      assert_raises(Invalid){ obj.must.struct({String => [Hash]})}
    end

    ok({})
    ng []
    ok "foo" => []
    ng "foo" => {"gp"=>"-1"}
    ok "foo" => [{"gp"=>"-1"}]
    ok "foo" => [{"sid"=>"45064"}, {"gp"=>"-1"}]
    ng "foo" => [[{"sid"=>"45064"}]]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
must-0.2.4 test/struct_test.rb