pathname2 1.6.5-universal-mingw32 → 1.7.1-universal-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.
data/pathname2.gemspec CHANGED
@@ -2,29 +2,26 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'pathname2'
5
- spec.version = '1.6.5'
5
+ spec.version = '1.7.1'
6
6
  spec.author = 'Daniel J. Berger'
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
- spec.homepage = 'http://www.rubyforge.org/projects/shards'
9
+ spec.homepage = 'https://github.com/djberg96/pathname2'
10
10
  spec.summary = 'An alternate implementation of the Pathname class'
11
11
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
12
12
 
13
13
  spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
14
- spec.rubyforge_project = 'shards'
15
14
 
16
15
  spec.add_dependency('facade')
17
16
  spec.add_development_dependency('test-unit')
17
+ spec.add_development_dependency('rake')
18
18
 
19
19
  if File::ALT_SEPARATOR
20
- spec.test_file = 'test/test_pathname_windows.rb'
21
- spec.add_dependency('windows-pr')
22
- spec.platform = Gem::Platform::CURRENT
23
- spec.platform.cpu = 'universal'
24
- spec.platform.version = nil
25
- spec.original_platform = spec.platform # See rubygems issue #147
20
+ spec.add_dependency('ffi')
21
+ spec.test_files = FileList['test/windows/*.rb', 'test/test_version.rb']
22
+ spec.platform = Gem::Platform.new(['universal', 'mingw32'])
26
23
  else
27
- spec.test_file = 'test/test_pathname.rb'
24
+ spec.test_files = FileList['test/test_pathname.rb', 'test/test_version.rb']
28
25
  end
29
26
 
30
27
  spec.description = <<-EOF
@@ -1,17 +1,13 @@
1
1
  ##############################################################################
2
2
  # test_pathname.rb
3
3
  #
4
- # Test suite for the pathname package (Unix). This test suite should be run
5
- # via the Rake tasks, i.e. 'rake test_pr' to test the pure Ruby version, or
6
- # 'rake test_c' to test the C version.
4
+ # Test suite for the pathname library on unixy platforms. This test suite
5
+ # should be run via the test rake task.
7
6
  ##############################################################################
8
7
  require 'pathname2'
9
8
  require 'rbconfig'
10
- include Config
11
-
12
- require 'rubygems'
13
- gem 'test-unit'
14
- require 'test/unit'
9
+ require 'test-unit'
10
+ include RbConfig
15
11
 
16
12
  class MyPathname < Pathname; end
17
13
 
@@ -71,10 +67,6 @@ class TC_Pathname < Test::Unit::TestCase
71
67
  }
72
68
  end
73
69
 
74
- def test_version
75
- assert_equal('1.6.5', Pathname::VERSION)
76
- end
77
-
78
70
  def test_file_url_path
79
71
  assert_equal('/foo bar/baz', @url_path)
80
72
  end
@@ -222,11 +214,12 @@ class TC_Pathname < Test::Unit::TestCase
222
214
  assert_nothing_raised{ @cur_path.children }
223
215
  assert_kind_of(Array, @cur_path.children)
224
216
 
225
- children = @cur_path.children.sort.reject{ |f| f.include?('CVS') }
217
+ children = @cur_path.children.sort.reject{ |f| f.include?('git') || f.include?('.swp') }
226
218
  assert_equal(
227
219
  [
228
220
  Dir.pwd + '/test_pathname.rb',
229
- Dir.pwd + '/test_pathname_windows.rb'
221
+ Dir.pwd + '/test_version.rb',
222
+ Dir.pwd + '/windows'
230
223
  ],
231
224
  children.sort
232
225
  )
@@ -235,8 +228,8 @@ class TC_Pathname < Test::Unit::TestCase
235
228
  def test_children_without_directory
236
229
  assert_nothing_raised{ @cur_path.children(false) }
237
230
 
238
- children = @cur_path.children(false).reject{ |f| f.include?('CVS') }
239
- assert_equal(['test_pathname.rb', 'test_pathname_windows.rb'], children.sort)
231
+ children = @cur_path.children(false).reject{ |f| f.include?('git') || f.include?('.swp') }
232
+ assert_equal(['test_pathname.rb', 'test_version.rb', 'windows'], children.sort)
240
233
  end
241
234
 
242
235
  def test_unc
@@ -416,8 +409,12 @@ class TC_Pathname < Test::Unit::TestCase
416
409
  methods = FileUtils.public_instance_methods
417
410
  methods -= File.methods(false)
418
411
  methods -= Dir.methods(false)
419
- methods.delete_if{ |m| m =~ /stream/ }
420
- methods.delete('identical?')
412
+ methods.delete_if{ |m| m.to_s =~ /stream/ }
413
+ methods.delete(:identical?)
414
+ methods.delete(:sh)
415
+ methods.delete(:ruby)
416
+ methods.delete(:safe_ln)
417
+ methods.delete(:split_all)
421
418
 
422
419
  methods.each{ |method|
423
420
  assert_respond_to(@abs_path, method.to_sym)
@@ -0,0 +1,13 @@
1
+ ########################################################################
2
+ # test_version.rb
3
+ #
4
+ # Universal test file that tests for the proper version number.
5
+ ########################################################################
6
+ require 'pathname2'
7
+ require 'test-unit'
8
+
9
+ class TC_Pathname_Version < Test::Unit::TestCase
10
+ test "version is set to expected value" do
11
+ assert_equal('1.7.1', Pathname::VERSION)
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ ########################################################################
2
+ # test_append.rb
3
+ #
4
+ # Test suite for the Pathname#append method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Append < Test::Unit::TestCase
10
+ def setup
11
+ @abs_path = Pathname.new("C:\\foo\\bar")
12
+ @rel_path = Pathname.new("foo\\bar\\baz")
13
+ end
14
+
15
+ def assert_pathname_plus(a, b, c)
16
+ a = Pathname.new(a)
17
+ b = Pathname.new(b)
18
+ c = Pathname.new(c)
19
+ assert_equal(a, b + c)
20
+ end
21
+
22
+ test "appending a string to an absolute path works as expected" do
23
+ assert_pathname_plus("C:\\a\\b", "C:\\a", "b")
24
+ assert_pathname_plus("C:\\b", "a", "C:\\b")
25
+ assert_pathname_plus("a\\b", "a", "b")
26
+ assert_pathname_plus("C:\\b", "C:\\a", "..\\b")
27
+ assert_pathname_plus("C:\\a\\b", "C:\\a\\.", "\\b")
28
+ assert_pathname_plus("C:\\a\\b.txt", "C:\\a", "b.txt")
29
+ end
30
+
31
+ test "appending a string to a UNC path works as expected" do
32
+ assert_pathname_plus("\\\\foo\\bar", "\\\\foo", "bar")
33
+ assert_pathname_plus("\\\\foo", "\\\\", "foo")
34
+ assert_pathname_plus("\\\\", "\\\\", "")
35
+ assert_pathname_plus("\\\\foo\\baz", "\\\\foo\\bar", "\\..\\baz")
36
+ assert_pathname_plus("\\\\", "\\\\", "..\\..\\..\\..")
37
+ end
38
+
39
+ test "appending a plain string to a path works as expected" do
40
+ assert_nothing_raised{ @abs_path + "bar" }
41
+ assert_equal('C:\foo\bar\baz', @abs_path + 'baz')
42
+ assert_equal('C:\foo\bar', @abs_path)
43
+ end
44
+
45
+ test "appending an absolute path results in that absolute path" do
46
+ assert_pathname_plus('C:\foo\bar', @rel_path, @abs_path)
47
+ end
48
+
49
+ test "neither receiver nor argument are modified" do
50
+ assert_nothing_raised{ @abs_path + @rel_path }
51
+ assert_equal('C:\foo\bar\foo\bar\baz', @abs_path + @rel_path)
52
+ assert_equal('C:\foo\bar', @abs_path)
53
+ assert_equal('foo\bar\baz', @rel_path)
54
+ end
55
+
56
+ def teardown
57
+ @path = nil
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ ########################################################################
2
+ # test_aref.rb
3
+ #
4
+ # Test suite for the Pathname#[] method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Aref < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:/Program Files/Windows NT/Accessories")
12
+ end
13
+
14
+ test "[] with index works as expected" do
15
+ assert_equal("C:", @path[0])
16
+ assert_equal("Program Files", @path[1])
17
+ assert_equal("Accessories", @path[-1])
18
+ assert_nil(@path[10])
19
+ end
20
+
21
+ test "[] with range argument works as expected" do
22
+ assert_equal("C:\\Program Files", @path[0..1])
23
+ assert_equal("C:\\Program Files\\Windows NT", @path[0..2])
24
+ assert_equal("Program Files\\Windows NT", @path[1..2])
25
+ #assert_equal(@path, @path[0..-1]) # TODO: Spews tons of warnings
26
+ end
27
+
28
+ test "[] with index and length works as expected" do
29
+ assert_equal("C:", @path[0,1])
30
+ assert_equal("C:\\Program Files", @path[0,2])
31
+ assert_equal("Program Files\\Windows NT", @path[1,2])
32
+ end
33
+
34
+ def teardown
35
+ @path = nil
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ ########################################################################
2
+ # test_ascend.rb
3
+ #
4
+ # Test suite for the Pathname#ascend method.
5
+ ########################################################################
6
+ require 'pathname2'
7
+ require 'test-unit'
8
+
9
+ class TC_Pathname_Ascend < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:\\foo\\bar\\baz")
12
+ end
13
+
14
+ test "ascend basic functionality" do
15
+ assert_respond_to(@path, :ascend)
16
+ assert_nothing_raised{ @path.ascend{} }
17
+ end
18
+
19
+ test "ascend works as expected on a standard absolute path" do
20
+ array = []
21
+ @path.ascend{ |e| array << e }
22
+ assert_equal('C:\foo\bar\baz', array[0])
23
+ assert_equal('C:\foo\bar', array[1])
24
+ assert_equal('C:\foo', array[2])
25
+ assert_equal('C:', array[3])
26
+ end
27
+
28
+ test "ascend works as expected on a UNC path" do
29
+ array = []
30
+ Pathname.new('//foo/bar/baz').ascend{ |e| array << e }
31
+ assert_equal("\\\\foo\\bar\\baz", array[0])
32
+ assert_equal("\\\\foo\\bar", array[1])
33
+ end
34
+
35
+ test "ascend works as expected on a relative path" do
36
+ array = []
37
+ Pathname.new('foo/bar/baz').ascend{ |e| array << e }
38
+ assert_equal('foo\bar\baz', array[0])
39
+ assert_equal('foo\bar', array[1])
40
+ assert_equal('foo', array[2])
41
+ end
42
+
43
+ test "ascend does not modify the receiver" do
44
+ @path.ascend{}
45
+ assert_equal('C:\foo\bar\baz', @path)
46
+ end
47
+
48
+ def teardown
49
+ @path = nil
50
+ end
51
+ end
@@ -0,0 +1,42 @@
1
+ ########################################################################
2
+ # test_children.rb
3
+ #
4
+ # Test suite for the Pathname#children method.
5
+ ########################################################################
6
+ require 'pathname2'
7
+ require 'test-unit'
8
+
9
+ class TC_Pathname_Children < Test::Unit::TestCase
10
+ def setup
11
+ @dir = 'foo'
12
+ @path = Pathname.new(File.dirname(File.dirname(__FILE__)))
13
+
14
+ Dir.mkdir(@dir)
15
+ Dir.chdir(@dir){
16
+ FileUtils.touch('alpha')
17
+ FileUtils.touch('beta')
18
+ FileUtils.touch('gamma')
19
+ }
20
+ end
21
+
22
+ test "children basic functionality" do
23
+ assert_respond_to(@path, :children)
24
+ assert_nothing_raised{ @path.children{} }
25
+ assert_kind_of(Array, @path.children)
26
+ end
27
+
28
+ test "children method returns expected results" do
29
+ path = Pathname.new(@dir)
30
+ assert_equal(%w[foo\alpha foo\beta foo\gamma], path.children)
31
+ end
32
+
33
+ test "each result of the children method is a Pathname object" do
34
+ path = Pathname.new(@dir)
35
+ assert_kind_of(Pathname, path.children.first)
36
+ end
37
+
38
+ def teardown
39
+ FileUtils.rm_rf(@dir) if File.exist?(@dir)
40
+ @path = nil
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ ########################################################################
2
+ # test_clean.rb
3
+ #
4
+ # Test suite for the Pathname#clean method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_Clean < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:\\foo\\..\\bar\\.\\baz")
12
+ end
13
+
14
+ test "clean basic functionality" do
15
+ assert_respond_to(@path, :clean)
16
+ assert_nothing_raised{ @path.clean }
17
+ assert_kind_of(Pathname, @path.clean)
18
+ end
19
+
20
+ test "clean returns expected results for unclean paths" do
21
+ assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean)
22
+ assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean)
23
+ assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean)
24
+ assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean)
25
+ assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean)
26
+ assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean)
27
+ end
28
+
29
+ test "clean returns already clean paths unmodified" do
30
+ assert_equal("C:\\", Pathname.new("C:\\").clean)
31
+ assert_equal("C:\\a", Pathname.new("C:\\a").clean)
32
+ assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean)
33
+ assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").clean)
34
+ assert_equal("a", Pathname.new("a").clean)
35
+ end
36
+
37
+ test "clean returns a slash for . and .." do
38
+ assert_equal("\\", Pathname.new(".").clean)
39
+ assert_equal("\\", Pathname.new("..").clean)
40
+ end
41
+
42
+ test "clean does not modify receiver" do
43
+ @path.clean
44
+ assert_equal("C:\\foo\\..\\bar\\.\\baz", @path)
45
+ end
46
+
47
+ def teardown
48
+ @path = nil
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ ########################################################################
2
+ # test_clean_bang.rb
3
+ #
4
+ # Test suite for the Pathname#clean! method.
5
+ ########################################################################
6
+ require 'test-unit'
7
+ require 'pathname2'
8
+
9
+ class TC_Pathname_CleanBang < Test::Unit::TestCase
10
+ def setup
11
+ @path = Pathname.new("C:\\foo\\..\\bar\\.\\baz")
12
+ end
13
+
14
+ test "clean basic functionality" do
15
+ assert_respond_to(@path, :clean!)
16
+ assert_nothing_raised{ @path.clean! }
17
+ assert_kind_of(Pathname, @path.clean!)
18
+ end
19
+
20
+ test "clean returns expected results for unclean paths" do
21
+ assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean!)
22
+ assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean!)
23
+ assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean!)
24
+ assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean!)
25
+ assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean!)
26
+ assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean!)
27
+ end
28
+
29
+ test "clean returns already clean paths unmodified" do
30
+ assert_equal("C:\\", Pathname.new("C:\\").clean!)
31
+ assert_equal("C:\\a", Pathname.new("C:\\a").clean!)
32
+ assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean!)
33
+ assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").clean!)
34
+ assert_equal("a", Pathname.new("a").clean!)
35
+ end
36
+
37
+ test "clean returns a slash for . and .." do
38
+ assert_equal("\\", Pathname.new(".").clean!)
39
+ assert_equal("\\", Pathname.new("..").clean!)
40
+ end
41
+
42
+ test "clean! modifies receiver" do
43
+ @path.clean!
44
+ assert_equal("C:\\bar\\baz", @path)
45
+ end
46
+
47
+ def teardown
48
+ @path = nil
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ ########################################################################
2
+ # test_constructor.rb
3
+ #
4
+ # Various tests for the Pathname.new method.
5
+ ########################################################################
6
+ require 'pathname2'
7
+ require 'test-unit'
8
+
9
+ class TC_Pathname_Constructor < Test::Unit::TestCase
10
+ def setup
11
+ @abs_path = "C:/Users"
12
+ @rel_path = "Users"
13
+ @url_path = "file:///C:/Documents%20and%20Settings"
14
+ end
15
+
16
+ test "constructor handles absolute paths properly" do
17
+ assert_nothing_raised{ Pathname.new(@abs_path) }
18
+ assert_equal("C:\\Users", Pathname.new(@abs_path).to_s)
19
+ end
20
+
21
+ test "constructor handles relative paths properly" do
22
+ assert_nothing_raised{ Pathname.new(@rel_path) }
23
+ assert_equal("Users", Pathname.new(@rel_path).to_s)
24
+ end
25
+
26
+ test "constructor handles file URL's properly" do
27
+ assert_nothing_raised{ Pathname.new(@url_path) }
28
+ assert_equal("C:\\Documents and Settings", Pathname.new(@url_path).to_s)
29
+ end
30
+
31
+ test "constructor returns a Pathname object" do
32
+ assert_kind_of(Pathname, Pathname.new(@abs_path))
33
+ end
34
+
35
+ test "constructor handles frozen arguments without issue" do
36
+ assert_nothing_raised{ Pathname.new(@abs_path.freeze) }
37
+ end
38
+
39
+ test "constructor raises an error if string argument is too long" do
40
+ assert_raise(ArgumentError){ Pathname.new("foo" * 1000) }
41
+ end
42
+
43
+ def teardown
44
+ @url_path = nil
45
+ @rel_path = nil
46
+ @abs_path = nil
47
+ end
48
+ end