fedora-migrator /vendor/gems/facets-2.4.5/test/more/test_boolean.rb

Language Ruby Lines 90
MD5 Hash a237d53566bcc124829e5b8e2842402f Estimated Cost $1,507 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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
Back to Top