Sha256: b947a3eeceb4395cc608b8b8173401635165057ce3a3a497d15dbdf52c845121

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
# for lib/facets/more/typecast.rb
#
# Extracted Tue Jun 06 09:30:19 EDT 2006
# Unit Tools Reap Test Extractor
#

require 'facets/more/typecast.rb'


  require 'test/unit'

  class TestClass
    attr_accessor :my_var
    def initialize(my_var); @my_var = my_var; end

    def cast_to_string(options={})
      @my_var
    end

    class << self
      def cast_from_string(string, options={})
        self.new( string )
      end
    end
  end

  class TC_TypeCast < Test::Unit::TestCase

    def setup
      @test_string = "this is a test"
      @test_class = TestClass.new(@test_string)
    end

    def test_to_string
      assert_equal( '1234', 1234.cast_to(String) )
    end

    def test_custom_to_string
      assert_equal( @test_string, @test_class.cast_to(String) )
    end

    def test_custom_from_string
      assert_equal( @test_class.my_var, @test_string.cast_to(TestClass).my_var )
    end

    def test_string_to_class
      assert_equal( Test::Unit::TestCase, "Test::Unit::TestCase".cast_to(Class) )
    end

    def test_string_to_time
      assert_equal( "Mon Oct 10 00:00:00 2005", "2005-10-10".cast_to(Time).strftime("%a %b %d %H:%M:%S %Y") )
    end

    def test_no_converter
      assert_equal( nil,  "sdfjljsldfjslk".cast_to( ::Regexp  ))
    end
  end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-1.4.1 test/lib/facets/more/test_typecast.rb