Sha256: b8e45c3601cc2130ab4b60b277cd284ec9d8ab2343bcb61e080c78fa1f644cea

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

#
# testing ruote
#
# Sat Sep 19 13:27:18 JST 2009
#

require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')

require 'ruote/util/misc'


class UtMiscTest < Test::Unit::TestCase

  def test_narrow_to_number

    assert_equal nil, Ruote.narrow_to_number(nil)
    assert_equal nil, Ruote.narrow_to_number('a')
    assert_equal nil, Ruote.narrow_to_number(Object.new)

    assert_equal 0, Ruote.narrow_to_number(0)
    assert_equal 1, Ruote.narrow_to_number(1)

    assert_equal 0.0, Ruote.narrow_to_number(0.0)
    assert_equal 1.0, Ruote.narrow_to_number(1.0)

    assert_equal 0, Ruote.narrow_to_number('0')
    assert_equal 1, Ruote.narrow_to_number('1')

    assert_equal 0.0, Ruote.narrow_to_number('0.0')
    assert_equal 1.0, Ruote.narrow_to_number('1.0')
  end

  def test_regex_or_s

    assert_equal /bravo/, Ruote.regex_or_s('/bravo/')
    assert_equal 'nada', Ruote.regex_or_s('nada')
    assert_equal nil, Ruote.regex_or_s(nil)
  end

  class Klass
    def initialize(s)
      @s = s
    end
  end

  def test_fulldup

    a = Klass.new('hello')
    b = Ruote.fulldup(a)

    assert_equal Klass, b.class
    assert_not_equal a.object_id, b.object_id
    assert_equal 'hello', b.instance_variable_get(:@s)
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ruote-maestrodev-2.2.1 test/unit/ut_15_util.rb
ruote-2.2.0 test/unit/ut_15_util.rb