win32-file 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.6.6 - 3-Sep-2010
2
+ * Fixed a bug in the custom File.dirname where trailing slashes were
3
+ affecting the result. Trailing slashes are now ignored.
4
+ * Added a global test task and a default rake task. Both run all tests.
5
+
1
6
  == 0.6.5 - 19-Jul-2010
2
7
  * Removed debug print statement (oops!).
3
8
 
data/Rakefile CHANGED
@@ -66,3 +66,6 @@ namespace 'test' do
66
66
  t.test_files = FileList['test/test_win32_file_stat.rb']
67
67
  end
68
68
  end
69
+
70
+ task :test => ['test:all']
71
+ task :default => ['test:all']
data/lib/win32/file.rb CHANGED
@@ -19,7 +19,7 @@ class File
19
19
  extend Windows::Handle
20
20
 
21
21
  # The version of the win32-file library
22
- WIN32_FILE_VERSION = '0.6.5'
22
+ WIN32_FILE_VERSION = '0.6.6'
23
23
 
24
24
  # Abbreviated attribute constants for convenience
25
25
 
@@ -514,6 +514,11 @@ class File
514
514
  #
515
515
  def dirname(file)
516
516
  raise TypeError unless file.is_a?(String)
517
+
518
+ # Short circuit for empty paths
519
+ return '.' if file.empty?
520
+
521
+ # Temporarily convert to wide-byte
517
522
  file = multi_to_wide(file)
518
523
 
519
524
  # Convert slashes to backslashes for the Windows API functions
@@ -521,10 +526,16 @@ class File
521
526
 
522
527
  # Return a root path as-is.
523
528
  return wide_to_multi(file) if PathIsRootW(file)
524
-
525
- # Remove trailing file name and backslash, if present
529
+
530
+ # Remove trailing slashes if present
531
+ while result = PathRemoveBackslashW(file)
532
+ break unless result.empty?
533
+ end
534
+
535
+ # Remove trailing file name if present
526
536
  PathRemoveFileSpecW(file)
527
537
 
538
+ # Return to multi-byte
528
539
  file = wide_to_multi(file)
529
540
 
530
541
  # Empty paths, short relative paths
@@ -26,7 +26,7 @@ class TC_Win32_File_Attributes < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  def test_version
29
- assert_equal('0.6.5', File::WIN32_FILE_VERSION)
29
+ assert_equal('0.6.6', File::WIN32_FILE_VERSION)
30
30
  end
31
31
 
32
32
  def test_is_directory
@@ -133,9 +133,8 @@ class TC_Win32_File_Path < Test::Unit::TestCase
133
133
  test "dirname handles various edge cases as expected" do
134
134
  assert_equal(".", File.dirname(""))
135
135
  assert_equal(".", File.dirname("."))
136
- assert_equal(".", File.dirname("."))
136
+ assert_equal(".", File.dirname(".."))
137
137
  assert_equal(".", File.dirname("./"))
138
- assert_raises(TypeError){ File.dirname(nil) }
139
138
  end
140
139
 
141
140
  test "dirname method does not modify its argument" do
@@ -143,7 +142,20 @@ class TC_Win32_File_Path < Test::Unit::TestCase
143
142
  assert_nothing_raised{ File.dirname(path) }
144
143
  assert_equal("C:\\foo\\bar", path)
145
144
  end
146
-
145
+
146
+ test "dirname method ignores trailing slashes" do
147
+ assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz/"))
148
+ assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz//"))
149
+ assert_equal("C:\\foo\\bar", File.dirname("C:/foo/bar/baz///"))
150
+ assert_equal("C:\\foo\\bar", File.dirname("C:\\foo\\bar\\baz\\"))
151
+ assert_equal("\\\\foo\\bar", File.dirname("\\\\foo\\bar\\baz\\"))
152
+ end
153
+
154
+ test "argument to dirname must be a string" do
155
+ assert_raises(TypeError){ File.dirname(nil) }
156
+ assert_raises(TypeError){ File.dirname(['foo', 'bar']) }
157
+ end
158
+
147
159
  test "split method basic functionality" do
148
160
  assert_respond_to(File, :split)
149
161
  assert_nothing_raised{ File.split("C:\\foo\\bar") }
data/win32-file.gemspec CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-file'
5
- spec.version = '0.6.5'
5
+ spec.version = '0.6.6'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 5
9
- version: 0.6.5
8
+ - 6
9
+ version: 0.6.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel J. Berger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-19 00:00:00 -07:00
18
+ date: 2010-09-03 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency