ptools 1.3.3-universal-mingw32 → 1.4.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,26 @@
1
1
  -----BEGIN CERTIFICATE-----
2
- MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
3
  cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
- MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
5
  ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
- bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
7
- Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
8
- S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
9
- gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
10
- FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
11
- zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
12
- DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe
13
- nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv
14
- bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD
15
- ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
16
- tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
17
- /sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
18
- wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
19
- EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
20
- tGSHgAmcLlkdGgan182qsE/4kKM=
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
8
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
9
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
10
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
11
+ iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
12
+ ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
13
+ 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
14
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
15
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
16
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
17
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
18
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
19
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
20
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
21
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
22
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
23
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
24
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
25
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
21
26
  -----END CERTIFICATE-----
@@ -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.3.3'
6
+ PTOOLS_VERSION = '1.4.1'.freeze
7
7
 
8
8
  # :stopdoc:
9
9
 
@@ -23,8 +23,8 @@ class File
23
23
 
24
24
  # :startdoc:
25
25
 
26
- # Returns whether or not the file is an image. Only JPEG, PNG, BMP and
27
- # GIF are checked against.
26
+ # Returns whether or not the file is an image. Only JPEG, PNG, BMP,
27
+ # GIF, and ICO are checked against.
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
@@ -39,46 +39,20 @@ class File
39
39
  # http://en.wikipedia.org/wiki/Magic_number_(programming)
40
40
  #
41
41
  def self.image?(file)
42
- bool = IMAGE_EXT.include?(File.extname(file).downcase) # Match ext
43
- bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) || tiff?(file) # Check data
42
+ bool = IMAGE_EXT.include?(File.extname(file).downcase)
43
+ bool = bmp?(file) || jpg?(file) || png?(file) || gif?(file) || tiff?(file) || ico?(file)
44
44
  bool
45
45
  end
46
46
 
47
- # Returns the name of the null device (aka bitbucket) on your platform.
48
- #
49
- # Examples:
50
- #
51
- # # On Linux
52
- # File.null # => '/dev/null'
53
- #
54
- # # On MS Windows
55
- # File.null # => 'NUL'
56
- #--
57
- # The values I used here are based on information from
58
- # http://en.wikipedia.org/wiki//dev/null
59
- #
60
- def self.null
61
- case RbConfig::CONFIG['host_os']
62
- when /mswin|win32|msdos|mingw|windows/i
63
- 'NUL'
64
- when /amiga/i
65
- 'NIL:'
66
- when /openvms/i
67
- 'NL:'
68
- else
69
- '/dev/null'
70
- end
71
- end
72
-
73
- class << self
74
- alias null_device null
75
- end
76
-
77
47
  # Returns whether or not +file+ is a binary non-image file, i.e. executable,
78
48
  # shared object, ect. Note that this is NOT guaranteed to be 100% accurate.
79
49
  # It performs a "best guess" based on a simple test of the first
80
50
  # +File.blksize+ characters, or 4096, whichever is smaller.
81
51
  #
52
+ # By default it will check to see if more than 30 percent of the characters
53
+ # are non-text characters. If so, the method returns true. You can configure
54
+ # this percentage by passing your own as a second argument.
55
+ #
82
56
  # Example:
83
57
  #
84
58
  # File.binary?('somefile.exe') # => true
@@ -87,13 +61,15 @@ class File
87
61
  # Based on code originally provided by Ryan Davis (which, in turn, is
88
62
  # based on Perl's -B switch).
89
63
  #
90
- def self.binary?(file)
64
+ def self.binary?(file, percentage = 0.30)
65
+ return false if File.stat(file).zero?
91
66
  return false if image?(file)
67
+ return false if check_bom?(file)
92
68
  bytes = File.stat(file).blksize
93
69
  bytes = 4096 if bytes > 4096
94
70
  s = (File.read(file, bytes) || "")
95
71
  s = s.encode('US-ASCII', :undef => :replace).split(//)
96
- ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
72
+ ((s.size - s.grep(" ".."~").size) / s.size.to_f) > percentage
97
73
  end
98
74
 
99
75
  # Looks for the first occurrence of +program+ within +path+.
@@ -428,6 +404,20 @@ class File
428
404
 
429
405
  private
430
406
 
407
+ # Returns whether or not the given +text+ contains a BOM marker.
408
+ # If present, we can generally assume it's a text file.
409
+ #
410
+ def self.check_bom?(file)
411
+ text = File.read(file, 4).force_encoding('utf-8')
412
+
413
+ bool = false
414
+ bool = true if text[0,3] == "\xEF\xBB\xBF"
415
+ bool = true if text[0,4] == "\x00\x00\xFE\xFF" || text[0,4] == "\xFF\xFE\x00\x00"
416
+ bool = true if text[0,2] == "\xFF\xFE" || text[0,2] == "\xFE\xFF"
417
+
418
+ bool
419
+ end
420
+
431
421
  def self.nl_for_platform(platform)
432
422
  platform = RbConfig::CONFIG["host_os"] if platform == 'local'
433
423
 
@@ -465,7 +455,7 @@ class File
465
455
  bytes = IO.read(file, 4)
466
456
 
467
457
  # II is Intel, MM is Motorola
468
- if bytes[0..1] != 'II'&& bytes[0..1] != 'MM'
458
+ if bytes[0..1] != 'II' && bytes[0..1] != 'MM'
469
459
  return false
470
460
  end
471
461
 
@@ -479,4 +469,8 @@ class File
479
469
 
480
470
  true
481
471
  end
472
+
473
+ def self.ico?(file)
474
+ ["\000\000\001\000", "\000\000\002\000"].include?(IO.read(file, 4, nil, :encoding => 'binary'))
475
+ end
482
476
  end
@@ -1,31 +1,37 @@
1
- require 'rubygems'
2
1
  require 'rbconfig'
3
2
 
4
3
  Gem::Specification.new do |spec|
5
4
  spec.name = 'ptools'
6
- spec.version = '1.3.3'
7
- spec.license = 'Artistic 2.0'
5
+ spec.version = '1.4.1'
6
+ spec.license = 'Artistic-2.0'
8
7
  spec.author = 'Daniel J. Berger'
9
8
  spec.email = 'djberg96@gmail.com'
10
9
  spec.homepage = 'https://github.com/djberg96/ptools'
11
10
  spec.summary = 'Extra methods for the File class'
12
- spec.test_files = Dir['test/test*']
13
- spec.files = Dir['**/*'] << '.gemtest'
11
+ spec.test_files = Dir['spec/_spec*']
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
14
13
  spec.cert_chain = ['certs/djberg96_pub.pem']
15
14
 
16
- spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
17
-
18
15
  spec.description = <<-EOF
19
16
  The ptools (power tools) library provides several handy methods to
20
17
  Ruby's core File class, such as File.which for finding executables,
21
18
  File.null to return the null device on your platform, and so on.
22
19
  EOF
23
20
 
21
+ spec.metadata = {
22
+ 'homepage_uri' => 'https://github.com/djberg96/ptools',
23
+ 'bug_tracker_uri' => 'https://github.com/djberg96/ptools/issues',
24
+ 'changelog_uri' => 'https://github.com/djberg96/ptools/blob/master/CHANGES.md',
25
+ 'documentation_uri' => 'https://github.com/djberg96/ptools/wiki',
26
+ 'source_code_uri' => 'https://github.com/djberg96/ptools',
27
+ 'wiki_uri' => 'https://github.com/djberg96/ptools/wiki'
28
+ }
29
+
24
30
  spec.add_development_dependency('rake')
25
- spec.add_development_dependency('test-unit', '>= 2.5.0')
31
+ spec.add_development_dependency('rspec', '~> 3.9')
26
32
 
27
33
  if File::ALT_SEPARATOR
28
34
  spec.platform = Gem::Platform.new(['universal', 'mingw32'])
29
- spec.add_dependency('win32-file', '>= 0.7.0')
35
+ spec.add_dependency('win32-file')
30
36
  end
31
37
  end
@@ -0,0 +1,59 @@
1
+ #####################################################################
2
+ # test_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
+ require 'rspec'
9
+ require 'ptools'
10
+
11
+ RSpec.describe File, :binary do
12
+ let(:dirname) { File.dirname(__FILE__) }
13
+ let(:bin_file) { File::ALT_SEPARATOR ? File.join(ENV['windir'], 'notepad.exe') : '/bin/ls' }
14
+
15
+ before do
16
+ @txt_file = File.join(dirname, 'txt', 'english.txt')
17
+ @emp_file = File.join(dirname, 'txt', 'empty.txt')
18
+ @uni_file = File.join(dirname, 'txt', 'korean.txt')
19
+ @utf_file = File.join(dirname, 'txt', 'english.utf16')
20
+ @png_file = File.join(dirname, 'img', 'test.png')
21
+ @jpg_file = File.join(dirname, 'img', 'test.jpg')
22
+ @gif_file = File.join(dirname, 'img', 'test.gif')
23
+ end
24
+
25
+ example "File.binary? basic functionality" do
26
+ expect(File).to respond_to(:binary?)
27
+ expect{ File.binary?(@txt_file) }.not_to raise_error
28
+ end
29
+
30
+ example "File.binary? returns true for binary files" do
31
+ expect(File.binary?(bin_file)).to be true
32
+ end
33
+
34
+ example "File.binary? returns false for text files" do
35
+ expect(File.binary?(@emp_file)).to be false
36
+ expect(File.binary?(@txt_file)).to be false
37
+ expect(File.binary?(@uni_file)).to be false
38
+ expect(File.binary?(@utf_file)).to be false
39
+ end
40
+
41
+ example "File.binary? returns false for image files" do
42
+ expect(File.binary?(@png_file)).to be false
43
+ expect(File.binary?(@jpg_file)).to be false
44
+ expect(File.binary?(@gif_file)).to be false
45
+ end
46
+
47
+ example "File.binary? accepts an optional percentage argument" do
48
+ expect(File.binary?(@txt_file, 0.50)).to be false
49
+ expect(File.binary?(@txt_file, 0.05)).to be true
50
+ end
51
+
52
+ example "File.binary? raises an error if the file cannot be found" do
53
+ expect{ File.binary?('bogus') }.to raise_error(SystemCallError)
54
+ end
55
+
56
+ example "File.binary? only accepts one argument" do
57
+ expect{ File.binary?(@txt_file, bin_file) }.to raise_error(ArgumentError)
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ ##############################################################################
2
+ # constants_spec.rb
3
+ #
4
+ # Specs for the constants that have been defined in the ptools library.
5
+ # This test case should be run via the 'rake spec:constants' task.
6
+ ##############################################################################
7
+ require 'rubygems'
8
+ require 'rspec'
9
+ require 'rbconfig'
10
+ require 'ptools'
11
+
12
+ RSpec.describe File, :constants do
13
+ let(:windows) { File::ALT_SEPARATOR }
14
+
15
+ example "PTOOLS_VERSION constant is set to expected value" do
16
+ expect(File::PTOOLS_VERSION).to eq('1.4.1')
17
+ expect(File::PTOOLS_VERSION.frozen?).to be true
18
+ end
19
+
20
+ example "IMAGE_EXT constant is set to array of values" do
21
+ expect(File::IMAGE_EXT.sort).to eq(%w[.bmp .gif .jpeg .jpg .png])
22
+ end
23
+
24
+ example "WINDOWS constant is defined on MS Windows" do
25
+ skip "skipped unless MS Windows" unless windows
26
+ expect(File::MSWINDOWS).not_to be_nil
27
+ end
28
+
29
+ example "WIN32EXTS constant is defined on MS Windows" do
30
+ skip "skipped unless MS Windows" unless windows
31
+ expect(File::WIN32EXTS).not_to be_nil
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ ######################################################################
2
+ # head_spec.rb
3
+ #
4
+ # Specs for the File.head method. These specs should be run via
5
+ # the 'rake spec:head' task.
6
+ ######################################################################
7
+ require 'rspec'
8
+ require 'ptools'
9
+
10
+ RSpec.describe File, :head do
11
+ let(:test_file) { 'test_file_head.txt' }
12
+
13
+ before do
14
+ File.open(test_file, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
15
+ @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
16
+ @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
17
+ @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
18
+ end
19
+
20
+ example "head method basic functionality" do
21
+ expect(File).to respond_to(:head)
22
+ expect{ File.head(test_file) }.not_to raise_error
23
+ expect{ File.head(test_file, 5) }.not_to raise_error
24
+ expect{ File.head(test_file){} }.not_to raise_error
25
+ end
26
+
27
+ example "head method returns the expected results" do
28
+ expect(File.head(test_file)).to be_kind_of(Array)
29
+ expect(File.head(test_file)).to eq(@expected_head1)
30
+ expect(File.head(test_file, 5)).to eq(@expected_head2)
31
+ end
32
+
33
+ example "head method requires two arguments" do
34
+ expect{ File.head(test_file, 5, "foo") }.to raise_error(ArgumentError)
35
+ expect{ File.head("bogus") }.to raise_error(Errno::ENOENT)
36
+ end
37
+
38
+ after do
39
+ File.delete(test_file) if File.exists?(test_file)
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ #####################################################################
2
+ # image_spec.rb
3
+ #
4
+ # Specs for the File.image? method. You should run these specs via
5
+ # the 'rake spec:image' task.
6
+ #####################################################################
7
+ require 'rspec'
8
+ require 'ptools'
9
+
10
+ RSpec.describe File, :image do
11
+ before do
12
+ Dir.chdir('spec') if File.exist?('spec')
13
+ @txt_file = File.join(Dir.pwd, 'txt', 'english.txt')
14
+ @uni_file = File.join(Dir.pwd, 'txt', 'korean.txt')
15
+ @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
16
+ @png_file = File.join(Dir.pwd, 'img', 'test.png')
17
+ @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
18
+ @ico_file = File.join(Dir.pwd, 'img', 'test.ico')
19
+ end
20
+
21
+ example "image? method basic functionality" do
22
+ expect(File).to respond_to(:image?)
23
+ expect{ File.image?(@txt_file) }.not_to raise_error
24
+ expect(File.image?(@txt_file)).to be(true).or be(false)
25
+ end
26
+
27
+ example "image? method returns false for a text file" do
28
+ expect(File.image?(@txt_file)).to be false
29
+ expect(File.image?(@uni_file)).to be false
30
+ end
31
+
32
+ example "image? method returns true for a gif" do
33
+ expect(File.image?(@gif_file)).to be true
34
+ end
35
+
36
+ example "image? method returns true for a jpeg" do
37
+ expect(File.image?(@jpg_file)).to be true
38
+ end
39
+
40
+ example "image? method returns true for a png" do
41
+ expect(File.image?(@png_file)).to be true
42
+ end
43
+
44
+ example "image? method returns true for an ico" do
45
+ expect(File.image?(@ico_file)).to be true
46
+ end
47
+
48
+ example "image? method raises an error if the file does not exist" do
49
+ expect{ File.image?('bogus') }.to raise_error(Exception) # Errno::ENOENT or ArgumentError
50
+ end
51
+ end
File without changes
Binary file
File without changes
File without changes
@@ -0,0 +1,104 @@
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
+ require 'rspec'
9
+ require 'ptools'
10
+
11
+ RSpec.describe File, :nlconvert do
12
+ let(:windows) { File::ALT_SEPARATOR }
13
+ let(:dirname) { File.dirname(__FILE__) }
14
+ let(:test_file1) { File.join(dirname, 'test_nl_convert1.txt') }
15
+ let(:test_file2) { File.join(dirname, 'test_nl_convert2.txt') }
16
+
17
+ before do
18
+ File.open(test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
19
+ File.open(test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
20
+ @test_file1 = File.join(dirname, 'test_nl_convert1.txt')
21
+ @test_file2 = File.join(dirname, 'test_nl_convert2.txt')
22
+ @dos_file = File.join(dirname, 'dos_test_file.txt')
23
+ @mac_file = File.join(dirname, 'mac_test_file.txt')
24
+ @unix_file = 'unix_test_file.txt'
25
+ end
26
+
27
+ example "nl_for_platform basic functionality" do
28
+ expect(File).to respond_to(:nl_for_platform)
29
+ end
30
+
31
+ example "nl_for_platform returns expected results" do
32
+ expect(File.nl_for_platform('dos') ).to eq( "\cM\cJ")
33
+ expect(File.nl_for_platform('unix') ).to eq( "\cJ")
34
+ expect(File.nl_for_platform('mac') ).to eq( "\cM")
35
+
36
+ end
37
+
38
+ example "nl_for_platform with 'local' platform does not raise an error" do
39
+ expect{ File.nl_for_platform('local') }.not_to raise_error
40
+ end
41
+
42
+ example "nl_for_platform with unsupported platform raises an error" do
43
+ expect{ File.nl_for_platform('bogus') }.to raise_error(ArgumentError)
44
+ end
45
+
46
+ example "nl_convert basic functionality" do
47
+ expect(File).to respond_to(:nl_convert)
48
+ end
49
+
50
+ example "nl_convert accepts one, two or three arguments" do
51
+ expect{ File.nl_convert(@test_file2) }.not_to raise_error
52
+ expect{ File.nl_convert(@test_file2, @test_file2) }.not_to raise_error
53
+ expect{ File.nl_convert(@test_file2, @test_file2, "unix") }.not_to raise_error
54
+ end
55
+
56
+ example "nl_convert with dos platform argument works as expected" do
57
+ expect{ File.nl_convert(@test_file1, @dos_file, "dos") }.not_to raise_error
58
+ expect{ File.nl_convert(@test_file1, @dos_file, "dos") }.not_to raise_error
59
+ expect(File.size(@dos_file)).to be > File.size(@test_file1)
60
+ expect(IO.readlines(@dos_file).first.split("")[-2..-1]).to eq(["\cM","\cJ"])
61
+ end
62
+
63
+ example "nl_convert with mac platform argument works as expected" do
64
+ expect{ File.nl_convert(@test_file1, @mac_file, 'mac') }.not_to raise_error
65
+ expect(IO.readlines(@mac_file).first.split("").last).to eq("\cM")
66
+
67
+ skip if windows
68
+ expect(File.size(@mac_file)).to eq(File.size(@test_file1))
69
+ end
70
+
71
+ example "nl_convert with unix platform argument works as expected" do
72
+ expect{ File.nl_convert(@test_file1, @unix_file, "unix") }.not_to raise_error
73
+ expect(IO.readlines(@unix_file).first.split("").last).to eq("\n")
74
+
75
+ if windows
76
+ expect(File.size(@unix_file) >= File.size(@test_file1)).to be true
77
+ else
78
+ expect(File.size(@unix_file) <= File.size(@test_file1)).to be true
79
+ end
80
+ end
81
+
82
+ example "nl_convert requires at least one argument" do
83
+ expect{ File.nl_convert }.to raise_error(ArgumentError)
84
+ end
85
+
86
+ example "nl_convert requires a valid platform string" do
87
+ expect{ File.nl_convert(@test_file1, "bogus.txt", "blah") }.to raise_error(ArgumentError)
88
+ end
89
+
90
+ example "nl_convert accepts a maximum of three arguments" do
91
+ expect{ File.nl_convert(@example_file1, @test_file2, 'dos', 1) }.to raise_error(ArgumentError)
92
+ expect{ File.nl_convert(@test_file1, @test_file2, 'dos', 1) }.to raise_error(ArgumentError)
93
+ end
94
+
95
+ example "nl_convert will fail on anything but plain files" do
96
+ expect{ File.nl_convert(IO::NULL, @test_file1) }.to raise_error(ArgumentError)
97
+ end
98
+
99
+ after do
100
+ [@dos_file, @mac_file, @unix_file].each{ |file| File.delete(file) if File.exist?(file) }
101
+ File.delete(test_file1) if File.exist?(test_file1)
102
+ File.delete(test_file2) if File.exist?(test_file2)
103
+ end
104
+ end