PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/file/test_file.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 85 lines | 37 code | 16 blank | 32 comment | 0 complexity | de1e6a2359c102707691343c2ca0b8e0 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/file.rb'
  2. require 'test/unit'
  3. require 'tempfile'
  4. class TC_File_Sanitize < Test::Unit::TestCase
  5. # mock file
  6. class MockFile < File
  7. def self.open( fname, mode, &blk )
  8. blk.call(self)
  9. end
  10. def self.read( fname=nil )
  11. @mock_content.clone
  12. end
  13. def self.write( str )
  14. @mock_content = str
  15. end
  16. def self.<<( str )
  17. (@mock_content ||="") << str
  18. end
  19. end
  20. # TODO Write file identity tests.
  21. def test_sanitize_01
  22. assert_equal( "This_is_a_test", MockFile.sanitize('This is a test') )
  23. end
  24. def test_sanitize_02
  25. assert_equal( "test", MockFile.sanitize('This\is\test') )
  26. end
  27. def test_sanitize_03
  28. assert_equal( "test", MockFile.sanitize('This/is/test') )
  29. end
  30. def test_sanitize_04
  31. assert_equal( "te_____st", MockFile.sanitize('This/te#$#@!st') )
  32. end
  33. def test_sanitize_05
  34. assert_equal( "_.", MockFile.sanitize('.') )
  35. end
  36. def test_sanitize_06
  37. assert_equal( "_....", MockFile.sanitize('....') )
  38. end
  39. end
  40. # class TestFileRead < Test::Unit::TestCase
  41. #
  42. #
  43. # class MockFile < ::File
  44. # def open( fname, mode, &blk )
  45. # blk.call(self)
  46. # end
  47. # def read( fname=nil )
  48. # @mock_content.clone
  49. # end
  50. # def write( str )
  51. # @mock_content = str
  52. # end
  53. # def <<( str )
  54. # (@mock_content ||="") << str
  55. # end
  56. # end
  57. #
  58. # File = MockFile.new
  59. #
  60. # def test_read_list
  61. # f = File.write("A\nB\nC")
  62. # s = File.read_list( f )
  63. # r = ['A','B','C']
  64. # assert_equal( r, s )
  65. # end
  66. #
  67. # end
  68. # Test for facets/file/write.rb
  69. # TODO Needs a file mock.