PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 89 lines | 64 code | 24 blank | 1 comment | 4 complexity | a237d53566bcc124829e5b8e2842402f MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test for facets/boolean.rb
  2. require 'facets/boolean.rb'
  3. require 'test/unit'
  4. class TestStringBoolean < Test::Unit::TestCase
  5. def test_to_b
  6. assert( 'true'.to_b )
  7. assert( 'True'.to_b )
  8. assert( 'yes'.to_b )
  9. assert( 'YES'.to_b )
  10. assert( 'on'.to_b )
  11. assert( 'ON'.to_b )
  12. assert( 't'.to_b )
  13. assert( '1'.to_b )
  14. assert( 'y'.to_b )
  15. assert( 'Y'.to_b )
  16. assert( '=='.to_b )
  17. assert( ! 'nil'.to_b )
  18. assert( ! 'false'.to_b )
  19. assert( ! 'blahblahtrueblah'.to_b )
  20. assert_equal( nil, 'nil'.to_b )
  21. assert_equal( nil, 'null'.to_b )
  22. end
  23. end
  24. class TestArrayBoolean < Test::Unit::TestCase
  25. def test_to_b
  26. a = []
  27. assert_equal( false, a.to_b )
  28. end
  29. end
  30. class TestNumericBoolean < Test::Unit::TestCase
  31. def test_to_b
  32. assert_equal( false, 0.to_b )
  33. assert_equal( true, 1.to_b )
  34. end
  35. end
  36. class TestKernelBoolean < Test::Unit::TestCase
  37. def test_to_b
  38. assert_equal( true, true.to_b )
  39. assert_equal( false, false.to_b )
  40. assert_equal( false, nil.to_b )
  41. end
  42. def test_false?
  43. assert( false.false? )
  44. assert( (1 == 2).false? )
  45. assert( ! (1 == 1).false? )
  46. end
  47. def test_true?
  48. assert( true.true? )
  49. assert( (1 == 1).true? )
  50. assert( ! (1 == 2).true? )
  51. end
  52. def test_bool?
  53. assert_equal( true, true.bool? )
  54. assert_equal( true, false.bool? )
  55. assert_equal( false, nil.bool? )
  56. assert_equal( false, 0.bool? )
  57. end
  58. end
  59. class TestBoolean < Test::Unit::TestCase
  60. def test_to_bool
  61. assert_equal( true, true.to_bool )
  62. assert_equal( false, false.to_bool )
  63. assert_equal( false, nil.to_bool )
  64. end
  65. end