ptools 1.3.0-universal-mingw32 → 1.3.6-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODRjNGZmYTAzYTU4ZjE4NDA0OWVlZWZiZDlmMDNlNjExZWM4YWY3ZQ==
5
- data.tar.gz: !binary |-
6
- ZjVkYjQwMTQ0YWViOTJlMDI4NTFmYTYyYTc3MGJhNTQyNGM3NTU5Ng==
2
+ SHA256:
3
+ metadata.gz: 7137b9d1e8f2be72fc7c5fecaad1101105dfcdec8b20ce4a14613290eb654d7f
4
+ data.tar.gz: f6277cd2a7c718b3fba6e219fcb67a550b97ce05986770b1badc760c9be527ba
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YjcxOWU1MmNkZTBlZjg5YTIzMTU0NWZmNjM5ZjBlMmU4NGUyZTM0MTdjYzNk
10
- NWFmNmRmZTYzZTUzYmE3N2U4NjMwZmM0MWEzZjc3M2EwNjUzMmY1NWM4NDc2
11
- NjUxODhkZDczNWVhZjIzZTRjNWRmMDNiMzc0Zjc4YTUzZWJkMjY=
12
- data.tar.gz: !binary |-
13
- YTUyMzY2MGRjNzM4YzE5ZDhkMWQ3MWYyNjgwNDBkYjFmMzA4NjQyYmJmYjg5
14
- ODdhMzFlNTZmZmQ4MzE0YzRiNGIwNGE5MjI2Y2MzZjdjNGYwYjkzNWI1NjMy
15
- OTJiMmNjMjE2ZTY3M2M4MDhhMzQ5ZjhmMGUwM2M3ZmJjMDIxOGY=
6
+ metadata.gz: 35a63af1addb2fb3e5bce61393941586a2f5bdd137408afeb437207502e61bc21ed92f72ff392ffc8adf7b67a4353604f713ce5cbcbd64245d4e4860efdf46ba
7
+ data.tar.gz: 408a73f0219d50632a63265b3a72f13f120962f5bee89a3a36ece8f8671a896015b1f2442c129558b4b079b5723efee37beaac3d56893f8246d3cb298c648885
Binary file
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,35 @@
1
+ == 1.3.6 - 7-Jun-2020
2
+ * Updated gemspec, added more versions to .travis.yml file, fixed typo.
3
+ Thanks go to Al Snow for the updates.
4
+ * Fixed a bug where the File.binary? method would return true for utf16
5
+ or utf32 encoded files. Thanks go to Andrew McAndre for the spot.
6
+ * Updated cert.
7
+
8
+ == 1.3.5 - 3-Sep-2017
9
+ * The File.image? method now checks against .ico files.
10
+ * Eliminated Fixnum warning that showed up in Ruby 2.4.x.
11
+ * Updated cert.
12
+
13
+ == 1.3.4 - 4-Jul-2017
14
+ * The File.binary? method now lets you set your own percentage for the
15
+ internal heuristic as an optional second argument.
16
+ * The VERSION constant is now frozen.
17
+ * Minor updates to the Rakefile and gemspec.
18
+ * Updated cert file.
19
+
20
+ == 1.3.3 - 25-Sep-2015
21
+ * This gem is now signed.
22
+ * The Rakefile tasks now assume Rubygems 2.x.
23
+
24
+ == 1.3.2 - 11-Dec-2014
25
+ * Update to the File.tail method that deals prevents potential line ending
26
+ issues in JRuby.
27
+ * Added known issues with JRuby to the README.
28
+
29
+ == 1.3.1 - 9-Dec-2014
30
+ * Fixed some potential issues with File.tail. Thanks go to Matt Hoyle for
31
+ the patch.
32
+
1
33
  == 1.3.0 - 8-Dec-2014
2
34
  * Made the File.tail method efficient. It's no longer slurpy, and it also no
3
35
  longer includes line endings in the result.
@@ -0,0 +1,19 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ power_assert (1.1.5)
5
+ rake (13.0.1)
6
+ structured_warnings (0.4.0)
7
+ test-unit (3.3.5)
8
+ power_assert
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ rake
15
+ structured_warnings
16
+ test-unit
17
+
18
+ BUNDLED WITH
19
+ 2.1.2
data/MANIFEST CHANGED
@@ -3,6 +3,7 @@
3
3
  * MANIFEST
4
4
  * Rakefile
5
5
  * ptools.gemspec
6
+ * certs/djberg96_pub.pem
6
7
  * lib/ptools.rb
7
8
  * test/test_constants.rb
8
9
  * test/test_head.rb
@@ -17,3 +18,4 @@
17
18
  * test/img/test.gif
18
19
  * test/img/test.jpg
19
20
  * test/img/test.png
21
+ * test/img/test.ico
data/README CHANGED
@@ -3,7 +3,7 @@
3
3
  File class based on Unix command line tools.
4
4
 
5
5
  == Prerequisites
6
- On MS Windows you will need win32-file 0.5.4 or later.
6
+ On MS Windows you will need the win32-file gem.
7
7
 
8
8
  == Installation
9
9
  gem install ptools
@@ -27,7 +27,10 @@
27
27
  File.nl_convert("myfile", "newfile", "dos")
28
28
 
29
29
  == Known Bugs
30
- None known. Please report any bugs on the github project page.
30
+ The File.which and File.whereis methods may fail when using JRuby on Windows.
31
+ See https://github.com/jruby/jruby/issues/2291 for details.
32
+
33
+ Please report any other issues on the github project page.
31
34
 
32
35
  http://www.github.com/djberg96/ptools
33
36
 
@@ -42,6 +45,10 @@
42
45
  The binary?() method was based almost entirely on a blog post by Ryan
43
46
  Davis (who, in turn, based his code on Perl's -B switch).
44
47
 
48
+ Thanks go to Matt Hoyle for help with the File.tail method.
49
+
50
+ And thanks to any and all contributors!
51
+
45
52
  == Future Plans
46
53
  Add whatever other tools people think might be useful.
47
54
 
@@ -49,7 +56,7 @@
49
56
  Artistic 2.0
50
57
 
51
58
  == Copyright
52
- (C) 2003-2014 Daniel J. Berger
59
+ (C) 2003-2020 Daniel J. Berger
53
60
  All Rights Reserved.
54
61
 
55
62
  == Warranty
data/Rakefile CHANGED
@@ -8,28 +8,28 @@ CLEAN.include("**/*.gem", "**/*.rbc", "**/*coverage*")
8
8
 
9
9
  desc 'Install the ptools package (non-gem)'
10
10
  task :install do
11
- sitelibdir = CONFIG["sitelibdir"]
12
- file = "lib/ptools.rb"
13
- FileUtils.cp(file, sitelibdir, :verbose => true)
11
+ sitelibdir = CONFIG["sitelibdir"]
12
+ file = "lib/ptools.rb"
13
+ FileUtils.cp(file, sitelibdir, :verbose => true)
14
14
  end
15
15
 
16
16
  namespace 'gem' do
17
17
  desc 'Create the ptools gem'
18
18
  task :create => [:clean] do
19
- Dir["*.gem"].each{ |f| File.delete(f) } # Clean first
19
+ require 'rubygems/package'
20
20
  spec = eval(IO.read('ptools.gemspec'))
21
- if Gem::VERSION < "2.0.0"
22
- Gem::Builder.new(spec).build
23
- else
24
- require 'rubygems/package'
25
- Gem::Package.build(spec)
26
- end
21
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
22
+ Gem::Package.build(spec, true)
27
23
  end
28
24
 
29
25
  desc 'Install the ptools gem'
30
26
  task :install => [:create] do
31
27
  file = Dir["*.gem"].first
32
- sh "gem install -l #{file}"
28
+ if RUBY_PLATFORM == 'java'
29
+ sh "jruby -S gem install -l #{file}"
30
+ else
31
+ sh "gem install -l #{file}"
32
+ end
33
33
  end
34
34
  end
35
35
 
@@ -75,13 +75,6 @@ namespace 'test' do
75
75
  t.test_files = FileList['test/test_image.rb']
76
76
  end
77
77
 
78
- Rake::TestTask.new('middle') do |t|
79
- t.libs << 'test'
80
- t.verbose = true
81
- t.warning = true
82
- t.test_files = FileList['test/test_middle.rb']
83
- end
84
-
85
78
  Rake::TestTask.new('nlconvert') do |t|
86
79
  t.libs << 'test'
87
80
  t.verbose = true
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP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bj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
24
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
25
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
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.0'
6
+ PTOOLS_VERSION = '1.3.6'.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,8 +39,8 @@ 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
 
@@ -79,6 +79,10 @@ class File
79
79
  # It performs a "best guess" based on a simple test of the first
80
80
  # +File.blksize+ characters, or 4096, whichever is smaller.
81
81
  #
82
+ # By default it will check to see if more than 30 percent of the characters
83
+ # are non-text characters. If so, the method returns true. You can configure
84
+ # this percentage by passing your own as a second argument.
85
+ #
82
86
  # Example:
83
87
  #
84
88
  # File.binary?('somefile.exe') # => true
@@ -87,13 +91,14 @@ class File
87
91
  # Based on code originally provided by Ryan Davis (which, in turn, is
88
92
  # based on Perl's -B switch).
89
93
  #
90
- def self.binary?(file)
94
+ def self.binary?(file, percentage = 0.30)
91
95
  return false if image?(file)
96
+ return false if check_bom?(file)
92
97
  bytes = File.stat(file).blksize
93
98
  bytes = 4096 if bytes > 4096
94
99
  s = (File.read(file, bytes) || "")
95
100
  s = s.encode('US-ASCII', :undef => :replace).split(//)
96
- ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
101
+ ((s.size - s.grep(" ".."~").size) / s.size.to_f) > percentage
97
102
  end
98
103
 
99
104
  # Looks for the first occurrence of +program+ within +path+.
@@ -247,35 +252,42 @@ class File
247
252
  # If you're looking for tail -f functionality, please use the file-tail
248
253
  # gem instead.
249
254
  #
255
+ #--
256
+ # Internally I'm using a 64 chunk of memory at a time. I may allow the size
257
+ # to be configured in the future as an optional 3rd argument.
258
+ #
250
259
  def self.tail(filename, num_lines=10)
251
260
  tail_size = 2**16 # 64k chunks
252
261
 
253
262
  # MS Windows gets unhappy if you try to seek backwards past the
254
263
  # end of the file, so we have some extra checks here and later.
255
- file_size = File.size(filename)
256
- tail_size = file_size if file_size <= tail_size
257
- line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
264
+ file_size = File.size(filename)
265
+ read_bytes = file_size % tail_size
266
+ read_bytes = tail_size if read_bytes == 0
267
+
268
+ line_sep = File::ALT_SEPARATOR ? "\r\n" : "\n"
258
269
 
259
270
  buf = ''
260
271
 
261
- File.open(filename){ |fh|
262
- fh.seek(-tail_size, File::SEEK_END)
272
+ # Open in binary mode to ensure line endings aren't converted.
273
+ File.open(filename, 'rb'){ |fh|
274
+ position = file_size - read_bytes # Set the starting read position
263
275
 
264
- while buf.count(line_sep) <= num_lines
265
- buf = fh.read(tail_size) + buf
266
- break if buf.count(line_sep) >= num_lines
267
- if tail_size * 2 < file_size
268
- fh.seek(-tail_size * 2, File::SEEK_CUR)
269
- else
270
- fh.seek(-file_size, File::SEEK_CUR)
271
- end
276
+ # Loop until we have the lines or run out of file
277
+ while buf.scan(line_sep).size <= num_lines and position >= 0
278
+ fh.seek(position, IO::SEEK_SET)
279
+ buf = fh.read(read_bytes) + buf
280
+ read_bytes = tail_size
281
+ position -= read_bytes
272
282
  end
273
283
  }
274
284
 
285
+ lines = buf.split(line_sep).pop(num_lines)
286
+
275
287
  if block_given?
276
- buf.split(line_sep)[-num_lines..-1].each{ |line| yield line }
288
+ lines.each{ |line| yield line }
277
289
  else
278
- buf.split(line_sep)[-num_lines..-1]
290
+ lines
279
291
  end
280
292
  end
281
293
 
@@ -421,6 +433,20 @@ class File
421
433
 
422
434
  private
423
435
 
436
+ # Returns whether or not the given +text+ contains a BOM marker.
437
+ # If present, we can generally assume it's a text file.
438
+ #
439
+ def self.check_bom?(file)
440
+ text = File.read(file, 4).force_encoding('utf-8')
441
+
442
+ bool = false
443
+ bool = true if text[0,3] == "\xEF\xBB\xBF"
444
+ bool = true if text[0,4] == "\x00\x00\xFE\xFF" || text[0,4] == "\xFF\xFE\x00\x00"
445
+ bool = true if text[0,2] == "\xFF\xFE" || text[0,2] == "\xFE\xFF"
446
+
447
+ bool
448
+ end
449
+
424
450
  def self.nl_for_platform(platform)
425
451
  platform = RbConfig::CONFIG["host_os"] if platform == 'local'
426
452
 
@@ -472,4 +498,8 @@ class File
472
498
 
473
499
  true
474
500
  end
501
+
502
+ def self.ico?(file)
503
+ ["\000\000\001\000", "\000\000\002\000"].include?(IO.read(file, 4, nil, :encoding => 'binary'))
504
+ end
475
505
  end
@@ -1,30 +1,30 @@
1
- require 'rubygems'
2
1
  require 'rbconfig'
3
2
 
4
- Gem::Specification.new do |gem|
5
- gem.name = 'ptools'
6
- gem.version = '1.3.0'
7
- gem.license = 'Artistic 2.0'
8
- gem.author = 'Daniel J. Berger'
9
- gem.email = 'djberg96@gmail.com'
10
- gem.homepage = 'https://github.com/djberg96/ptools'
11
- gem.summary = 'Extra methods for the File class'
12
- gem.test_files = Dir['test/test*']
13
- gem.files = Dir['**/*'] << '.gemtest'
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'ptools'
5
+ spec.version = '1.3.6'
6
+ spec.license = 'Artistic-2.0'
7
+ spec.author = 'Daniel J. Berger'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'https://github.com/djberg96/ptools'
10
+ spec.summary = 'Extra methods for the File class'
11
+ spec.test_files = Dir['test/test*']
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.cert_chain = ['certs/djberg96_pub.pem']
14
14
 
15
- gem.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
15
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
16
 
17
- gem.description = <<-EOF
17
+ spec.description = <<-EOF
18
18
  The ptools (power tools) library provides several handy methods to
19
19
  Ruby's core File class, such as File.which for finding executables,
20
20
  File.null to return the null device on your platform, and so on.
21
21
  EOF
22
22
 
23
- gem.add_development_dependency('rake')
24
- gem.add_development_dependency('test-unit', '>= 2.5.0')
23
+ spec.add_development_dependency('rake')
24
+ spec.add_development_dependency('test-unit')
25
25
 
26
26
  if File::ALT_SEPARATOR
27
- gem.platform = Gem::Platform.new(['universal', 'mingw32'])
28
- gem.add_dependency('win32-file', '>= 0.7.0')
27
+ spec.platform = Gem::Platform.new(['universal', 'mingw32'])
28
+ spec.add_dependency('win32-file')
29
29
  end
30
30
  end
Binary file
@@ -16,15 +16,16 @@ class TC_Ptools_Binary < Test::Unit::TestCase
16
16
  @@bin_file = '/bin/ls'
17
17
  end
18
18
 
19
- Dir.chdir('test') if File.exist?('test')
19
+ @@dirname = File.dirname(__FILE__)
20
20
  end
21
21
 
22
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')
23
+ @txt_file = File.join(@@dirname, 'txt', 'english.txt')
24
+ @uni_file = File.join(@@dirname, 'txt', 'korean.txt')
25
+ @utf_file = File.join(@@dirname, 'txt', 'english.utf16')
26
+ @png_file = File.join(@@dirname, 'img', 'test.png')
27
+ @jpg_file = File.join(@@dirname, 'img', 'test.jpg')
28
+ @gif_file = File.join(@@dirname, 'img', 'test.gif')
28
29
  end
29
30
 
30
31
  test "File.binary? basic functionality" do
@@ -39,6 +40,7 @@ class TC_Ptools_Binary < Test::Unit::TestCase
39
40
  test "File.binary? returns false for text files" do
40
41
  assert_false(File.binary?(@txt_file))
41
42
  assert_false(File.binary?(@uni_file))
43
+ assert_false(File.binary?(@utf_file))
42
44
  end
43
45
 
44
46
  test "File.binary? returns false for image files" do
@@ -47,6 +49,11 @@ class TC_Ptools_Binary < Test::Unit::TestCase
47
49
  assert_false(File.binary?(@gif_file))
48
50
  end
49
51
 
52
+ test "File.binary? accepts an optional percentage argument" do
53
+ assert_false(File.binary?(@txt_file, 0.50))
54
+ assert_true(File.binary?(@txt_file, 0.05))
55
+ end
56
+
50
57
  test "File.binary? raises an error if the file cannot be found" do
51
58
  assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
52
59
  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.3.0', File::PTOOLS_VERSION)
18
+ assert_equal('1.3.6', File::PTOOLS_VERSION)
19
19
  end
20
20
 
21
21
  test "IMAGE_EXT constant is set to array of values" do
@@ -27,7 +27,7 @@ class TC_Ptools_Constants < Test::Unit::TestCase
27
27
  assert_not_nil(File::MSWINDOWS)
28
28
  end
29
29
 
30
- test "WIN32EXTS constant is defiend on MS Windows" do
30
+ test "WIN32EXTS constant is defined on MS Windows" do
31
31
  omit_unless(@@windows, "Skipping on Unix systems")
32
32
  assert_not_nil(File::WIN32EXTS)
33
33
  end
@@ -18,6 +18,7 @@ class TC_Ptools_Image < Test::Unit::TestCase
18
18
  @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
19
19
  @png_file = File.join(Dir.pwd, 'img', 'test.png')
20
20
  @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
21
+ @ico_file = File.join(Dir.pwd, 'img', 'test.ico')
21
22
  end
22
23
 
23
24
  test "image? method basic functionality" do
@@ -43,6 +44,10 @@ class TC_Ptools_Image < Test::Unit::TestCase
43
44
  assert_true(File.image?(@png_file))
44
45
  end
45
46
 
47
+ test "image? method returns true for an ico" do
48
+ assert_true(File.image?(@ico_file))
49
+ end
50
+
46
51
  test "image? method raises an error if the file does not exist" do
47
52
  assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
48
53
  end
@@ -10,18 +10,18 @@ require 'ptools'
10
10
 
11
11
  class TC_Ptools_NLConvert < Test::Unit::TestCase
12
12
  def self.startup
13
- Dir.chdir('test') if File.exist?('test')
14
- @@test_file1 = 'test_nl_convert1.txt'
15
- @@test_file2 = 'test_nl_convert2.txt'
13
+ @@dirname = File.dirname(__FILE__)
14
+ @@test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
15
+ @@test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
16
16
  File.open(@@test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
17
17
  File.open(@@test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
18
18
  end
19
19
 
20
20
  def setup
21
- @test_file1 = 'test_nl_convert1.txt'
22
- @test_file2 = 'test_nl_convert2.txt'
23
- @dos_file = 'dos_test_file.txt'
24
- @mac_file = 'mac_test_file.txt'
21
+ @test_file1 = File.join(@@dirname, 'test_nl_convert1.txt')
22
+ @test_file2 = File.join(@@dirname, 'test_nl_convert2.txt')
23
+ @dos_file = File.join(@@dirname, 'dos_test_file.txt')
24
+ @mac_file = File.join(@@dirname, 'mac_test_file.txt')
25
25
  @unix_file = 'nix_test_file.txt'
26
26
  end
27
27
 
@@ -35,7 +35,7 @@ class TC_Ptools_NLConvert < Test::Unit::TestCase
35
35
  assert_equal( "\cM", File.nl_for_platform('mac') )
36
36
  assert_nothing_raised{ File.nl_for_platform('local') }
37
37
  end
38
-
38
+
39
39
  test "nl_convert basic functionality" do
40
40
  assert_respond_to(File, :nl_convert)
41
41
  end
@@ -9,18 +9,64 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTail < Test::Unit::TestCase
11
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}" } }
12
+ @@dirname = File.dirname(__FILE__)
13
+
14
+ @@test_file1 = File.join(@@dirname, 'test_file1.txt')
15
+ @@test_file64 = File.join(@@dirname, 'test_file64.txt')
16
+ @@test_file128 = File.join(@@dirname, 'test_file128.txt')
17
+
18
+ @@test_file_trail = File.join(@@dirname, 'test_file_trail.txt')
19
+ @@test_file_trail_nl = File.join(@@dirname, 'test_file_trail_nl.txt')
20
+
21
+ File.open(@@test_file1, 'w'){ |fh|
22
+ 25.times{ |n| fh.puts "line#{n+1}" }
23
+ }
24
+
25
+ # Trailing newline test
26
+ File.open(@@test_file_trail, 'w'){ |fh|
27
+ 2.times{ |n| fh.puts "trail#{n+1}" }
28
+ fh.write "trail3"
29
+ }
30
+ File.open(@@test_file_trail_nl, 'w'){ |fh|
31
+ 3.times{ |n| fh.puts "trail#{n+1}" }
32
+ }
33
+
34
+ # Larger files
35
+ test_tail_fmt_str = "line data data data data data data data %5s"
36
+
37
+ File.open(@@test_file64, 'w'){ |fh|
38
+ 2000.times{ |n|
39
+ fh.puts test_tail_fmt_str % (n+1).to_s
40
+ }
41
+ }
42
+
43
+ File.open(@@test_file128, 'w'){ |fh|
44
+ 4500.times{ |n|
45
+ fh.puts test_tail_fmt_str % (n+1).to_s
46
+ }
47
+ }
14
48
  end
15
49
 
16
50
  def setup
17
- @test_file = 'test_file1.txt'
51
+ @test_file = @@test_file1
52
+ @test_trail = @@test_file_trail
53
+ @test_trail_nl = @@test_file_trail_nl
54
+ @test_file_64 = @@test_file64
55
+ @test_file_128 = @@test_file128
18
56
 
19
- @expected_tail1 = ["line16","line17","line18","line19"]
20
- @expected_tail1.push("line20","line21","line22", "line23")
21
- @expected_tail1.push("line24","line25")
57
+ @expected_tail1 = %w{
58
+ line16 line17 line18 line19 line20
59
+ line21 line22 line23 line24 line25
60
+ }
22
61
 
23
62
  @expected_tail2 = ["line21","line22","line23","line24","line25"]
63
+
64
+ @expected_tail_more = []
65
+ 25.times{ |n| @expected_tail_more.push "line#{n+1}" }
66
+
67
+ @expected_tail_trail = %w{ trail2 trail3 }
68
+
69
+ @test_tail_fmt_str = "line data data data data data data data %5s"
24
70
  end
25
71
 
26
72
  def test_tail_basic
@@ -36,11 +82,32 @@ class TC_FileTail < Test::Unit::TestCase
36
82
  assert_equal(@expected_tail2, File.tail(@test_file, 5))
37
83
  end
38
84
 
85
+ def test_more_lines_than_file
86
+ assert_equal( @expected_tail_more, File.tail(@test_file, 30) )
87
+ end
88
+
39
89
  def test_tail_expected_errors
40
90
  assert_raises(ArgumentError){ File.tail }
41
91
  assert_raises(ArgumentError){ File.tail(@test_file, 5, 5) }
42
92
  end
43
93
 
94
+ def test_no_trailing_newline
95
+ assert_equal( @expected_tail_trail, File.tail(@test_trail, 2) )
96
+ assert_equal( @expected_tail_trail, File.tail(@test_trail_nl, 2) )
97
+ end
98
+
99
+ def test_tail_larger_than_64k
100
+ expected_tail_64k=[]
101
+ 2000.times{ |n| expected_tail_64k.push( @test_tail_fmt_str % (n+1).to_s ) }
102
+ assert_equal( expected_tail_64k, File.tail(@test_file_64, 2000) )
103
+ end
104
+
105
+ def test_tail_larger_than_128k
106
+ expected_tail_128k = []
107
+ 4500.times{ |n| expected_tail_128k.push( @test_tail_fmt_str % (n+1).to_s ) }
108
+ assert_equal( expected_tail_128k, File.tail(@test_file_128, 4500) )
109
+ end
110
+
44
111
  def teardown
45
112
  @test_file = nil
46
113
  @expected_tail1 = nil
@@ -48,6 +115,10 @@ class TC_FileTail < Test::Unit::TestCase
48
115
  end
49
116
 
50
117
  def self.shutdown
51
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
118
+ File.delete(@@test_file1) if File.exist?(@@test_file1)
119
+ File.delete(@@test_file64) if File.exist?(@@test_file64)
120
+ File.delete(@@test_file128) if File.exist?(@@test_file128)
121
+ File.delete(@@test_file_trail_nl) if File.exist?(@@test_file_trail_nl)
122
+ File.delete(@@test_file_trail) if File.exist?(@@test_file_trail)
52
123
  end
53
124
  end
@@ -9,13 +9,14 @@ require 'ptools'
9
9
 
10
10
  class TC_FileTouch < Test::Unit::TestCase
11
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}" } }
12
+ @@dirname = File.dirname(__FILE__)
13
+ @@xfile = File.join(@@dirname, 'test_file1.txt')
14
+ File.open(@@xfile, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
14
15
  end
15
16
 
16
17
  def setup
17
- @test_file = 'delete.this'
18
- @xfile = 'test_file1.txt'
18
+ @test_file = File.join(@@dirname, 'delete.this')
19
+ @xfile = File.join(@@dirname, 'test_file1.txt')
19
20
  end
20
21
 
21
22
  def test_touch_basic
@@ -47,6 +48,6 @@ class TC_FileTouch < Test::Unit::TestCase
47
48
  end
48
49
 
49
50
  def self.shutdown
50
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
51
+ File.delete(@@xfile) if File.exist?(@@xfile)
51
52
  end
52
53
  end
Binary file
metadata CHANGED
@@ -1,60 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.6
5
5
  platform: universal-mingw32
6
6
  authors:
7
7
  - Daniel J. Berger
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
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YEAW2tnYixXQtKxgGXq
29
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
30
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
31
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
32
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
33
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
34
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
35
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
+ -----END CERTIFICATE-----
38
+ date:
12
39
  dependencies:
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: rake
15
42
  requirement: !ruby/object:Gem::Requirement
16
43
  requirements:
17
- - - ! '>='
44
+ - - ">="
18
45
  - !ruby/object:Gem::Version
19
46
  version: '0'
20
47
  type: :development
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
- - - ! '>='
51
+ - - ">="
25
52
  - !ruby/object:Gem::Version
26
53
  version: '0'
27
54
  - !ruby/object:Gem::Dependency
28
55
  name: test-unit
29
56
  requirement: !ruby/object:Gem::Requirement
30
57
  requirements:
31
- - - ! '>='
58
+ - - ">="
32
59
  - !ruby/object:Gem::Version
33
- version: 2.5.0
60
+ version: '0'
34
61
  type: :development
35
62
  prerelease: false
36
63
  version_requirements: !ruby/object:Gem::Requirement
37
64
  requirements:
38
- - - ! '>='
65
+ - - ">="
39
66
  - !ruby/object:Gem::Version
40
- version: 2.5.0
67
+ version: '0'
41
68
  - !ruby/object:Gem::Dependency
42
69
  name: win32-file
43
70
  requirement: !ruby/object:Gem::Requirement
44
71
  requirements:
45
- - - ! '>='
72
+ - - ">="
46
73
  - !ruby/object:Gem::Version
47
- version: 0.7.0
74
+ version: '0'
48
75
  type: :runtime
49
76
  prerelease: false
50
77
  version_requirements: !ruby/object:Gem::Requirement
51
78
  requirements:
52
- - - ! '>='
79
+ - - ">="
53
80
  - !ruby/object:Gem::Version
54
- version: 0.7.0
55
- description: ! " The ptools (power tools) library provides several handy methods
56
- to\n Ruby's core File class, such as File.which for finding executables,\n File.null
57
- to return the null device on your platform, and so on.\n"
81
+ version: '0'
82
+ description: |2
83
+ The ptools (power tools) library provides several handy methods to
84
+ Ruby's core File class, such as File.which for finding executables,
85
+ File.null to return the null device on your platform, and so on.
58
86
  email: djberg96@gmail.com
59
87
  executables: []
60
88
  extensions: []
@@ -63,15 +91,21 @@ extra_rdoc_files:
63
91
  - CHANGES
64
92
  - MANIFEST
65
93
  files:
66
- - .gemtest
94
+ - certs
95
+ - certs/djberg96_pub.pem
67
96
  - CHANGES
68
97
  - Gemfile
69
- - MANIFEST
70
- - README
71
- - Rakefile
98
+ - Gemfile.lock
99
+ - lib
72
100
  - lib/ptools.rb
101
+ - MANIFEST
73
102
  - ptools.gemspec
103
+ - Rakefile
104
+ - README
105
+ - test
106
+ - test/img
74
107
  - test/img/test.gif
108
+ - test/img/test.ico
75
109
  - test/img/test.jpg
76
110
  - test/img/test.png
77
111
  - test/test_binary.rb
@@ -86,11 +120,13 @@ files:
86
120
  - test/test_wc.rb
87
121
  - test/test_whereis.rb
88
122
  - test/test_which.rb
123
+ - test/txt
89
124
  - test/txt/english.txt
125
+ - test/txt/english.utf16
90
126
  - test/txt/korean.txt
91
127
  homepage: https://github.com/djberg96/ptools
92
128
  licenses:
93
- - Artistic 2.0
129
+ - Artistic-2.0
94
130
  metadata: {}
95
131
  post_install_message:
96
132
  rdoc_options: []
@@ -98,17 +134,16 @@ require_paths:
98
134
  - lib
99
135
  required_ruby_version: !ruby/object:Gem::Requirement
100
136
  requirements:
101
- - - ! '>='
137
+ - - ">="
102
138
  - !ruby/object:Gem::Version
103
139
  version: '0'
104
140
  required_rubygems_version: !ruby/object:Gem::Requirement
105
141
  requirements:
106
- - - ! '>='
142
+ - - ">="
107
143
  - !ruby/object:Gem::Version
108
144
  version: '0'
109
145
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.4.2
146
+ rubygems_version: 3.0.3
112
147
  signing_key:
113
148
  specification_version: 4
114
149
  summary: Extra methods for the File class
Binary file
data/.gemtest DELETED
File without changes