Sha256: 6a6105e81c785f410fbfca2df1aa846938974494e5cd91855281c86ab2ec8a07

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

require 'test/unit'
require 'rubygems'
require File.join(File.dirname(__FILE__), '../init')

class StructInfoTest < Test::Unit::TestCase
  ######################################################################
  ### same?

  def test_same_p
    assert   Must::StructInfo.new(1).same?(Integer)
    assert   Must::StructInfo.new(1).same?(Numeric)
    assert ! Must::StructInfo.new(1).same?(String)

    assert   Must::StructInfo.new(Integer).same?(Integer)
    assert   Must::StructInfo.new(Integer).same?(Numeric)
    assert   Must::StructInfo.new(Fixnum).same?(1)
  end

  ######################################################################
  ### types

  def test_types
    assert_equal [Fixnum], Must::StructInfo.new(1).types
    assert_equal [Hash, Symbol, String, Float], Must::StructInfo.new({:a=>{"1"=>0.25}}).types
  end

  ######################################################################
  ### struct

  def test_compact
    assert_equal(Fixnum, Must::StructInfo.new(1).compact)
    assert_equal({}, Must::StructInfo.new({}).compact)
    assert_equal({String=>Fixnum}, Must::StructInfo.new({"a"=>1}).compact)
    assert_equal([{String=>Float}], Must::StructInfo.new([{"1"=>0.25}]).compact)
    assert_equal({String=>{String=>[{Symbol=>Fixnum}]}}, Must::StructInfo.new({"1.1" => {"jp"=>[{:a=>0},{:b=>2}]}}).compact)
  end

  def test_compact_array_into_first_element
    assert_equal [Fixnum], Must::StructInfo.new([1, "a"]).compact
    assert_equal [String], Must::StructInfo.new(["a", 1]).compact
  end

  ######################################################################
  ### pp

  def test_inspect
    assert_equal "Fixnum", Must::StructInfo.new(1).inspect
    assert_equal "{}", Must::StructInfo.new({}).inspect
    assert_equal "{String=>Fixnum}", Must::StructInfo.new({"a"=>1}).inspect
    assert_equal "[{String=>Float}]", Must::StructInfo.new([{"1"=>0.25}]).inspect
    assert_equal "{String=>{String=>[{Symbol=>Fixnum}]}}", Must::StructInfo.new({"1.1" => {"jp"=>[{:a=>0},{:b=>2}]}}).inspect
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
must-0.2.5 test/struct_info_test.rb