Sha256: 78526850a62beb595ce38a6fc7ddcf214f2ad93b20cc06d97d9cc97498287dd3

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

# Test for facets/boolean.rb

require 'facets/boolean.rb'
require 'test/unit'


class TestStringBoolean < Test::Unit::TestCase

  def test_to_b
    assert( 'true'.to_b )
    assert( 'True'.to_b )
    assert( 'yes'.to_b )
    assert( 'YES'.to_b )
    assert( 'on'.to_b )
    assert( 'ON'.to_b )
    assert( 't'.to_b )
    assert( '1'.to_b )
    assert( 'y'.to_b )
    assert( 'Y'.to_b )
    assert( '=='.to_b )
    assert( ! 'nil'.to_b )
    assert( ! 'false'.to_b )
    assert( ! 'blahblahtrueblah'.to_b )
    assert_equal( nil, 'nil'.to_b )
    assert_equal( nil, 'null'.to_b )
  end

end


class TestArrayBoolean < Test::Unit::TestCase

  def test_to_b
    a = []
    assert_equal( false, a.to_b )
  end

end


class TestNumericBoolean < Test::Unit::TestCase

  def test_to_b
    assert_equal( false, 0.to_b )
    assert_equal( true, 1.to_b )
  end

end


class TestKernelBoolean < Test::Unit::TestCase

  def test_to_b
    assert_equal( true, true.to_b )
    assert_equal( false, false.to_b )
    assert_equal( false, nil.to_b )
  end

  def test_false?
    assert( false.false? )
    assert( (1 == 2).false? )
    assert( ! (1 == 1).false? )
  end

  def test_true?
    assert( true.true? )
    assert( (1 == 1).true? )
    assert( ! (1 == 2).true? )
  end

  def test_bool?
    assert_equal( true, true.bool? )
    assert_equal( true, false.bool? )
    assert_equal( false, nil.bool? )
    assert_equal( false, 0.bool? )
  end

end


class TestBoolean < Test::Unit::TestCase

  def test_to_bool
    assert_equal( true, true.to_bool )
    assert_equal( false, false.to_bool )
    assert_equal( false, nil.to_bool )
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/test_boolean.rb
facets-2.8.3 test/core/test_boolean.rb
facets-2.8.2 test/core/test_boolean.rb
facets-2.8.1 test/core/test_boolean.rb
facets-2.8.0 test/core/test_boolean.rb
facets-2.7.0 test/core/test_boolean.rb
facets-2.6.0 test/more/test_boolean.rb
facets-2.1.3 test/unit/test_boolean.rb
facets-2.2.1 test/unit/test_boolean.rb
facets-2.2.0 test/unit/test_boolean.rb
facets-2.4.0 test/test_boolean.rb
facets-2.3.0 test/core/test_boolean.rb
facets-2.4.1 test/test_boolean.rb
facets-2.4.2 test/more/test_boolean.rb
facets-2.4.4 test/more/test_boolean.rb
facets-2.4.3 test/more/test_boolean.rb
facets-2.4.5 test/more/test_boolean.rb
facets-2.5.1 test/more/test_boolean.rb
facets-2.5.0 test/more/test_boolean.rb
facets-2.5.2 test/more/test_boolean.rb