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

Language Ruby Lines 86
MD5 Hash de1e6a2359c102707691343c2ca0b8e0 Estimated Cost $848 (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
require 'facets/file.rb'
require 'test/unit'
require 'tempfile'

class TC_File_Sanitize < Test::Unit::TestCase

  # mock file

  class MockFile < File
    def self.open( fname, mode, &blk )
      blk.call(self)
    end
    def self.read( fname=nil )
      @mock_content.clone
    end
    def self.write( str )
      @mock_content = str
    end
    def self.<<( str )
      (@mock_content ||="") << str
    end
  end

  # TODO Write file identity tests.

  def test_sanitize_01
    assert_equal( "This_is_a_test", MockFile.sanitize('This is a test') )
  end

  def test_sanitize_02
    assert_equal( "test", MockFile.sanitize('This\is\test') )
  end

  def test_sanitize_03
    assert_equal( "test", MockFile.sanitize('This/is/test') )
  end

  def test_sanitize_04
    assert_equal( "te_____st", MockFile.sanitize('This/te#$#@!st') )
  end

  def test_sanitize_05
    assert_equal( "_.", MockFile.sanitize('.') )
  end

  def test_sanitize_06
    assert_equal( "_....", MockFile.sanitize('....') )
  end

end

# class TestFileRead < Test::Unit::TestCase
#
#
#   class MockFile < ::File
#     def open( fname, mode, &blk )
#       blk.call(self)
#     end
#     def read( fname=nil )
#       @mock_content.clone
#     end
#     def write( str )
#       @mock_content = str
#     end
#     def <<( str )
#       (@mock_content ||="") << str
#     end
#   end
#
#   File = MockFile.new
#
#   def test_read_list
#     f = File.write("A\nB\nC")
#     s = File.read_list( f )
#     r = ['A','B','C']
#     assert_equal( r, s )
#   end
#
# end

# Test for facets/file/write.rb

# TODO Needs a file mock.
Back to Top