ptools 1.1.9-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'ptools'
6
+ gem.version = '1.1.9'
7
+ gem.license = 'Artistic 2.0'
8
+ gem.author = 'Daniel J. Berger'
9
+ gem.email = 'djberg96@gmail.com'
10
+ gem.homepage = 'http://www.rubyforge.org/projects/shards'
11
+ gem.summary = 'Extra methods for the File class'
12
+ gem.test_files = Dir['test/test*']
13
+ gem.has_rdoc = true
14
+ gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') || f.include?('git') }
15
+
16
+ gem.rubyforge_project = 'shards'
17
+ gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
18
+
19
+ gem.description = <<-EOF
20
+ The ptools (power tools) library provides several handy methods to
21
+ Ruby's core File class, such as File.which for finding executables,
22
+ File.null to return the null device on your platform, and so on.
23
+ EOF
24
+
25
+ gem.add_development_dependency('test-unit', '>= 2.0.7')
26
+
27
+ if Config::CONFIG['host_os'] =~ /mswin|win32|msdos|cygwin|mingw/i
28
+ gem.platform = Gem::Platform::CURRENT
29
+ gem.add_dependency('win32-file', '>= 0.5.4')
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ #####################################################################
2
+ # tc_binary.rb
3
+ #
4
+ # Test case for the File.binary? method. You should run this test
5
+ # via the 'rake test_binary' task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'ptools'
12
+
13
+ class TC_Binary < 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
+ @text_file = 'test_file1.txt'
21
+ end
22
+
23
+ def test_binary_basic
24
+ assert_respond_to(File, :binary?)
25
+ assert_nothing_raised{ File.binary?(@text_file) }
26
+ end
27
+
28
+ def test_binary_expected_results
29
+ assert_equal(false, File.binary?(@text_file))
30
+ end
31
+
32
+ def test_binary_expected_errors
33
+ assert_raise_kind_of(SystemCallError){ File.binary?('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
43
+ end
@@ -0,0 +1,32 @@
1
+ #####################################################################
2
+ # test_constants.rb
3
+ #
4
+ # Tests the constants that have been defined for our package. This
5
+ # test case should be run via the 'rake test_constants' task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'rbconfig'
12
+ require 'ptools'
13
+
14
+ class TC_Constants < Test::Unit::TestCase
15
+ def test_version
16
+ assert_equal('1.1.9', File::PTOOLS_VERSION)
17
+ end
18
+
19
+ def test_image_ext
20
+ assert_equal(%w/.bmp .gif .jpeg .jpg .png/, File::IMAGE_EXT.sort)
21
+ end
22
+
23
+ def test_windows
24
+ omit_unless(Config::CONFIG['host_os'].match('mswin'), "Skipping on Unix systems")
25
+ assert_not_nil(File::IS_WINDOWS)
26
+ end
27
+
28
+ def test_win32exts
29
+ omit_unless(Config::CONFIG['host_os'].match('mswin'), "Skipping on Unix systems")
30
+ assert_not_nil(File::WIN32EXTS)
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ ######################################################################
2
+ # test_head.rb
3
+ #
4
+ # Test case for the File.head method. This test should be run via
5
+ # the 'rake test_head' task.
6
+ ######################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'ptools'
12
+
13
+ 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
25
+
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
32
+
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
38
+
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
43
+
44
+ def teardown
45
+ @test_file = nil
46
+ end
47
+
48
+ def self.shutdown
49
+ File.delete('test_file1.txt') if File.exists?('test_file1.txt')
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ #####################################################################
2
+ # test_image.rb
3
+ #
4
+ # Test case for the File.image? method. You should run this test
5
+ # via the 'rake test_image' task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'ptools'
12
+
13
+ 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
43
+ end
@@ -0,0 +1,61 @@
1
+ #####################################################################
2
+ # test_middle.rb
3
+ #
4
+ # Test case for the File.middle method. You should run this test
5
+ # via the 'rake test_middle' task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'ptools'
12
+
13
+ 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
61
+ end
@@ -0,0 +1,89 @@
1
+ #####################################################################
2
+ # test_nlconvert.rb
3
+ #
4
+ # Test case for the File.nl_convert method. You should run this
5
+ # test via the 'rake test_nlconvert' task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'ptools'
12
+
13
+ class TC_FileNLConvert < 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
+ File.open('test_file2.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
18
+ end
19
+
20
+ def setup
21
+ @test_file1 = 'test_file1.txt'
22
+ @test_file2 = 'test_file2.txt'
23
+ @dos_file = 'dos_test_file.txt'
24
+ @mac_file = 'mac_test_file.txt'
25
+ @unix_file = 'nix_test_file.txt'
26
+ end
27
+
28
+ def test_nl_convert_basic
29
+ assert_respond_to(File, :nl_convert)
30
+ assert_nothing_raised{ File.nl_convert(@test_file2) }
31
+ assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2) }
32
+ assert_nothing_raised{ File.nl_convert(@test_file2, @test_file2, "unix") }
33
+ end
34
+
35
+ def test_nl_convert_to_dos
36
+ msg = "dos file should be larger, but isn't"
37
+
38
+ assert_nothing_raised{ File.nl_convert(@test_file1, @dos_file, "dos") }
39
+ assert_equal(true, File.size(@dos_file) > File.size(@test_file1), msg)
40
+ assert_equal(["\cM","\cJ"],
41
+ IO.readlines(@dos_file).first.split("")[-2..-1]
42
+ )
43
+ end
44
+
45
+ def test_nl_convert_to_mac
46
+ assert_nothing_raised{ File.nl_convert(@test_file1, @mac_file, 'mac') }
47
+ assert_equal("\cM", IO.readlines(@mac_file).first.split("").last)
48
+
49
+ omit_if(Config::CONFIG['host_os'] =~ /win32|mswin|dos|cygwin|mingw/i)
50
+ msg = "=> Mac file should be the same size (or larger), but isn't"
51
+ assert_true(File.size(@mac_file) == File.size(@test_file1), msg)
52
+ end
53
+
54
+ def test_nl_convert_to_unix
55
+ msg = "unix file should be the same size (or smaller), but isn't"
56
+
57
+ assert_nothing_raised{ File.nl_convert(@test_file1, @unix_file, "unix") }
58
+ assert_equal("\n", IO.readlines(@unix_file).first.split("").last)
59
+
60
+ if File::ALT_SEPARATOR
61
+ assert_equal(true, File.size(@unix_file) >= File.size(@test_file1),msg)
62
+ else
63
+ assert_equal(true, File.size(@unix_file) <= File.size(@test_file1),msg)
64
+ end
65
+ end
66
+
67
+ def test_nl_convert_expected_errors
68
+ assert_raises(ArgumentError){ File.nl_convert }
69
+ assert_raises(ArgumentError){
70
+ File.nl_convert(@test_file1, "bogus.txt", "blah")
71
+ }
72
+ end
73
+
74
+ def teardown
75
+ [@dos_file, @mac_file, @unix_file].each{ |file|
76
+ File.delete(file) if File.exists?(file)
77
+ }
78
+ @dos_file = nil
79
+ @mac_file = nil
80
+ @unix_file = nil
81
+ @test_file1 = nil
82
+ @test_file2 = nil
83
+ end
84
+
85
+ def self.shutdown
86
+ File.delete('test_file1.txt') if File.exists?('test_file1.txt')
87
+ File.delete('test_file2.txt') if File.exists?('test_file2.txt')
88
+ end
89
+ end
@@ -0,0 +1,37 @@
1
+ #####################################################################
2
+ # test_null.rb
3
+ #
4
+ # Test case for the File.null method. You should run this test via
5
+ # the 'rake test_null' task.
6
+ #####################################################################
7
+ require 'test/unit'
8
+ require 'ptools'
9
+
10
+ class TC_Null < Test::Unit::TestCase
11
+ def setup
12
+ @nulls = ['/dev/null', 'NUL', 'NIL:', 'NL:']
13
+ end
14
+
15
+ def test_null_basic
16
+ assert_respond_to(File, :null)
17
+ assert_nothing_raised{ File.null }
18
+ end
19
+
20
+ def test_null_expected_results
21
+ assert_kind_of(String, File.null)
22
+ assert(@nulls.include?(File.null))
23
+ end
24
+
25
+ def test_null_expected_errors
26
+ assert_raises(ArgumentError){ File.null(1) }
27
+ end
28
+
29
+ def test_null_device_alias
30
+ assert_respond_to(File, :null_device)
31
+ assert_equal(true, File.method(:null) == File.method(:null_device))
32
+ end
33
+
34
+ def teardown
35
+ @nulls = nil
36
+ end
37
+ end
@@ -0,0 +1,56 @@
1
+ #####################################################################
2
+ # test_tail.rb
3
+ #
4
+ # Test case for the File.tail method. This test should be run via
5
+ # the 'rake test_tail' task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'ptools'
12
+
13
+ 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
56
+ end