ptools 1.2.3-universal-mingw32 → 1.2.4-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aab93763e9329f79313e50cb5f7137312c9fc0d
4
- data.tar.gz: e58c83afbb52f088b766b21e50b8c65ebae1348d
3
+ metadata.gz: ac21ce3ffb8aa8dcb92d1b68a643e8d2f16a3d3a
4
+ data.tar.gz: 66be57ae67363a6efa93269a4bcce4003ee45f08
5
5
  SHA512:
6
- metadata.gz: 4b3c28fa6066055f6b68dbc169aadba02b46f0c31a0547c39508ec2252ec4ca9ba9e6e776d553fa7b06d8a10c5149a372a9b76701584fac0d03ab7632b12555d
7
- data.tar.gz: efaf6a4e6a98ce9267febbf05a1dd320152dde55af0443e87b90794f9949585b010528ec0c5bca95f7f2571e16bae28fc2c39b8f0417fa8918e23733141b32d3
6
+ metadata.gz: 027fce7e6924732d99331c520cc2bcc37979c471f85a0dd28ea141c3dc582a579bea952072a4810b3d8ab544f398c01e59efafde44f353de0471e4fa6c84a337
7
+ data.tar.gz: 51ec3df25f8bfdab9ff0253f6bf97d8a1a626b9126edb8a1cb2de70a849502ff841ee9d9accf463c08c24777c7f29d4fa52fbd1b8d4224c1beb0f34c13373608
data/CHANGES CHANGED
@@ -1,7 +1,14 @@
1
+ == 1.2.4 - 25-Feb-2014
2
+ * The File.binary method now always returns false for images. It is meant to
3
+ detect executables, shared objects, etc. Use File.image? to detect images.
4
+ * Encoding fixes for the File.image? method.
5
+
1
6
  == 1.2.3 - 19-Feb-2014
2
7
  * Fixed a bug where File.binary? would return true for unicode text. Thanks go
3
8
  to Ben Hollis for the spot.
4
9
  * Updated the win32-file and test-unit dependencies.
10
+ * Replace all instances of File.exists? with File.exist? because the former
11
+ is deprecated in Ruby 2.1 and later.
5
12
 
6
13
  == 1.2.2 - 6-Apr-2012
7
14
  * Yet another sparse file test fix for OSX, which does not support
data/Rakefile CHANGED
@@ -68,6 +68,13 @@ namespace 'test' do
68
68
  t.test_files = FileList['test/test_head.rb']
69
69
  end
70
70
 
71
+ Rake::TestTask.new('image') do |t|
72
+ t.libs << 'test'
73
+ t.verbose = true
74
+ t.warning = true
75
+ t.test_files = FileList['test/test_image.rb']
76
+ end
77
+
71
78
  Rake::TestTask.new('middle') do |t|
72
79
  t.libs << 'test'
73
80
  t.verbose = true
data/lib/ptools.rb CHANGED
@@ -3,7 +3,7 @@ require 'win32/file' if File::ALT_SEPARATOR
3
3
 
4
4
  class File
5
5
  # The version of the ptools library.
6
- PTOOLS_VERSION = '1.2.3'
6
+ PTOOLS_VERSION = '1.2.4'
7
7
 
8
8
  # :stopdoc:
9
9
 
@@ -28,13 +28,12 @@ class File
28
28
  #
29
29
  # This method does some simple read and extension checks. For a version
30
30
  # that is more robust, but which depends on a 3rd party C library (and is
31
- # difficult to build on MS Windows), see the 'filemagic' library, available
32
- # on the RAA.
31
+ # difficult to build on MS Windows), see the 'filemagic' library.
33
32
  #
34
33
  # Examples:
35
34
  #
36
35
  # File.image?('somefile.jpg') # => true
37
- # File.image?('somefile.txt') # => true
36
+ # File.image?('somefile.txt') # => false
38
37
  #--
39
38
  # The approach I used here is based on information found at
40
39
  # http://en.wikipedia.org/wiki/Magic_number_(programming)
@@ -75,9 +74,10 @@ class File
75
74
  alias null_device null
76
75
  end
77
76
 
78
- # Returns whether or not +file+ is a binary file. Note that this is
79
- # not guaranteed to be 100% accurate. It performs a "best guess" based
80
- # on a simple test of the first +File.blksize+ characters.
77
+ # Returns whether or not +file+ is a binary non-image file, i.e. executable,
78
+ # shared object, ect. Note that this is NOT guaranteed to be 100% accurate.
79
+ # It performs a "best guess" based on a simple test of the first
80
+ # +File.blksize+ characters.
81
81
  #
82
82
  # Example:
83
83
  #
@@ -88,7 +88,9 @@ class File
88
88
  # based on Perl's -B switch).
89
89
  #
90
90
  def self.binary?(file)
91
- s = (File.read(file, File.stat(file).blksize) || "").encode('US-ASCII', :undef => :replace).split(//)
91
+ return false if image?(file)
92
+ s = (File.read(file, File.stat(file).blksize) || "")
93
+ s = s.encode('US-ASCII', :undef => :replace).split(//)
92
94
  ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
93
95
  end
94
96
 
@@ -123,7 +125,7 @@ class File
123
125
 
124
126
  # Iterate over each path glob the dir + program.
125
127
  path.split(File::PATH_SEPARATOR).each{ |dir|
126
- next unless File.exists?(dir) # In case of bogus second argument
128
+ next unless File.exist?(dir) # In case of bogus second argument
127
129
  file = File.join(dir, program)
128
130
 
129
131
  # Dir[] doesn't handle backslashes properly, so convert them. Also, if
@@ -182,7 +184,7 @@ class File
182
184
 
183
185
  # Iterate over each path glob the dir + program.
184
186
  path.split(File::PATH_SEPARATOR).each{ |dir|
185
- next unless File.exists?(dir) # In case of bogus second argument
187
+ next unless File.exist?(dir) # In case of bogus second argument
186
188
  file = File.join(dir, program)
187
189
 
188
190
  # Dir[] doesn't handle backslashes properly, so convert them. Also, if
@@ -332,7 +334,7 @@ class File
332
334
  # byte file +filename+ if it doesn't already exist.
333
335
  #
334
336
  def self.touch(filename)
335
- if File.exists?(filename)
337
+ if File.exist?(filename)
336
338
  time = Time.now
337
339
  File.utime(time, time, filename)
338
340
  else
@@ -416,11 +418,11 @@ class File
416
418
  end
417
419
 
418
420
  def self.jpg?(file)
419
- IO.read(file, 10) == "\377\330\377\340\000\020JFIF"
421
+ IO.read(file, 10, encoding: 'binary') == "\377\330\377\340\000\020JFIF".force_encoding(Encoding::BINARY)
420
422
  end
421
423
 
422
424
  def self.png?(file)
423
- IO.read(file, 4) == "\211PNG"
425
+ IO.read(file, 4, encoding: 'binary') == "\211PNG".force_encoding(Encoding::BINARY)
424
426
  end
425
427
 
426
428
  def self.gif?(file)
data/ptools.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'rbconfig'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'ptools'
6
- gem.version = '1.2.3'
6
+ gem.version = '1.2.4'
7
7
  gem.license = 'Artistic 2.0'
8
8
  gem.author = 'Daniel J. Berger'
9
9
  gem.email = 'djberg96@gmail.com'
data/test/img/test.gif ADDED
Binary file
data/test/img/test.jpg ADDED
Binary file
data/test/img/test.png ADDED
Binary file
data/test/test_binary.rb CHANGED
@@ -10,38 +10,56 @@ require 'ptools'
10
10
 
11
11
  class TC_Ptools_Binary < Test::Unit::TestCase
12
12
  def self.startup
13
- @@txt_file = 'test_binary.txt'
14
-
15
13
  if File::ALT_SEPARATOR
16
14
  @@bin_file = File.join(ENV['windir'], 'notepad.exe')
17
15
  else
18
16
  @@bin_file = '/bin/ls'
19
17
  end
20
18
 
21
- Dir.chdir('test') if File.exists?('test')
19
+ Dir.chdir('test') if File.exist?('test')
20
+ end
22
21
 
23
- File.open(@@txt_file, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
22
+ def setup
23
+ @txt_file = File.join('txt', 'english.txt')
24
+ @uni_file = File.join('txt', 'korean.txt')
25
+ @png_file = File.join('img', 'test.png')
26
+ @jpg_file = File.join('img', 'test.jpg')
27
+ @gif_file = File.join('img', 'test.gif')
24
28
  end
25
29
 
26
30
  test "File.binary? basic functionality" do
27
31
  assert_respond_to(File, :binary?)
28
- assert_nothing_raised{ File.binary?(@@txt_file) }
32
+ assert_nothing_raised{ File.binary?(@txt_file) }
29
33
  end
30
34
 
31
- test "File.binary? returns expected results" do
32
- assert_false(File.binary?(@@txt_file))
35
+ test "File.binary? returns true for binary files" do
33
36
  assert_true(File.binary?(@@bin_file))
34
37
  end
35
38
 
39
+ test "File.binary? returns false for text files" do
40
+ assert_false(File.binary?(@txt_file))
41
+ assert_false(File.binary?(@uni_file))
42
+ end
43
+
44
+ test "File.binary? returns false for image files" do
45
+ assert_false(File.binary?(@png_file))
46
+ assert_false(File.binary?(@jpg_file))
47
+ assert_false(File.binary?(@gif_file))
48
+ end
49
+
36
50
  test "File.binary? raises an error if the file cannot be found" do
37
51
  assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
38
52
  end
39
53
 
40
54
  test "File.binary? only accepts one argument" do
41
- assert_raise_kind_of(ArgumentError){ File.binary?(@@txt_file, @@bin_file) }
55
+ assert_raise_kind_of(ArgumentError){ File.binary?(@txt_file, @@bin_file) }
42
56
  end
43
57
 
44
- def self.shutdown
45
- File.delete(@@txt_file) if File.exists?(@@txt_file)
58
+ def teardown
59
+ @txt_file = nil
60
+ @uni_file = nil
61
+ @png_file = nil
62
+ @jpg_file = nil
63
+ @gif_file = nil
46
64
  end
47
65
  end
@@ -15,7 +15,7 @@ class TC_Ptools_Constants < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  test "PTOOLS_VERSION constant is set to expected value" do
18
- assert_equal('1.2.3', File::PTOOLS_VERSION)
18
+ assert_equal('1.2.4', File::PTOOLS_VERSION)
19
19
  end
20
20
 
21
21
  test "IMAGE_EXT constant is set to array of values" do
data/test/test_head.rb CHANGED
@@ -1,51 +1,48 @@
1
1
  ######################################################################
2
2
  # test_head.rb
3
- #
3
+ #
4
4
  # Test case for the File.head method. This test should be run via
5
5
  # the 'rake test_head' task.
6
6
  ######################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_FileHead < Test::Unit::TestCase
14
- def self.startup
15
- Dir.chdir('test') if File.exists?('test')
16
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
17
- end
18
-
19
- def setup
20
- @test_file = 'test_file1.txt'
21
- @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
22
- @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
23
- @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
24
- end
11
+ def self.startup
12
+ Dir.chdir('test') if File.exist?('test')
13
+ File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
14
+ end
15
+
16
+ def setup
17
+ @test_file = 'test_file1.txt'
18
+ @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
19
+ @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
20
+ @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
21
+ end
25
22
 
26
- def test_head_basic
27
- assert_respond_to(File, :head)
28
- assert_nothing_raised{ File.head(@test_file) }
29
- assert_nothing_raised{ File.head(@test_file, 5) }
30
- assert_nothing_raised{ File.head(@test_file){} }
31
- end
23
+ def test_head_basic
24
+ assert_respond_to(File, :head)
25
+ assert_nothing_raised{ File.head(@test_file) }
26
+ assert_nothing_raised{ File.head(@test_file, 5) }
27
+ assert_nothing_raised{ File.head(@test_file){} }
28
+ end
32
29
 
33
- def test_head_expected_results
34
- assert_kind_of(Array, File.head(@test_file))
35
- assert_equal(@expected_head1, File.head(@test_file))
36
- assert_equal(@expected_head2, File.head(@test_file, 5))
37
- end
30
+ def test_head_expected_results
31
+ assert_kind_of(Array, File.head(@test_file))
32
+ assert_equal(@expected_head1, File.head(@test_file))
33
+ assert_equal(@expected_head2, File.head(@test_file, 5))
34
+ end
38
35
 
39
- def test_head_expected_errors
40
- assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
41
- assert_raises(Errno::ENOENT){ File.head("bogus") }
42
- end
36
+ def test_head_expected_errors
37
+ assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
38
+ assert_raises(Errno::ENOENT){ File.head("bogus") }
39
+ end
43
40
 
44
- def teardown
45
- @test_file = nil
46
- end
41
+ def teardown
42
+ @test_file = nil
43
+ end
47
44
 
48
- def self.shutdown
49
- File.delete('test_file1.txt') if File.exists?('test_file1.txt')
50
- end
45
+ def self.shutdown
46
+ File.delete('test_file1.txt') if File.exist?('test_file1.txt')
47
+ end
51
48
  end
data/test/test_image.rb CHANGED
@@ -1,43 +1,57 @@
1
1
  #####################################################################
2
2
  # test_image.rb
3
- #
3
+ #
4
4
  # Test case for the File.image? method. You should run this test
5
- # via the 'rake test_image' task.
5
+ # via the 'rake test:image' task.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_Ptools_Image < Test::Unit::TestCase
14
- def self.startup
15
- Dir.chdir('test') if File.exists?('test')
16
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
17
- end
18
-
19
- def setup
20
- @text_file = 'test_file1.txt'
21
- end
22
-
23
- def test_image_basic
24
- assert_respond_to(File, :image?)
25
- assert_nothing_raised{ File.image?(@text_file) }
26
- end
27
-
28
- def test_image_expected_results
29
- assert_equal(false, File.image?(@text_file))
30
- end
31
-
32
- def test_image_expected_errors
33
- assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
34
- end
35
-
36
- def teardown
37
- @text_file = nil
38
- end
39
-
40
- def self.shutdown
41
- File.delete('test_file1.txt') if File.exists?('test_file1.txt')
42
- end
11
+ def self.startup
12
+ Dir.chdir('test') if File.exist?('test')
13
+ end
14
+
15
+ def setup
16
+ @txt_file = File.join(Dir.pwd, 'txt', 'english.txt')
17
+ @uni_file = File.join(Dir.pwd, 'txt', 'korean.txt')
18
+ @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
19
+ @png_file = File.join(Dir.pwd, 'img', 'test.png')
20
+ @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
21
+ end
22
+
23
+ test "image? method basic functionality" do
24
+ assert_respond_to(File, :image?)
25
+ assert_nothing_raised{ File.image?(@txt_file) }
26
+ assert_boolean(File.image?(@txt_file))
27
+ end
28
+
29
+ test "image? method returns false for a text file" do
30
+ assert_false(File.image?(@txt_file))
31
+ assert_false(File.image?(@uni_file))
32
+ end
33
+
34
+ test "image? method returns true for a gif" do
35
+ assert_true(File.image?(@gif_file))
36
+ end
37
+
38
+ test "image? method returns true for a jpeg" do
39
+ assert_true(File.image?(@jpg_file))
40
+ end
41
+
42
+ test "image? method returns true for a png" do
43
+ assert_true(File.image?(@png_file))
44
+ end
45
+
46
+ test "image? method raises an error if the file does not exist" do
47
+ assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
48
+ end
49
+
50
+ def teardown
51
+ @txt_file = nil
52
+ @uni_file = nil
53
+ @jpg_file = nil
54
+ @png_file = nil
55
+ @gif_file = nil
56
+ end
43
57
  end
@@ -4,15 +4,12 @@
4
4
  # Test case for the File.sparse? method. You should run this test
5
5
  # via the 'rake test:is_sparse' task.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_IsSparse < Test::Unit::TestCase
14
11
  def self.startup
15
- Dir.chdir("test") if File.exists?("test")
12
+ Dir.chdir("test") if File.exist?("test")
16
13
  @@win = RbConfig::CONFIG['host_os'] =~ /windows|mswin|dos|cygwin|mingw/i
17
14
  @@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
18
15
  @@sun = RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
data/test/test_middle.rb CHANGED
@@ -4,58 +4,55 @@
4
4
  # Test case for the File.middle method. You should run this test
5
5
  # via the 'rake test_middle' task.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_FileMiddle < Test::Unit::TestCase
14
- def self.startup
15
- Dir.chdir('test') if File.exists?('test')
16
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
17
- end
18
-
19
- def setup
20
- @test_file = 'test_file1.txt'
21
-
22
- @expected_middle1 = ["line10\n", "line11\n", "line12\n", "line13\n", "line14\n"]
23
- @expected_middle1.push("line15\n","line16\n", "line17\n", "line18\n")
24
- @expected_middle1.push("line19\n","line20\n")
25
-
26
- @expected_middle2 = ["line14\n","line15\n","line16\n","line17\n"]
27
- @expected_middle2.push("line18\n","line19\n","line20\n")
28
-
29
- @expected_middle3 = ["line5\n","line6\n","line7\n"]
30
- @expected_middle3.push("line8\n","line9\n","line10\n")
31
- end
32
-
33
- def test_method_basic
34
- assert_respond_to(File, :middle)
35
- assert_nothing_raised{ File.middle(@test_file) }
36
- assert_nothing_raised{ File.middle(@test_file, 14) }
37
- assert_nothing_raised{ File.middle(@test_file, 5, 10) }
38
- assert_nothing_raised{ File.middle(@test_file){} }
39
- end
40
-
41
- def test_middle_expected_results
42
- assert_kind_of(Array, File.middle(@test_file))
43
- assert_equal(@expected_middle1, File.middle(@test_file))
44
- assert_equal(@expected_middle2, File.middle(@test_file, 14))
45
- assert_equal(@expected_middle3, File.middle(@test_file, 5, 10))
46
- end
47
-
48
- def test_middle_expected_errors
49
- assert_raises(ArgumentError){ File.middle }
50
- assert_raises(ArgumentError){ File.middle(@test_file, 5, 10, 15) }
51
- assert_raises(NoMethodError){ File.middle(@test_file, "foo") }
52
- assert_raises(Errno::ENOENT){ File.middle("bogus") }
53
- end
54
-
55
- def teardown
56
- @test_file = nil
57
- @expected_middle1 = nil
58
- @expected_middle2 = nil
59
- @expected_middle3 = nil
60
- end
11
+ def self.startup
12
+ Dir.chdir('test') if File.exist?('test')
13
+ File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
14
+ end
15
+
16
+ def setup
17
+ @test_file = 'test_file1.txt'
18
+
19
+ @expected_middle1 = ["line10\n", "line11\n", "line12\n", "line13\n", "line14\n"]
20
+ @expected_middle1.push("line15\n","line16\n", "line17\n", "line18\n")
21
+ @expected_middle1.push("line19\n","line20\n")
22
+
23
+ @expected_middle2 = ["line14\n","line15\n","line16\n","line17\n"]
24
+ @expected_middle2.push("line18\n","line19\n","line20\n")
25
+
26
+ @expected_middle3 = ["line5\n","line6\n","line7\n"]
27
+ @expected_middle3.push("line8\n","line9\n","line10\n")
28
+ end
29
+
30
+ def test_method_basic
31
+ assert_respond_to(File, :middle)
32
+ assert_nothing_raised{ File.middle(@test_file) }
33
+ assert_nothing_raised{ File.middle(@test_file, 14) }
34
+ assert_nothing_raised{ File.middle(@test_file, 5, 10) }
35
+ assert_nothing_raised{ File.middle(@test_file){} }
36
+ end
37
+
38
+ def test_middle_expected_results
39
+ assert_kind_of(Array, File.middle(@test_file))
40
+ assert_equal(@expected_middle1, File.middle(@test_file))
41
+ assert_equal(@expected_middle2, File.middle(@test_file, 14))
42
+ assert_equal(@expected_middle3, File.middle(@test_file, 5, 10))
43
+ end
44
+
45
+ def test_middle_expected_errors
46
+ assert_raises(ArgumentError){ File.middle }
47
+ assert_raises(ArgumentError){ File.middle(@test_file, 5, 10, 15) }
48
+ assert_raises(NoMethodError){ File.middle(@test_file, "foo") }
49
+ assert_raises(Errno::ENOENT){ File.middle("bogus") }
50
+ end
51
+
52
+ def teardown
53
+ @test_file = nil
54
+ @expected_middle1 = nil
55
+ @expected_middle2 = nil
56
+ @expected_middle3 = nil
57
+ end
61
58
  end
@@ -10,7 +10,7 @@ require 'ptools'
10
10
 
11
11
  class TC_Ptools_NLConvert < Test::Unit::TestCase
12
12
  def self.startup
13
- Dir.chdir('test') if File.exists?('test')
13
+ Dir.chdir('test') if File.exist?('test')
14
14
  @@test_file1 = 'test_nl_convert1.txt'
15
15
  @@test_file2 = 'test_nl_convert2.txt'
16
16
  File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
@@ -83,7 +83,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
83
83
 
84
84
  def teardown
85
85
  [@dos_file, @mac_file, @unix_file].each{ |file|
86
- File.delete(file) if File.exists?(file)
86
+ File.delete(file) if File.exist?(file)
87
87
  }
88
88
  @dos_file = nil
89
89
  @mac_file = nil
@@ -93,7 +93,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
93
93
  end
94
94
 
95
95
  def self.shutdown
96
- File.delete(@@test_file1) if File.exists?(@@test_file1)
97
- File.delete(@@test_file2) if File.exists?(@@test_file2)
96
+ File.delete(@@test_file1) if File.exist?(@@test_file1)
97
+ File.delete(@@test_file2) if File.exist?(@@test_file2)
98
98
  end
99
99
  end
data/test/test_tail.rb CHANGED
@@ -4,53 +4,50 @@
4
4
  # Test case for the File.tail method. This test should be run via
5
5
  # the 'rake test_tail' task.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_FileTail < Test::Unit::TestCase
14
- def self.startup
15
- Dir.chdir('test') if File.exists?('test')
16
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
17
- end
18
-
19
- def setup
20
- @test_file = 'test_file1.txt'
21
-
22
- @expected_tail1 = ["line16\n","line17\n","line18\n","line19\n"]
23
- @expected_tail1.push("line20\n","line21\n","line22\n", "line23\n")
24
- @expected_tail1.push("line24\n","line25\n")
25
-
26
- @expected_tail2 = ["line21\n","line22\n","line23\n","line24\n","line25\n"]
27
- end
28
-
29
- def test_tail_basic
30
- assert_respond_to(File, :tail)
31
- assert_nothing_raised{ File.tail(@test_file) }
32
- assert_nothing_raised{ File.tail(@test_file, 5) }
33
- assert_nothing_raised{ File.tail(@test_file){} }
34
- end
35
-
36
- def test_tail_expected_return_values
37
- assert_kind_of(Array, File.tail(@test_file))
38
- assert_equal(@expected_tail1, File.tail(@test_file))
39
- assert_equal(@expected_tail2, File.tail(@test_file, 5))
40
- end
41
-
42
- def test_tail_expected_errors
43
- assert_raises(ArgumentError){ File.tail }
44
- assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
45
- end
46
-
47
- def teardown
48
- @test_file = nil
49
- @expected_tail1 = nil
50
- @expected_tail2 = nil
51
- end
52
-
53
- def self.shutdown
54
- File.delete('test_file1.txt') if File.exists?('test_file1.txt')
55
- end
11
+ def self.startup
12
+ Dir.chdir('test') if File.exist?('test')
13
+ File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
14
+ end
15
+
16
+ def setup
17
+ @test_file = 'test_file1.txt'
18
+
19
+ @expected_tail1 = ["line16\n","line17\n","line18\n","line19\n"]
20
+ @expected_tail1.push("line20\n","line21\n","line22\n", "line23\n")
21
+ @expected_tail1.push("line24\n","line25\n")
22
+
23
+ @expected_tail2 = ["line21\n","line22\n","line23\n","line24\n","line25\n"]
24
+ end
25
+
26
+ def test_tail_basic
27
+ assert_respond_to(File, :tail)
28
+ assert_nothing_raised{ File.tail(@test_file) }
29
+ assert_nothing_raised{ File.tail(@test_file, 5) }
30
+ assert_nothing_raised{ File.tail(@test_file){} }
31
+ end
32
+
33
+ def test_tail_expected_return_values
34
+ assert_kind_of(Array, File.tail(@test_file))
35
+ assert_equal(@expected_tail1, File.tail(@test_file))
36
+ assert_equal(@expected_tail2, File.tail(@test_file, 5))
37
+ end
38
+
39
+ def test_tail_expected_errors
40
+ assert_raises(ArgumentError){ File.tail }
41
+ assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
42
+ end
43
+
44
+ def teardown
45
+ @test_file = nil
46
+ @expected_tail1 = nil
47
+ @expected_tail2 = nil
48
+ end
49
+
50
+ def self.shutdown
51
+ File.delete('test_file1.txt') if File.exist?('test_file1.txt')
52
+ end
56
53
  end
data/test/test_touch.rb CHANGED
@@ -1,55 +1,52 @@
1
1
  #####################################################################
2
- # tc_touch.rb
2
+ # test_touch.rb
3
3
  #
4
4
  # Test case for the File.touch method. This test should be run
5
5
  # via the 'rake test_touch task'.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_FileTouch < Test::Unit::TestCase
14
- def self.startup
15
- Dir.chdir('test') if File.exists?('test')
16
- File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
17
- end
18
-
19
- def setup
20
- @test_file = 'delete.this'
21
- @xfile = 'test_file1.txt'
22
- end
23
-
24
- def test_touch_basic
25
- assert_respond_to(File, :touch)
26
- assert_nothing_raised{ File.touch(@test_file) }
27
- end
28
-
29
- def test_touch_expected_results
30
- assert_equal(File, File.touch(@test_file))
31
- assert_equal(true, File.exists?(@test_file))
32
- assert_equal(0, File.size(@test_file))
33
- end
34
-
35
- def test_touch_existing_file
36
- stat = File.stat(@xfile)
37
- sleep 1
38
- assert_nothing_raised{ File.touch(@xfile) }
39
- assert_equal(true, File.size(@xfile) == stat.size)
40
- assert_equal(false, File.mtime(@xfile) == stat.mtime)
41
- end
42
-
43
- def test_touch_expected_errors
44
- assert_raises(ArgumentError){ File.touch }
45
- end
46
-
47
- def teardown
48
- File.delete(@test_file) if File.exists?(@test_file)
49
- @test_file = nil
50
- end
51
-
52
- def self.shutdown
53
- File.delete('test_file1.txt') if File.exists?('test_file1.txt')
54
- end
11
+ def self.startup
12
+ Dir.chdir('test') if File.exist?('test')
13
+ File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
14
+ end
15
+
16
+ def setup
17
+ @test_file = 'delete.this'
18
+ @xfile = 'test_file1.txt'
19
+ end
20
+
21
+ def test_touch_basic
22
+ assert_respond_to(File, :touch)
23
+ assert_nothing_raised{ File.touch(@test_file) }
24
+ end
25
+
26
+ def test_touch_expected_results
27
+ assert_equal(File, File.touch(@test_file))
28
+ assert_equal(true, File.exist?(@test_file))
29
+ assert_equal(0, File.size(@test_file))
30
+ end
31
+
32
+ def test_touch_existing_file
33
+ stat = File.stat(@xfile)
34
+ sleep 1
35
+ assert_nothing_raised{ File.touch(@xfile) }
36
+ assert_equal(true, File.size(@xfile) == stat.size)
37
+ assert_equal(false, File.mtime(@xfile) == stat.mtime)
38
+ end
39
+
40
+ def test_touch_expected_errors
41
+ assert_raises(ArgumentError){ File.touch }
42
+ end
43
+
44
+ def teardown
45
+ File.delete(@test_file) if File.exist?(@test_file)
46
+ @test_file = nil
47
+ end
48
+
49
+ def self.shutdown
50
+ File.delete('test_file1.txt') if File.exist?('test_file1.txt')
51
+ end
55
52
  end
data/test/test_wc.rb CHANGED
@@ -4,20 +4,17 @@
4
4
  # Test case for the File.wc method. This test should be run via
5
5
  # the 'rake test_wc' task.
6
6
  #####################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'ptools'
12
9
 
13
10
  class TC_FileWC < Test::Unit::TestCase
14
11
  def self.startup
15
- Dir.chdir('test') if File.exists?('test')
12
+ Dir.chdir('test') if File.exist?('test')
16
13
  File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
17
14
  @@test_file = 'test_file1.txt'
18
15
  end
19
-
20
- def setup
16
+
17
+ def setup
21
18
  @test_file = 'test_file1.txt'
22
19
  end
23
20
 
@@ -71,6 +68,6 @@ class TC_FileWC < Test::Unit::TestCase
71
68
  end
72
69
 
73
70
  def self.shutdown
74
- File.delete(@@test_file) if File.exists?(@@test_file)
71
+ File.delete(@@test_file) if File.exist?(@@test_file)
75
72
  end
76
73
  end
data/test/test_which.rb CHANGED
@@ -7,10 +7,7 @@
7
7
  # NOTE: I make the assumption that Ruby (or JRuby) is in your
8
8
  # PATH for these tests.
9
9
  #####################################################################
10
- require 'rubygems'
11
- gem 'test-unit'
12
-
13
- require 'test/unit'
10
+ require 'test-unit'
14
11
  require 'rbconfig'
15
12
  require 'fileutils'
16
13
  require 'ptools'
@@ -21,7 +18,7 @@ class TC_FileWhich < Test::Unit::TestCase
21
18
  @@dir = File.join(Dir.pwd, 'tempdir')
22
19
  @@non_exe = File.join(Dir.pwd, 'tempfile')
23
20
 
24
- Dir.mkdir(@@dir) unless File.exists?(@@dir)
21
+ Dir.mkdir(@@dir) unless File.exist?(@@dir)
25
22
  FileUtils.touch(@@non_exe)
26
23
  File.chmod(775, @@dir)
27
24
  File.chmod(644, @@non_exe)
@@ -0,0 +1 @@
1
+ Hello World
@@ -0,0 +1 @@
1
+ 한국어의 내용분석을 위한
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -57,6 +57,9 @@ files:
57
57
  - Rakefile
58
58
  - lib/ptools.rb
59
59
  - ptools.gemspec
60
+ - test/img/test.gif
61
+ - test/img/test.jpg
62
+ - test/img/test.png
60
63
  - test/test_binary.rb
61
64
  - test/test_constants.rb
62
65
  - test/test_head.rb
@@ -70,6 +73,8 @@ files:
70
73
  - test/test_wc.rb
71
74
  - test/test_whereis.rb
72
75
  - test/test_which.rb
76
+ - test/txt/english.txt
77
+ - test/txt/korean.txt
73
78
  homepage: https://github.com/djberg96/ptools
74
79
  licenses:
75
80
  - Artistic 2.0