pathname2-1.8.2/0000755000004100000410000000000013706321500013426 5ustar www-datawww-datapathname2-1.8.2/test/0000755000004100000410000000000013706321500014405 5ustar www-datawww-datapathname2-1.8.2/test/test_version.rb0000644000004100000410000000076413706321500017465 0ustar www-datawww-data######################################################################## # test_version.rb # # Universal test file that tests for the proper version number. ######################################################################## require 'pathname2' require 'test-unit' class TC_Pathname_Version < Test::Unit::TestCase test "version is set to expected value" do assert_equal('1.8.1', Pathname::VERSION) end test "version is frozen" do assert_true(Pathname::VERSION.frozen?) end end pathname2-1.8.2/test/test_pathname.rb0000644000004100000410000003516213706321500017575 0ustar www-datawww-data############################################################################## # test_pathname.rb # # Test suite for the pathname library on unixy platforms. This test suite # should be run via the test rake task. ############################################################################## require 'pathname2' require 'fileutils' require 'rbconfig' require 'test-unit' include RbConfig class MyPathname < Pathname; end class TC_Pathname < Test::Unit::TestCase def self.startup Dir.chdir(File.expand_path(File.dirname(__FILE__))) @@pwd = Dir.pwd end def setup @abs_path = Pathname.new('/usr/local/bin') @rel_path = Pathname.new('usr/local/bin') @trl_path = Pathname.new('/usr/local/bin/') @mul_path = Pathname.new('/usr/local/lib/local/lib') @rul_path = Pathname.new('usr/local/lib/local/lib') @url_path = Pathname.new('file:///foo%20bar/baz') @cur_path = Pathname.new(@@pwd) @abs_array = [] @rel_array = [] @mypath = MyPathname.new('/usr/bin') @test_file = 'realpath_test.txt' @link_file = 'realpath_symlink.txt' @link_file2 = 'realpath_symlink2.txt' end # Convenience method to verify that the receiver was not modified # except perhaps slashes def assert_non_destructive assert_equal('/usr/local/bin', @abs_path) assert_equal('usr/local/bin', @rel_path) end # Convenience method for test_plus def assert_pathname_plus(a, b, c) a = Pathname.new(a) b = Pathname.new(b) c = Pathname.new(c) assert_equal(a, b + c) end # Convenience method for test_spaceship operator def assert_pathname_cmp(int, s1, s2) p1 = Pathname.new(s1) p2 = Pathname.new(s2) result = p1 <=> p2 assert_equal(int, result) end # Convenience method for test_relative_path_from def assert_relpath(result, dest, base) assert_equal(result, Pathname.new(dest).relative_path_from(base)) end # Convenience method for test_relative_path_from_expected_errors def assert_relpath_err(to, from) assert_raise(ArgumentError) { Pathname.new(to).relative_path_from(from) } end test "url_path returns expected result" do assert_equal('/foo bar/baz', @url_path) end test "realpath basic functionality" do FileUtils.touch(@test_file) && File.symlink(@test_file, @link_file) assert_respond_to(@abs_path, :realpath) assert_equal(@@pwd, Pathname.new('.').realpath) assert_kind_of(Pathname, Pathname.new(@link_file).realpath) end test "realpath returns expected result for simple symlink" do FileUtils.touch(@test_file) && File.symlink(@test_file, @link_file) assert_true(Pathname.new(@link_file) != Pathname.new(@link_file).realpath) assert_raises(Errno::ENOENT){ Pathname.new('../bogus').realpath } end test "realpath returns expected result for nested symlink" do FileUtils.touch(@test_file) && File.symlink(@test_file, @link_file) && File.symlink(@link_file, @link_file2) assert_true(Pathname.new(@link_file) != Pathname.new(@link_file2).realpath) assert_equal(Pathname.new(@link_file).realpath, Pathname.new(@link_file2).realpath) end # These tests taken directly from Tanaka's pathname.rb. The one failure # (commented out) is due to the fact that Tanaka's cleanpath method returns # the cleanpath for '../a' as '../a' (i.e. it does nothing) whereas mine # converts '../a' into just 'a'. Which is correct? I vote mine, because # I don't see how you can get 'more relative' from a relative path not # already in the pathname. # def test_relative_path_from assert_relpath('../a', 'a', 'b') assert_relpath('../a', 'a', 'b/') assert_relpath('../a', 'a/', 'b') assert_relpath('../a', 'a/', 'b/') assert_relpath('../a', '/a', '/b') assert_relpath('../a', '/a', '/b/') assert_relpath('../a', '/a/', '/b') assert_relpath('../a', '/a/', '/b/') assert_relpath('../b', 'a/b', 'a/c') assert_relpath('../a', '../a', '../b') assert_relpath('a', 'a', '.') assert_relpath('..', '.', 'a') assert_relpath('.', '.', '.') assert_relpath('.', '..', '..') assert_relpath('..', '..', '.') assert_relpath('c/d', '/a/b/c/d', '/a/b') assert_relpath('../..', '/a/b', '/a/b/c/d') assert_relpath('../../../../e', '/e', '/a/b/c/d') assert_relpath('../b/c', 'a/b/c', 'a/d') assert_relpath('../a', '/../a', '/b') #assert_relpath('../../a', '../a', 'b') # fails assert_relpath('.', '/a/../../b', '/b') assert_relpath('..', 'a/..', 'a') assert_relpath('.', 'a/../b', 'b') assert_relpath('a', 'a', 'b/..') assert_relpath('b/c', 'b/c', 'b/..') assert_relpath_err('/', '.') assert_relpath_err('.', '/') assert_relpath_err('a', '..') assert_relpath_err('.', '..') end def test_parent assert_respond_to(@abs_path, :parent) assert_equal('/usr/local', @abs_path.parent) assert_equal('usr/local', @rel_path.parent) assert_equal('/', Pathname.new('/').parent) end def test_pstrip assert_respond_to(@trl_path, :pstrip) assert_nothing_raised{ @trl_path.pstrip } assert_equal('/usr/local/bin', @trl_path.pstrip) assert_equal('/usr/local/bin/', @trl_path) end def test_pstrip_bang assert_respond_to(@trl_path, :pstrip!) assert_nothing_raised{ @trl_path.pstrip! } assert_equal('/usr/local/bin', @trl_path.pstrip!) assert_equal('/usr/local/bin', @trl_path) end def test_ascend assert_respond_to(@abs_path, :ascend) assert_nothing_raised{ @abs_path.ascend{} } @abs_path.ascend{ |path| @abs_array.push(path) } @rel_path.ascend{ |path| @rel_array.push(path) } assert_equal('/usr/local/bin', @abs_array[0]) assert_equal('/usr/local', @abs_array[1]) assert_equal('/usr', @abs_array[2]) assert_equal('/', @abs_array[3]) assert_equal(4, @abs_array.length) assert_equal('usr/local/bin', @rel_array[0]) assert_equal('usr/local', @rel_array[1]) assert_equal('usr', @rel_array[2]) assert_equal(3, @rel_array.length) assert_non_destructive end def test_descend assert_respond_to(@abs_path, :descend) assert_nothing_raised{ @abs_path.descend{} } @abs_path.descend{ |path| @abs_array.push(path) } @rel_path.descend{ |path| @rel_array.push(path) } assert_equal('/', @abs_array[0]) assert_equal('/usr', @abs_array[1]) assert_equal('/usr/local', @abs_array[2]) assert_equal('/usr/local/bin', @abs_array[3]) assert_equal(4, @abs_array.length) assert_equal('usr', @rel_array[0]) assert_equal('usr/local', @rel_array[1]) assert_equal('usr/local/bin', @rel_array[2]) assert_equal(3, @rel_array.length) assert_non_destructive end def test_children_with_directory assert_respond_to(@cur_path, :children) assert_nothing_raised{ @cur_path.children } assert_kind_of(Array, @cur_path.children) children = @cur_path.children.sort.reject{ |f| f.include?('git') || f.include?('.swp') } assert_equal( [ Dir.pwd + '/test_pathname.rb', Dir.pwd + '/test_version.rb', Dir.pwd + '/windows' ], children.sort ) end def test_children_without_directory assert_nothing_raised{ @cur_path.children(false) } children = @cur_path.children(false).reject{ |f| f.include?('git') || f.include?('.swp') } assert_equal(['test_pathname.rb', 'test_version.rb', 'windows'], children.sort) end def test_unc assert_raises(NotImplementedError){ @abs_path.unc? } end def test_enumerable assert_respond_to(@abs_path, :each) end def test_root assert_respond_to(@abs_path, :root) assert_nothing_raised{ @abs_path.root } assert_nothing_raised{ @rel_path.root } assert_equal('/', @abs_path.root) assert_equal('.', @rel_path.root) assert_non_destructive end def test_root? assert_respond_to(@abs_path, :root?) assert_nothing_raised{ @abs_path.root? } assert_nothing_raised{ @rel_path.root? } path1 = Pathname.new('/') path2 = Pathname.new('a') assert_equal(true, path1.root?) assert_equal(false, path2.root?) assert_non_destructive end def test_absolute assert_respond_to(@abs_path, :absolute?) assert_nothing_raised{ @abs_path.absolute? } assert_nothing_raised{ @rel_path.absolute? } assert_equal(true, @abs_path.absolute?) assert_equal(false, @rel_path.absolute?) assert_equal(true, Pathname.new('/usr/bin/ruby').absolute?) assert_equal(false, Pathname.new('foo').absolute?) assert_equal(false, Pathname.new('foo/bar').absolute?) assert_equal(false, Pathname.new('../foo/bar').absolute?) assert_non_destructive end def test_relative assert_respond_to(@abs_path, :relative?) assert_nothing_raised{ @abs_path.relative? } assert_nothing_raised{ @rel_path.relative? } assert_equal(false, @abs_path.relative?) assert_equal(true, @rel_path.relative?) assert_equal(false, Pathname.new('/usr/bin/ruby').relative?) assert_equal(true, Pathname.new('foo').relative?) assert_equal(true, Pathname.new('foo/bar').relative?) assert_equal(true, Pathname.new('../foo/bar').relative?) assert_non_destructive end def test_to_a assert_respond_to(@abs_path, :to_a) assert_nothing_raised{ @abs_path.to_a } assert_nothing_raised{ @rel_path.to_a } assert_kind_of(Array, @abs_path.to_a) assert_equal(%w/usr local bin/, @abs_path.to_a) assert_non_destructive end def test_spaceship_operator assert_respond_to(@abs_path, :<=>) assert_pathname_cmp( 0, '/foo/bar', '/foo/bar') assert_pathname_cmp(-1, '/foo/bar', '/foo/zap') assert_pathname_cmp( 1, '/foo/zap', '/foo/bar') assert_pathname_cmp(-1, 'foo', 'foo/') assert_pathname_cmp(-1, 'foo/', 'foo/bar') end def test_plus_operator assert_respond_to(@abs_path, :+) # Standard stuff assert_pathname_plus('/foo/bar', '/foo', 'bar') assert_pathname_plus('foo/bar', 'foo', 'bar') assert_pathname_plus('foo', 'foo', '.') assert_pathname_plus('foo', '.', 'foo') assert_pathname_plus('/foo', 'bar', '/foo') assert_pathname_plus('foo', 'foo/bar', '..') assert_pathname_plus('/foo', '/', '../foo') assert_pathname_plus('foo/zap', 'foo/bar', '../zap') assert_pathname_plus('.', 'foo', '..') assert_pathname_plus('foo', '..', 'foo') # Auto clean assert_pathname_plus('foo', '..', '../foo') # Auto clean # Edge cases assert_pathname_plus('.', '.', '.') assert_pathname_plus('/', '/', '..') assert_pathname_plus('.', '..', '..') assert_pathname_plus('.', 'foo', '..') # Alias assert_equal('/foo/bar', Pathname.new('/foo') / Pathname.new('bar')) end # Any tests marked with '***' mean that this behavior is different than # the current implementation. It also means I disagree with the current # implementation. def test_clean # Standard stuff assert_equal('/a/b/c', Pathname.new('/a/b/c').cleanpath) assert_equal('b/c', Pathname.new('./b/c').cleanpath) assert_equal('a', Pathname.new('a/.').cleanpath) # *** assert_equal('a/c', Pathname.new('a/./c').cleanpath) assert_equal('a/b', Pathname.new('a/b/.').cleanpath) # *** assert_equal('.', Pathname.new('a/../.').cleanpath) # *** assert_equal('/a', Pathname.new('/a/b/..').cleanpath) assert_equal('/b', Pathname.new('/a/../b').cleanpath) assert_equal('d', Pathname.new('a/../../d').cleanpath) # *** # Edge cases assert_equal('', Pathname.new('').cleanpath) assert_equal('.', Pathname.new('.').cleanpath) assert_equal('..', Pathname.new('..').cleanpath) assert_equal('/', Pathname.new('/').cleanpath) assert_equal('/', Pathname.new('//').cleanpath) assert_non_destructive end def test_dirname_basic assert_respond_to(@abs_path, :dirname) assert_nothing_raised{ @abs_path.dirname } assert_kind_of(String, @abs_path.dirname) end def test_dirname assert_equal('/usr/local', @abs_path.dirname) assert_equal('/usr/local/bin', @abs_path.dirname(0)) assert_equal('/usr/local', @abs_path.dirname(1)) assert_equal('/usr', @abs_path.dirname(2)) assert_equal('/', @abs_path.dirname(3)) assert_equal('/', @abs_path.dirname(9)) end def test_dirname_expected_errors assert_raise(ArgumentError){ @abs_path.dirname(-1) } end def test_facade_io assert_respond_to(@abs_path, :foreach) assert_respond_to(@abs_path, :read) assert_respond_to(@abs_path, :readlines) assert_respond_to(@abs_path, :sysopen) end def test_facade_file File.methods(false).each{ |method| assert_respond_to(@abs_path, method.to_sym) } end def test_facade_dir Dir.methods(false).each{ |method| assert_respond_to(@abs_path, method.to_sym) } end def test_facade_fileutils methods = FileUtils.public_instance_methods methods -= File.methods(false) methods -= Dir.methods(false) methods.delete_if{ |m| m.to_s =~ /stream/ } methods.delete(:identical?) methods.delete(:sh) methods.delete(:ruby) methods.delete(:safe_ln) methods.delete(:split_all) methods.each{ |method| assert_respond_to(@abs_path, method.to_sym) } end def test_facade_find assert_respond_to(@abs_path, :find) assert_nothing_raised{ @abs_path.find{} } Pathname.new(Dir.pwd).find{ |f| Find.prune if f.match('CVS') assert_kind_of(Pathname, f) } end # Ensures that subclasses return the subclass as the class, not a hard # coded Pathname. # def test_subclasses assert_kind_of(MyPathname, @mypath) assert_kind_of(MyPathname, @mypath + MyPathname.new('foo')) assert_kind_of(MyPathname, @mypath.realpath) assert_kind_of(MyPathname, @mypath.children.first) end # Test to ensure that the pn{ } shortcut works # def test_kernel_method assert_respond_to(Kernel, :pn) assert_nothing_raised{ pn{'/foo'} } assert_kind_of(Pathname, pn{'/foo'}) assert_equal('/foo', pn{'/foo'}) end def test_pwd_singleton_method assert_respond_to(Pathname, :pwd) assert_kind_of(String, Pathname.pwd) assert_equal(@@pwd, Pathname.pwd) end test "String#to_path instance method is implemented" do string = "/usr/local/bin" assert_respond_to(string, :to_path) assert_nothing_raised{ string.to_path } assert_kind_of(Pathname, string.to_path) end def teardown @abs_path = nil @rel_path = nil @trl_path = nil @mul_path = nil @rul_path = nil @cur_path = nil @abs_path = nil @rel_path = nil @cur_path = nil @mypath = nil @abs_array.clear @rel_array.clear File.delete(@link_file2) if File.exist?(@link_file2) File.delete(@link_file) if File.exist?(@link_file) File.delete(@test_file) if File.exist?(@test_file) @link_file2 = nil @link_file = nil @test_file = nil end def self.shutdown @@pwd = nil end end pathname2-1.8.2/test/windows/0000755000004100000410000000000013706321500016077 5ustar www-datawww-datapathname2-1.8.2/test/windows/test_long_path.rb0000644000004100000410000000226213706321500021440 0ustar www-datawww-data######################################################################## # test_long_path.rb # # Test suite for the Pathname#long_path method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_LongPath < Test::Unit::TestCase def setup @abs_path = Pathname.new("C:\\PROGRA~1") end test "long_path basic functionality" do assert_respond_to(@abs_path, :long_path) assert_nothing_raised{ @abs_path.long_path } assert_kind_of(String, @abs_path.long_path) end test "long_path returns the expected result" do assert_equal("C:\\Program Files", @abs_path.long_path) end test "long_path returns the same string if it's already long" do assert_equal("C:\\Program Files", Pathname.new("C:/Program Files").long_path) end test "long_path fails if the path does not exist" do assert_raise(Errno::ESRCH){ Pathname.new("C:/Bogus/AlsoBogus").long_path } end test "long_path method is not destructive" do str = 'C:/Program Files' assert_nothing_raised{ Pathname.new(str).long_path } assert_equal('C:/Program Files', str) end def teardown @abs_path = nil end end pathname2-1.8.2/test/windows/test_is_absolute.rb0000644000004100000410000000244013706321500021774 0ustar www-datawww-data######################################################################## # test_is_absolute.rb # # Test suite for the Pathname#absolute method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_IsAbsolute < Test::Unit::TestCase def setup @abs_std = Pathname.new("C:/foo/bar/baz") @abs_unc = Pathname.new("//foo/bar/baz") end test "absolute? basic functionality" do assert_respond_to(@abs_std, :absolute?) assert_nothing_raised{ @abs_std.absolute? } assert_boolean(@abs_std.absolute?) end test "absolute? method returns true for absolute paths" do assert_true(@abs_std.absolute?) assert_true(@abs_unc.absolute?) end test "absolute? method returns false for non-absolute paths" do assert_false(Pathname.new("foo").absolute?) assert_false(Pathname.new("foo/bar").absolute?) end test "absolute? method returns false for empty path" do assert_false(Pathname.new("").absolute?) end test "absolute? method is not destructive" do str = 'C:/foo' path = Pathname.new(str) assert_nothing_raised{ path.absolute? } assert_equal('C:\foo', path.to_s) assert_equal('C:/foo', str) end def teardown @std_absolute = nil @unc_absolute = nil end end pathname2-1.8.2/test/windows/test_parent.rb0000644000004100000410000000211013706321500020746 0ustar www-datawww-data######################################################################## # test_parent.rb # # Test suite for the Pathname#parent method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Parent < Test::Unit::TestCase def setup @path = Pathname.new("C:\\foo\\bar\\baz") end test "parent basic functionality" do assert_respond_to(@path, :parent) assert_nothing_raised{ @path.parent } assert_kind_of(Pathname, @path.parent) end test "parent returns expected results for an absolute path" do assert_equal("C:\\foo\\bar", Pathname.new("C:\\foo\\bar\\baz").parent) assert_equal("C:\\", Pathname.new("C:\\foo").parent) end test "parent returns expected results for a relative path" do assert_equal("foo", Pathname.new("foo\\bar").parent) end test "parent method returns root if already a root path" do assert_equal("C:\\", Pathname.new("C:\\").parent) assert_equal("\\\\foo\\bar", Pathname.new("//foo/bar").parent) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_to_a.rb0000644000004100000410000000271013706321500020405 0ustar www-datawww-data######################################################################## # test_to_a.rb # # Test suite for the Pathname#to_a method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_ToA < Test::Unit::TestCase def setup @path = Pathname.new('C:/Program Files/foo') end test "to_a basic functionality" do assert_respond_to(@path, :to_a) assert_nothing_raised{ @path.to_a } assert_kind_of(Array, @path.to_a) end test "to_a returns the expected results for standard paths" do assert_equal(['C:'], Pathname.new('C:/').to_a) assert_equal(['C:', 'Program Files'], Pathname.new('C:/Program Files').to_a) assert_equal(['C:', 'Program Files', 'Stuff'], Pathname.new('C:/Program Files/Stuff').to_a) assert_equal(['C:', 'Users'], Pathname.new("C:\\Users").to_a) end test "to_a returns the expected results for unc paths" do assert_equal(['foo', 'bar', 'baz'], Pathname.new('//foo/bar/baz').to_a) assert_equal(['foo', 'bar'], Pathname.new('//foo/bar').to_a) assert_equal(['foo'], Pathname.new('//foo').to_a) end test "to_a returns the expected results for empty strings and empty unc paths" do assert_equal([], Pathname.new('').to_a) assert_equal([], Pathname.new('//').to_a) end test "to_a does not modify receiver" do @path.to_a assert_equal('C:\Program Files\foo', @path) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_root.rb0000644000004100000410000000337013706321500020451 0ustar www-datawww-data######################################################################## # test_root.rb # # Test suite for the Pathname#root method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Root < Test::Unit::TestCase def setup @abs_path = Pathname.new("C:\\Program Files") @unc_path = Pathname.new("\\\\foo\\bar\\baz") @rel_path = Pathname.new("foo\\bar\\baz") end test "root method returns expected results for absolute paths" do assert_equal("C:\\", @abs_path.root) end test "root method returns expected results for paths with forward slashes" do assert_equal("C:\\", Pathname.new("C:/Program Files").root) end test "root method returns expected results for unc paths" do assert_equal("\\\\foo\\bar", @unc_path.root) assert_equal("\\\\foo", Pathname.new("\\\\foo").root) assert_equal("\\\\", Pathname.new("\\\\").root) end test "root method returns dot for relative paths" do assert_equal('.', @rel_path.root) end test "root method returns expected result for root path" do assert_equal("Z:\\", Pathname.new("Z:\\").root) assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").root) end test "root method returns expected result for empty string" do assert_equal(".", Pathname.new("").root) end test "root method returns expected result for dot and dotdot" do assert_equal(".", Pathname.new("..").root) assert_equal(".", Pathname.new(".").root) end test "root method is not destructive" do str = 'C:/Program Files' assert_nothing_raised{ Pathname.new(str).root } assert_equal('C:/Program Files', str) end def teardown @abs_path = nil @unc_path = nil @rel_path = nil end end pathname2-1.8.2/test/windows/test_realpath.rb0000644000004100000410000000201713706321500021263 0ustar www-datawww-data######################################################################## # test_realpath.rb # # Test suite for the Pathname#realpath method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Realpath < Test::Unit::TestCase def setup @cwd = Dir.pwd.tr('/', "\\") @path = Pathname.new(Dir.pwd) end test "realpath basic functionality" do assert_respond_to(@path, :realpath) assert_nothing_raised{ @path.realpath } assert_kind_of(String, @path.realpath) end test "realpath returns the expected result" do assert_equal(@cwd, @path.realpath) end test "realpath fails if the path does not exist" do assert_raise(Errno::ENOENT){ Pathname.new("C:/Bogus/AlsoBogus").realpath } end test "realpath method is not destructive" do str = 'C:/Program Files' assert_nothing_raised{ Pathname.new(str).realpath } assert_equal('C:/Program Files', str) end def teardown @cwd = nil @path = nil end end pathname2-1.8.2/test/windows/test_clean_bang.rb0000644000004100000410000000315713706321500021542 0ustar www-datawww-data######################################################################## # test_clean_bang.rb # # Test suite for the Pathname#clean! method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_CleanBang < Test::Unit::TestCase def setup @path = Pathname.new("C:\\foo\\..\\bar\\.\\baz") end test "clean basic functionality" do assert_respond_to(@path, :clean!) assert_nothing_raised{ @path.clean! } assert_kind_of(Pathname, @path.clean!) end test "clean returns expected results for unclean paths" do assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean!) assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean!) assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean!) assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean!) assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean!) assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean!) end test "clean returns already clean paths unmodified" do assert_equal("C:\\", Pathname.new("C:\\").clean!) assert_equal("C:\\a", Pathname.new("C:\\a").clean!) assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean!) assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").clean!) assert_equal("a", Pathname.new("a").clean!) end test "clean returns a slash for . and .." do assert_equal("\\", Pathname.new(".").clean!) assert_equal("\\", Pathname.new("..").clean!) end test "clean! modifies receiver" do @path.clean! assert_equal("C:\\bar\\baz", @path) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_undecorate_bang.rb0000644000004100000410000000331313706321500022603 0ustar www-datawww-data######################################################################## # test_undecorate_bang.rb # # Test suite for the Pathname#undecorate! method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_UndecorateBang < Test::Unit::TestCase def setup @std = Pathname.new('C:/Path/File.txt') end test "undecorate! basic functionality" do assert_respond_to(@std, :undecorate!) assert_nothing_raised{ @std.undecorate! } end test "undecorate! returns a Pathname object" do assert_kind_of(Pathname, @std.undecorate!) end test "undecorate! method returns an already undecorated path unchanged" do assert_equal('C:\Path\File.txt', Pathname.new('C:\Path\File.txt').undecorate!) assert_equal('\\foo\bar', Pathname.new('\\foo\bar').undecorate!) end test "undecorate! returns expected result for standard path" do assert_equal('C:\Path\File', Pathname.new('C:\Path\File[12]').undecorate!) assert_equal('C:\Path\[3].txt', Pathname.new('C:\Path\[3].txt').undecorate!) end test "undecorate! returns expected result for UNC path" do assert_equal('\\foo\bar.txt',Pathname.new('\\foo\bar[5].txt').undecorate!) assert_equal('\\foo\bar', Pathname.new('\\foo\bar[5]').undecorate!) end test "undecorate! does not modify the original string" do str = 'C:/Path/File.txt' assert_nothing_raised{ Pathname.new(str).undecorate } assert_equal('C:/Path/File.txt', str) end test "undecorate does modify the object itself" do path = Pathname.new('C:\Path\File[12]') assert_nothing_raised{ path.undecorate! } assert_equal('C:\Path\File', path) end def teardown @std = nil end end pathname2-1.8.2/test/windows/test_descend.rb0000644000004100000410000000260513706321500021073 0ustar www-datawww-data######################################################################## # test_descend.rb # # Test suite for the Pathname#descend method. ######################################################################## require 'pathname2' require 'test-unit' class TC_Pathname_Descend < Test::Unit::TestCase def setup @path = Pathname.new("C:\\foo\\bar\\baz") end test "descend basic functionality" do assert_respond_to(@path, :descend) assert_nothing_raised{ @path.descend{} } end test "descend works as expected on a standard absolute path" do array = [] @path.descend{ |e| array << e } assert_equal('C:', array[0]) assert_equal('C:\foo', array[1]) assert_equal('C:\foo\bar', array[2]) assert_equal('C:\foo\bar\baz', array[3]) end test "descend works as expected on a UNC path" do array = [] Pathname.new('//foo/bar/baz').descend{ |e| array << e } assert_equal("\\\\foo\\bar", array[0]) assert_equal("\\\\foo\\bar\\baz", array[1]) end test "descend works as expected on a relative path" do array = [] Pathname.new('foo/bar/baz').descend{ |e| array << e } assert_equal('foo', array[0]) assert_equal('foo\bar', array[1]) assert_equal('foo\bar\baz', array[2]) end test "descend does not modify the receiver" do @path.descend{} assert_equal('C:\foo\bar\baz', @path) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_pstrip.rb0000644000004100000410000000245113706321500021006 0ustar www-datawww-data######################################################################## # test_pstrip.rb # # Test suite for the Pathname#pstrip method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Pstrip < Test::Unit::TestCase def setup @path = Pathname.new("C:/Program Files////") end test "pstrip basic functionality" do assert_respond_to(@path, :pstrip) assert_nothing_raised{ @path.pstrip } assert_kind_of(Pathname, @path.pstrip) end test "pstrip returns expected result for path with trailing slashes" do assert_equal("C:\\Program Files", @path.pstrip) assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files\\\\").pstrip) assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files//\\").pstrip) end test "pstrip returns the path as is if it does not contain a trailing slash" do assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files").pstrip) assert_equal("", Pathname.new("").pstrip) end test "pstrip method is not destructive" do str = 'C:/Program Files////' assert_nothing_raised{ Pathname.new(str).pstrip } assert_equal('C:/Program Files////', str) end def teardown @abs_path = nil @unc_path = nil @rel_path = nil end end pathname2-1.8.2/test/windows/test_append.rb0000644000004100000410000000363313706321500020737 0ustar www-datawww-data######################################################################## # test_append.rb # # Test suite for the Pathname#append method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Append < Test::Unit::TestCase def setup @abs_path = Pathname.new("C:\\foo\\bar") @rel_path = Pathname.new("foo\\bar\\baz") end def assert_pathname_plus(a, b, c) a = Pathname.new(a) b = Pathname.new(b) c = Pathname.new(c) assert_equal(a, b + c) end test "appending a string to an absolute path works as expected" do assert_pathname_plus("C:\\a\\b", "C:\\a", "b") assert_pathname_plus("C:\\b", "a", "C:\\b") assert_pathname_plus("a\\b", "a", "b") assert_pathname_plus("C:\\b", "C:\\a", "..\\b") assert_pathname_plus("C:\\a\\b", "C:\\a\\.", "\\b") assert_pathname_plus("C:\\a\\b.txt", "C:\\a", "b.txt") end test "appending a string to a UNC path works as expected" do assert_pathname_plus("\\\\foo\\bar", "\\\\foo", "bar") assert_pathname_plus("\\\\foo", "\\\\", "foo") assert_pathname_plus("\\\\", "\\\\", "") assert_pathname_plus("\\\\foo\\baz", "\\\\foo\\bar", "\\..\\baz") assert_pathname_plus("\\\\", "\\\\", "..\\..\\..\\..") end test "appending a plain string to a path works as expected" do assert_nothing_raised{ @abs_path + "bar" } assert_equal('C:\foo\bar\baz', @abs_path + 'baz') assert_equal('C:\foo\bar', @abs_path) end test "appending an absolute path results in that absolute path" do assert_pathname_plus('C:\foo\bar', @rel_path, @abs_path) end test "neither receiver nor argument are modified" do assert_nothing_raised{ @abs_path + @rel_path } assert_equal('C:\foo\bar\foo\bar\baz', @abs_path + @rel_path) assert_equal('C:\foo\bar', @abs_path) assert_equal('foo\bar\baz', @rel_path) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_each.rb0000644000004100000410000000123613706321500020365 0ustar www-datawww-data######################################################################## # test_each.rb # # Test suite for the Pathname#each method. ######################################################################## require 'pathname2' require 'test-unit' class TC_Pathname_Each < Test::Unit::TestCase def setup @path = Pathname.new("C:/Users/foo/bar") end test "each basic functionality" do assert_respond_to(@path, :each) assert_nothing_raised{ @path.each{} } end test "each returns the expected results" do arr = [] @path.each{ |e| arr << e } assert_equal(['C:', 'Users', 'foo', 'bar'], arr) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_constructor.rb0000644000004100000410000000263613706321500022057 0ustar www-datawww-data######################################################################## # test_constructor.rb # # Various tests for the Pathname.new method. ######################################################################## require 'pathname2' require 'test-unit' class TC_Pathname_Constructor < Test::Unit::TestCase def setup @abs_path = "C:/Users" @rel_path = "Users" @url_path = "file:///C:/Documents%20and%20Settings" end test "constructor handles absolute paths properly" do assert_nothing_raised{ Pathname.new(@abs_path) } assert_equal("C:\\Users", Pathname.new(@abs_path).to_s) end test "constructor handles relative paths properly" do assert_nothing_raised{ Pathname.new(@rel_path) } assert_equal("Users", Pathname.new(@rel_path).to_s) end test "constructor handles file URL's properly" do assert_nothing_raised{ Pathname.new(@url_path) } assert_equal("C:\\Documents and Settings", Pathname.new(@url_path).to_s) end test "constructor returns a Pathname object" do assert_kind_of(Pathname, Pathname.new(@abs_path)) end test "constructor handles frozen arguments without issue" do assert_nothing_raised{ Pathname.new(@abs_path.freeze) } end test "constructor raises an error if string argument is too long" do assert_raise(ArgumentError){ Pathname.new("foo" * 1000) } end def teardown @url_path = nil @rel_path = nil @abs_path = nil end end pathname2-1.8.2/test/windows/test_is_relative.rb0000644000004100000410000000235613706321500021777 0ustar www-datawww-data######################################################################## # test_is_relative.rb # # Test suite for the Pathname#relative method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_IsRelative < Test::Unit::TestCase def setup @relative = Pathname.new("foo/bar") @absolute = Pathname.new("C:/foo/bar") end test "relative? basic functionality" do assert_respond_to(@relative, :relative?) assert_nothing_raised{ @relative.relative? } assert_boolean(@relative.relative?) end test "relative? method returns true for relative paths" do assert_true(@relative.relative?) end test "relative? method returns false for non-relative paths" do assert_false(@absolute.relative?) assert_false(Pathname.new("//foo/bar").relative?) end test "relative? method returns true for empty path" do assert_true(Pathname.new("").relative?) end test "relative? method is not destructive" do str = 'C:/foo' path = Pathname.new(str) assert_nothing_raised{ path.relative? } assert_equal('C:\foo', path.to_s) assert_equal('C:/foo', str) end def teardown @std_relative = nil @unc_relative = nil end end pathname2-1.8.2/test/windows/test_drive_number.rb0000644000004100000410000000342013706321500022143 0ustar www-datawww-data######################################################################## # test_drive_number.rb # # Test suite for the Pathname#drive_number method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_DriveNumber < Test::Unit::TestCase def setup @abs_path = Pathname.new("C:\\Program Files") @unc_path = Pathname.new("\\\\foo\\bar\\baz") @rel_path = Pathname.new("foo\\bar\\baz") end test "drive_number method returns expected results for absolute paths" do assert_equal(2, @abs_path.drive_number) end test "drive_number method returns expected results for paths with forward slashes" do assert_equal(2, Pathname.new("C:/Program Files").drive_number) end test "drive_number method returns expected results for unc paths" do assert_nil(@unc_path.drive_number) assert_nil(Pathname.new("\\\\foo").drive_number) assert_nil(Pathname.new("\\\\").drive_number) end test "drive_number method returns dot for relative paths" do assert_nil(@rel_path.drive_number) end test "drive_number method returns expected result for root path" do assert_equal(25, Pathname.new("Z:\\").drive_number) end test "drive_number method returns expected result for empty string" do assert_nil(Pathname.new("").drive_number) end test "drive_number method returns expected result for dot and dotdot" do assert_nil(Pathname.new(".").drive_number) assert_nil(Pathname.new("..").drive_number) end test "drive_number method is not destructive" do str = 'C:/Program Files' assert_nothing_raised{ Pathname.new(str).drive_number } assert_equal('C:/Program Files', str) end def teardown @abs_path = nil @unc_path = nil @rel_path = nil end end pathname2-1.8.2/test/windows/test_facade.rb0000644000004100000410000000333413706321500020671 0ustar www-datawww-data######################################################################## # test_facade.rb # # Test suite for the various facade methods. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Facade < Test::Unit::TestCase def setup @path = Pathname.new("C:/Program Files") end test "file facade methods are defined" do File.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) } end test "dir facade methods are defined" do Dir.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) } end test "fileutils facade methods are defined" do methods = FileUtils.public_instance_methods methods -= File.methods(false) methods -= Dir.methods(false) # Ruby 1.9.x and 2.0 incorrectly made some of these methods public methods.delete_if{ |m| m =~ /stream|^ln|identical\?|mode_to_s|^sh|ruby|safe_ln|split_all/i } methods.each{ |method| assert_respond_to(@path, method.to_sym) } end test "find facade works as expected" do assert_respond_to(@path, :find) assert_nothing_raised{ @path.find{} } Pathname.new(Dir.pwd).find{ |f| Find.prune if f.match("git") assert_kind_of(Pathname, f) } end test "custom io methods are defined" do assert_respond_to(@path, :foreach) assert_respond_to(@path, :read) assert_respond_to(@path, :readlines) assert_respond_to(@path, :sysopen) end test "exist? facade works as expected" do assert_respond_to(@path, :exist?) assert_nothing_raised{ @path.exist? } assert_true(Pathname.new("C:\\").exist?) assert_false(Pathname.new("X:\\foo\\bar\\baz").exist?) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_clean.rb0000644000004100000410000000314613706321500020551 0ustar www-datawww-data######################################################################## # test_clean.rb # # Test suite for the Pathname#clean method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Clean < Test::Unit::TestCase def setup @path = Pathname.new("C:\\foo\\..\\bar\\.\\baz") end test "clean basic functionality" do assert_respond_to(@path, :clean) assert_nothing_raised{ @path.clean } assert_kind_of(Pathname, @path.clean) end test "clean returns expected results for unclean paths" do assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean) assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean) assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean) assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean) assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean) assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean) end test "clean returns already clean paths unmodified" do assert_equal("C:\\", Pathname.new("C:\\").clean) assert_equal("C:\\a", Pathname.new("C:\\a").clean) assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean) assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").clean) assert_equal("a", Pathname.new("a").clean) end test "clean returns a slash for . and .." do assert_equal("\\", Pathname.new(".").clean) assert_equal("\\", Pathname.new("..").clean) end test "clean does not modify receiver" do @path.clean assert_equal("C:\\foo\\..\\bar\\.\\baz", @path) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_join.rb0000644000004100000410000000326413706321500020427 0ustar www-datawww-data######################################################################## # test_join.rb # # Test suite for the Pathname#join method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Join < Test::Unit::TestCase def setup @apath = Pathname.new("C:\\foo\\bar") @rpath = Pathname.new("foo\\bar\\baz") end def assert_pathname_join(final, initial, *rest) a = Pathname.new(final) b = Pathname.new(initial) assert_equal(a, b.join(*rest)) end test "join method accepts one or more arguments" do assert_nothing_raised{ @apath.join("foo") } assert_nothing_raised{ @apath.join("foo", "bar") } assert_nothing_raised{ @apath.join("foo", "bar", "baz") } end test "join method returns expected results when joining relative paths to an absolute path" do assert_pathname_join("C:\\foo", "C:\\", "foo") assert_pathname_join("C:\\foo\\bar", "C:\\foo", "bar") assert_pathname_join("C:\\foo\\bar\\baz", "C:\\foo", "bar", "baz") end test "join method returns expected results when joining relative paths to a relative path" do assert_pathname_join("foo\\bar", "foo", "bar") assert_pathname_join("foo\\bar\\baz", "foo", "bar", "baz") end test "join method returns expected results when joining an absolute path to an absolute path" do assert_pathname_join("D:\\", "C:\\", "D:\\") assert_pathname_join("D:\\foo", "C:\\", "D:\\", "foo") assert_pathname_join("D:\\", "C:\\", "foo", "bar", "D:\\") end test "join returns an instance of Pathname" do assert_kind_of(Pathname, @apath.join("foo")) end def teardown @apath = nil @rpath = nil end end pathname2-1.8.2/test/windows/test_relative_path_from.rb0000644000004100000410000000441213706321500023336 0ustar www-datawww-data######################################################################## # test_relative_path_from.rb # # Test suite for the Pathname#relative_path_from method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_RelativePathFrom < Test::Unit::TestCase def assert_relpath(result, dest, base) assert_equal(result, Pathname.new(dest).relative_path_from(base)) end def assert_relative_path_error(to, from) assert_raise(ArgumentError){ Pathname.new(to).relative_path_from(from) } end test "relative_path_from works as expected between two relative paths" do assert_relpath("..\\a", 'a', 'b') assert_relpath("..\\a", 'a', 'b/') assert_relpath("..\\a", 'a/', 'b') assert_relpath("..\\a", 'a/', 'b/') assert_relpath("..\\b", "a\\b", "a\\c") assert_relpath("..\\a", "..\\a", "..\\b") assert_relpath("..\\b\\c", "a\\b\\c", "a\\d") assert_relpath("..", "a\\..", "a") assert_relpath(".", "a\\..\\b", "b") assert_relpath("a", "a", "b\\..") assert_relpath("b\\c", "b\\c", "b\\..") end test "relative_path_from works as expected between two absolute paths" do assert_relpath("..\\a", "c:\\a", "c:\\b") assert_relpath("..\\a", "c:\\a", "c:\\b\\") assert_relpath("..\\a", "c:\\a\\", "c:\\b") assert_relpath("..\\a", "c:\\a\\", "c:\\b\\") assert_relpath("c\\d", "c:\\a\\b\\c\\d", "c:\\a\\b") assert_relpath("..\\..", "c:\\a\\b", "c:\\a\\b\\c\\d") assert_relpath("..\\..\\..\\..\\e", "c:\\e", "c:\\a\\b\\c\\d") assert_relpath("..\\a", "c:\\..\\a", "c:\\b") assert_relpath(".", "c:\\a\\..\\..\\b", "c:\\b") end test "relative_path_from works as expected between for . and .." do assert_relpath("a", "a", ".") assert_relpath("..", ".", "a") assert_relpath(".", ".", ".") assert_relpath(".", "..", "..") assert_relpath("..", "..", ".") end test "relative_path_from is not allowed between relative and absolute paths" do assert_relative_path_error("c:\\", ".") assert_relative_path_error(".", "c:\\") assert_relative_path_error("a", "..") assert_relative_path_error(".", "..") assert_relative_path_error("C:\\Temp", "D:\\Temp") assert_relative_path_error("\\\\Server\\Temp", "D:\\Temp") end end pathname2-1.8.2/test/windows/test_short_path.rb0000644000004100000410000000225013706321500021635 0ustar www-datawww-data######################################################################## # test_short_path.rb # # Test suite for the Pathname#short_path method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_ShortPath < Test::Unit::TestCase def setup @abs_path = Pathname.new("C:\\Program Files") end test "short_path basic functionality" do assert_respond_to(@abs_path, :short_path) assert_nothing_raised{ @abs_path.short_path } assert_kind_of(String, @abs_path.short_path) end test "short_path returns the expected result" do assert_equal("C:\\PROGRA~1", @abs_path.short_path) end test "short_path returns the same string if it's already short" do assert_equal("C:\\", Pathname.new("C:/").short_path) end test "short_path fails if the path does not exist" do assert_raise(Errno::ESRCH){ Pathname.new("C:/Bogus/AlsoBogus").short_path } end test "short_path method is not destructive" do str = 'C:/Program Files' assert_nothing_raised{ Pathname.new(str).short_path } assert_equal('C:/Program Files', str) end def teardown @abs_path = nil end end pathname2-1.8.2/test/windows/test_is_unc.rb0000644000004100000410000000312113706321500020740 0ustar www-datawww-data######################################################################## # test_is_unc.rb # # Test suite for the Pathname#unc? method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_IsUNC < Test::Unit::TestCase def setup @abs_path = Pathname.new("C:\\Program Files") @unc_path = Pathname.new("\\\\foo\\bar\\baz") @rel_path = Pathname.new("foo\\bar\\baz") end test "unc? basic functionality" do assert_respond_to(@unc_path, :unc?) assert_nothing_raised{ @unc_path.unc? } assert_boolean(@unc_path.unc?) end test "unc? method returns false for non-unc paths" do assert_false(Pathname.new("C:\\").unc?) assert_false(Pathname.new("C:\\Program Files").unc?) assert_false(Pathname.new("C:\\\\Program Files").unc?) assert_false(Pathname.new("C:/Program Files/File.txt").unc?) assert_false(Pathname.new("C:\\Program Files\\File[12].txt").unc?) assert_false(Pathname.new("foo\\bar").unc?) assert_false(Pathname.new(".").unc?) end test "unc? method returns true for unc paths" do assert_true(Pathname.new("\\\\foo\\bar").unc?) assert_true(Pathname.new("//foo/bar").unc?) assert_true(Pathname.new("\\\\foo\\bar\\baz").unc?) assert_true(Pathname.new("\\\\foo").unc?) assert_true(Pathname.new("\\\\").unc?) end test "unc? method is not destructive" do str = '//foo/bar' assert_nothing_raised{ Pathname.new(str).unc? } assert_equal('//foo/bar', str) end def teardown @abs_path = nil @unc_path = nil @rel_path = nil end end pathname2-1.8.2/test/windows/test_misc.rb0000644000004100000410000000160013706321500020413 0ustar www-datawww-data######################################################################## # test_misc.rb # # Test suite for miscellaneous items that didn't warrant their own # test file. ######################################################################## require 'pathname2' require 'test-unit' class MyPathname < Pathname; end class TC_Pathname_Misc < Test::Unit::TestCase def setup @mypath = MyPathname.new(Dir.pwd) end test "subclasses return instances of that subclass" do assert_kind_of(MyPathname, @mypath) assert_kind_of(MyPathname, @mypath + MyPathname.new('foo')) assert_kind_of(MyPathname, @mypath.realpath) end test "custom pn method works as expected" do assert_respond_to(Kernel, :pn) assert_nothing_raised{ pn{'c:\foo'} } assert_kind_of(Pathname, pn{'c:\foo'}) assert_equal('c:\foo', pn{'c:\foo'}) end def teardown @mypath = nil end end pathname2-1.8.2/test/windows/test_pstrip_bang.rb0000644000004100000410000000275313706321500022002 0ustar www-datawww-data######################################################################## # test_pstrip_bang.rb # # Test suite for the Pathname#pstrip! method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_PstripBang < Test::Unit::TestCase def setup @path = Pathname.new("C:/Program Files////") end test "pstrip! basic functionality" do assert_respond_to(@path, :pstrip!) assert_nothing_raised{ @path.pstrip! } assert_kind_of(Pathname, @path.pstrip!) end test "pstrip! returns expected result for path with trailing slashes" do assert_equal("C:\\Program Files", @path.pstrip!) assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files\\\\").pstrip!) assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files//\\").pstrip!) end test "pstrip! returns the path as is if it does not contain a trailing slash" do assert_equal("C:\\Program Files", Pathname.new("C:\\Program Files").pstrip!) assert_equal("", Pathname.new("").pstrip!) end test "pstrip! alters pathname object" do path = Pathname.new('C:/Program Files////') assert_nothing_raised{ path.pstrip! } assert_equal('C:\Program Files', path.to_s) end test "pstrip! method does not modify original constructor argument" do str = 'C:/Program Files////' assert_nothing_raised{ Pathname.new(str).pstrip! } assert_equal('C:/Program Files////', str) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_ascend.rb0000644000004100000410000000256713706321500020732 0ustar www-datawww-data######################################################################## # test_ascend.rb # # Test suite for the Pathname#ascend method. ######################################################################## require 'pathname2' require 'test-unit' class TC_Pathname_Ascend < Test::Unit::TestCase def setup @path = Pathname.new("C:\\foo\\bar\\baz") end test "ascend basic functionality" do assert_respond_to(@path, :ascend) assert_nothing_raised{ @path.ascend{} } end test "ascend works as expected on a standard absolute path" do array = [] @path.ascend{ |e| array << e } assert_equal('C:\foo\bar\baz', array[0]) assert_equal('C:\foo\bar', array[1]) assert_equal('C:\foo', array[2]) assert_equal('C:', array[3]) end test "ascend works as expected on a UNC path" do array = [] Pathname.new('//foo/bar/baz').ascend{ |e| array << e } assert_equal("\\\\foo\\bar\\baz", array[0]) assert_equal("\\\\foo\\bar", array[1]) end test "ascend works as expected on a relative path" do array = [] Pathname.new('foo/bar/baz').ascend{ |e| array << e } assert_equal('foo\bar\baz', array[0]) assert_equal('foo\bar', array[1]) assert_equal('foo', array[2]) end test "ascend does not modify the receiver" do @path.ascend{} assert_equal('C:\foo\bar\baz', @path) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_children.rb0000644000004100000410000000214013706321500021250 0ustar www-datawww-data######################################################################## # test_children.rb # # Test suite for the Pathname#children method. ######################################################################## require 'pathname2' require 'test-unit' class TC_Pathname_Children < Test::Unit::TestCase def setup @dir = 'foo' @path = Pathname.new(File.dirname(File.dirname(__FILE__))) Dir.mkdir(@dir) Dir.chdir(@dir){ FileUtils.touch('alpha') FileUtils.touch('beta') FileUtils.touch('gamma') } end test "children basic functionality" do assert_respond_to(@path, :children) assert_nothing_raised{ @path.children{} } assert_kind_of(Array, @path.children) end test "children method returns expected results" do path = Pathname.new(@dir) assert_equal(%w[foo\alpha foo\beta foo\gamma], path.children) end test "each result of the children method is a Pathname object" do path = Pathname.new(@dir) assert_kind_of(Pathname, path.children.first) end def teardown FileUtils.rm_rf(@dir) if File.exist?(@dir) @path = nil end end pathname2-1.8.2/test/windows/test_undecorate.rb0000644000004100000410000000276513706321500021626 0ustar www-datawww-data######################################################################## # test_undecorate.rb # # Test suite for the Pathname#undecorate method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Undecorate < Test::Unit::TestCase def setup @std = Pathname.new('C:/Path/File.txt') end test "undecorate basic functionality" do assert_respond_to(@std, :undecorate) assert_nothing_raised{ @std.undecorate } end test "undecorate returns a Pathname object" do assert_kind_of(Pathname, @std.undecorate) end test "undecorate method returns an already undecorated path unchanged" do assert_equal('C:\Path\File.txt', Pathname.new('C:\Path\File.txt').undecorate) assert_equal('\\foo\bar', Pathname.new('\\foo\bar').undecorate) end test "undecorate returns expected result for standard path" do assert_equal('C:\Path\File', Pathname.new('C:\Path\File[12]').undecorate) assert_equal('C:\Path\[3].txt', Pathname.new('C:\Path\[3].txt').undecorate) end test "undecorate returns expected result for UNC path" do assert_equal('\\foo\bar.txt',Pathname.new('\\foo\bar[5].txt').undecorate) assert_equal('\\foo\bar', Pathname.new('\\foo\bar[5]').undecorate) end test "undecorate does not modify the original string" do str = 'C:/Path/File.txt' assert_nothing_raised{ Pathname.new(str).undecorate } assert_equal('C:/Path/File.txt', str) end def teardown @std = nil end end pathname2-1.8.2/test/windows/test_aref.rb0000644000004100000410000000214413706321500020401 0ustar www-datawww-data######################################################################## # test_aref.rb # # Test suite for the Pathname#[] method. ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_Aref < Test::Unit::TestCase def setup @path = Pathname.new("C:/Program Files/Windows NT/Accessories") end test "[] with index works as expected" do assert_equal("C:", @path[0]) assert_equal("Program Files", @path[1]) assert_equal("Accessories", @path[-1]) assert_nil(@path[10]) end test "[] with range argument works as expected" do assert_equal("C:\\Program Files", @path[0..1]) assert_equal("C:\\Program Files\\Windows NT", @path[0..2]) assert_equal("Program Files\\Windows NT", @path[1..2]) #assert_equal(@path, @path[0..-1]) # TODO: Spews tons of warnings end test "[] with index and length works as expected" do assert_equal("C:", @path[0,1]) assert_equal("C:\\Program Files", @path[0,2]) assert_equal("Program Files\\Windows NT", @path[1,2]) end def teardown @path = nil end end pathname2-1.8.2/test/windows/test_is_root.rb0000644000004100000410000000222313706321500021140 0ustar www-datawww-data######################################################################## # test_is_root.rb # # Test suite for the Pathname#root method ######################################################################## require 'test-unit' require 'pathname2' class TC_Pathname_IsRoot < Test::Unit::TestCase def setup @std_root = Pathname.new("C:\\") @unc_root = Pathname.new("\\\\foo\\bar") end test "root? basic functionality" do assert_respond_to(@std_root, :root?) assert_nothing_raised{ @std_root.root? } assert_boolean(@std_root.root?) end test "root? method returns true for root paths" do assert_true(@std_root.root?) assert_true(@unc_root.root?) end test "root? method returns false for non-root paths" do assert_false(Pathname.new("C:/foo").root?) assert_false(Pathname.new("//foo/bar/baz").root?) assert_false(Pathname.new("").root?) end test "root? method is not destructive" do str = 'C:/foo' path = Pathname.new(str) assert_nothing_raised{ path.root } assert_equal('C:\foo', path.to_s) assert_equal('C:/foo', str) end def teardown @std_root = nil @unc_root = nil end end pathname2-1.8.2/MANIFEST0000644000004100000410000000213113706321500014554 0ustar www-datawww-data* CHANGES * LICENSE * MANIFEST * Rakefile * README * pathname2.gempsec * benchmarks/bench_all.rb * benchmarks/bench_plus.rb * certs/djberg96_pub.pem * examples/example_pathname.rb * lib/pathname2.rb * test/test_pathname.rb * test/test_version.rb * test/windows/test_append.rb * test/windows/test_aref.rb * test/windows/test_ascend.rb * test/windows/test_children.rb * test/windows/test_clean.rb * test/windows/test_clean_bang.rb * test/windows/test_constructor.rb * test/windows/test_descend.rb * test/windows/test_drive_number.rb * test/windows/test_each.rb * test/windows/test_facade.rb * test/windows/test_is_absolute.rb * test/windows/test_is_relative.rb * test/windows/test_is_root.rb * test/windows/test_is_unc.rb * test/windows/test_long_path.rb * test/windows/test_misc.rb * test/windows/test_parent.rb * test/windows/test_pstrip.rb * test/windows/test_pstrip_bang.rb * test/windows/test_realpath.rb * test/windows/test_relative_path_from.rb * test/windows/test_root.rb * test/windows/test_short_path.rb * test/windows/test_to_a.rb * test/windows/test_undecorate.rb * test/windows/test_undecorate_bang.rb pathname2-1.8.2/data.tar.gz.sig0000444000004100000410000000060013706321500016241 0ustar www-datawww-dataˆgô‡"£?›mà^BÒãzÕÚ ¾Aùüú²2õ4¶í®fç1 ˜r*—OØúŒ¶x'ps<— ÿ«¡ˆ#}Qˆž>]ýÂT¶“r—où;¬#8‰ V:Î0>ÇŠƒ÷jVs´¯@æStOL±™*¦Fí$>½ŸÕfµÝ®sâ—pn!r#«šÏ:4ˆÞ¿íF¨9ŸÜ×wl¾F6IYîÈeXmœHMgz)²ä˜ðµ#öî¦Äò>Äk„"zöΓ…[ø;:`-Ì?Ð —™ÜW¢Œqøôeý‚¬ªAªN6j»74#:Èmä•âXÞÐøÂDèxò\ýï™qÑr® 1þÇMœØZßý5æो Ÿ‹\ÒטôÕ%eËWBÁ*Pø³UǤ^¶mpœ~‚5¤1x›û¶œU8¢y„’Þ'pkù tÔŽYÙS.|x"“ –^'­¢Õò"—êíŒ|z`ÕnÑÜú˜‰y?H•ëÉ=ùôðP‰UÞ^|¢¬±~ºLðöAP9;ñb®ç´SüJ߸{§_íVbñ7&tU}÷ö’‰’„02¶<£PÙ8¡bK˜ùP¾N’ÁE0¢£^)¸²•ýÝå§JnÖ°fÑuyÈçüÃÿÐq òë?”ò‘5˜ïUžF(Ân³Õ\×1þJ]FÁɇ߭míä? ßOÜ ©cÎfÅpathname2-1.8.2/LICENSE0000644000004100000410000002367613706321500014451 0ustar www-datawww-data Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS pathname2-1.8.2/pathname2.gemspec0000644000004100000410000000356013706321500016656 0ustar www-datawww-datarequire 'rubygems' Gem::Specification.new do |spec| spec.name = 'pathname2' spec.version = '1.8.2' spec.author = 'Daniel J. Berger' spec.license = 'Apache-2.0' spec.email = 'djberg96@gmail.com' spec.homepage = 'https://github.com/djberg96/pathname2' spec.summary = 'An alternate implementation of the Pathname class' spec.files = Dir['**/*'].reject{ |f| f.include?('git') } spec.cert_chain = ['certs/djberg96_pub.pem'] spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST'] spec.add_dependency('facade') spec.add_development_dependency('test-unit') spec.add_development_dependency('rake') spec.metadata = { 'homepage_uri' => 'https://github.com/djberg96/pathname2', 'bug_tracker_uri' => 'https://github.com/djberg96/pathname2/issues', 'changelog_uri' => 'https://github.com/djberg96/pathname2/blob/ffi/CHANGES', 'documentation_uri' => 'https://github.com/djberg96/pathname2/wiki', 'source_code_uri' => 'https://github.com/djberg96/pathname2', 'wiki_uri' => 'https://github.com/djberg96/pathname2/wiki' } if File::ALT_SEPARATOR spec.add_dependency('ffi') spec.test_files = FileList['test/windows/*.rb', 'test/test_version.rb'] spec.platform = Gem::Platform.new(['universal', 'mingw32']) else spec.test_files = FileList['test/test_pathname.rb', 'test/test_version.rb'] end spec.description = <<-EOF The pathname2 library provides an implementation of the Pathname class different from the one that ships as part of the Ruby standard library. It is a subclass of String, though several methods have been overridden to better fit a path context. In addition, it supports file URL's as paths, provides additional methods for Windows paths, and handles UNC paths on Windows properly. See the README file for more details. EOF end pathname2-1.8.2/examples/0000755000004100000410000000000013706321500015244 5ustar www-datawww-datapathname2-1.8.2/examples/example_pathname.rb0000644000004100000410000000132013706321500021075 0ustar www-datawww-data######################################################################## # example_pathname.rb # # Some examples to demonstrate the behavior of the pathname2 library. ######################################################################## require 'pathname2' puts "VERSION: " + Pathname::VERSION path1 = Pathname.new("foo/bar") path2 = Pathname.new("baz/blah") path3 = Pathname.new("foo/../bar") path4 = Pathname.new("../baz") p path1 + path2 # foo/bar/baz/blah p path3 + path4 # baz # Shortcut syntax path = pn{ "C:\\Documents and Settings\\snoopy\\My Documents" } p path[0] # C: p path[1] # Documents and Settings p path[0,2] # C:\\Documents and Settings p path[0..2] # C:\\Documents and Settings\\snoopypathname2-1.8.2/Rakefile0000644000004100000410000001306213706321500015075 0ustar www-datawww-datarequire 'rake' require 'rake/clean' require 'rake/testtask' CLEAN.include("**/*.gem", "**/*.rbc") namespace :gem do desc "Build the pathname2 gem" task :create => [:clean] do require 'rubygems/package' spec = eval(IO.read('pathname2.gemspec')) spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem') Gem::Package.build(spec, true) end desc "Install the pathname2 gem" task :install => [:create] do file = Dir["*.gem"].first sh "gem install -l #{file}" end end desc 'Run the test suite for the pure Ruby version' Rake::TestTask.new('test') do |t| t.warning = true t.verbose = true if File::ALT_SEPARATOR t.test_files = FileList["test/windows/*.rb"] + FileList["test/test_version.rb"] else t.test_files = FileList['test/test_pathname.rb'] end end namespace :test do dir = File::ALT_SEPARATOR ? "windows" : "unix" Rake::TestTask.new(:all) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/*.rb"] + FileList["test/test_version.rb"] end Rake::TestTask.new(:append) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_append.rb"] end Rake::TestTask.new(:aref) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_aref.rb"] end Rake::TestTask.new(:ascend) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_ascend.rb"] end Rake::TestTask.new(:children) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_children.rb"] end Rake::TestTask.new(:clean) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_clean.rb"] end Rake::TestTask.new(:clean!) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_clean_bang.rb"] end Rake::TestTask.new(:constructor) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_constructor.rb"] end Rake::TestTask.new(:descend) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_descend.rb"] end Rake::TestTask.new(:drive_number) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_drive_number.rb"] end Rake::TestTask.new(:each) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_each.rb"] end Rake::TestTask.new(:facade) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_facade.rb"] end Rake::TestTask.new(:is_absolute) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_is_absolute.rb"] end Rake::TestTask.new(:is_relative) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_is_relative.rb"] end Rake::TestTask.new(:is_root) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_is_root.rb"] end Rake::TestTask.new(:is_unc) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_is_unc.rb"] end Rake::TestTask.new(:join) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_join.rb"] end Rake::TestTask.new(:long_path) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_long_path.rb"] end Rake::TestTask.new(:misc) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_misc.rb"] end Rake::TestTask.new(:parent) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_parent.rb"] end Rake::TestTask.new(:pstrip) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_pstrip.rb"] end Rake::TestTask.new(:pstrip!) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_pstrip_bang.rb"] end Rake::TestTask.new(:realpath) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_realpath.rb"] end Rake::TestTask.new(:relative_path_from) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_relative_path_from.rb"] end Rake::TestTask.new(:root) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_root.rb"] end Rake::TestTask.new(:short_path) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_short_path.rb"] end Rake::TestTask.new(:to_a) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_to_a.rb"] end Rake::TestTask.new(:undecorate) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_undecorate.rb"] end Rake::TestTask.new(:undecorate!) do |t| t.warning = true t.verbose = true t.test_files = FileList["test/#{dir}/test_undecorate_bang.rb"] end end desc 'Run the Pathname benchmark suite' task :benchmark do sh 'ruby -Ilib benchmarks/bench_pathname.rb' end desc 'Run the benchmark suite for Pathname#+ vs File.join' task :benchmark_plus do sh 'ruby -Ilib benchmarks/bench_plus.rb' end task :default => :test pathname2-1.8.2/lib/0000755000004100000410000000000013706321500014174 5ustar www-datawww-datapathname2-1.8.2/lib/pathname2.rb0000644000004100000410000006432713706321500016414 0ustar www-datawww-data# == Synopsis # # Pathname represents a path name on a filesystem. A Pathname can be # relative or absolute. It does not matter whether the path exists or not. # # All functionality from File, FileTest, and Dir is included, using a facade # pattern. # # This class works on both Unix and Windows, including UNC path names. Note # that forward slashes are converted to backslashes on Windows systems. # # == Usage # # require "pathname2" # # # Unix # path1 = Pathname.new("/foo/bar/baz") # path2 = Pathname.new("../zap") # # path1 + path2 # "/foo/bar/zap" # path1.dirname # "/foo/bar" # # # Windows # path1 = Pathname.new("C:\\foo\\bar\\baz") # path2 = Pathname.new("..\\zap") # # path1 + path2 # "C:\\foo\\bar\\zap" # path1.exists? # Does the path exist? # require 'facade' require 'fileutils' require 'pp' if File::ALT_SEPARATOR require 'ffi' class String # Convenience method for converting strings to UTF-16LE for wide character # functions that require it. def wincode if self.encoding.name != 'UTF-16LE' temp = self.dup (temp.tr(File::SEPARATOR, File::ALT_SEPARATOR) << 0.chr).encode('UTF-16LE') end end end end # You're mine now. Object.send(:remove_const, :Pathname) if defined?(Pathname) class Pathname < String class Error < StandardError; end extend Facade undef_method :pretty_print facade File, File.methods(false).map{ |m| m.to_sym } - [ :chmod, :lchmod, :chown, :lchown, :dirname, :fnmatch, :fnmatch?, :link, :open, :realpath, :rename, :symlink, :truncate, :utime, :basename, :expand_path, :join ] facade Dir, Dir.methods(false).map{ |m| m.to_sym } - [ :chdir, :entries, :glob, :foreach, :mkdir, :open ] private alias :_plus_ :+ # Used to prevent infinite loops in some cases if File::ALT_SEPARATOR extend FFI::Library ffi_lib :shlwapi attach_function :PathAppendW, [:pointer, :pointer], :bool attach_function :PathCanonicalizeW, [:pointer, :buffer_in], :bool attach_function :PathCreateFromUrlW, [:buffer_in, :pointer, :pointer, :ulong], :long attach_function :PathGetDriveNumberW, [:buffer_in], :int attach_function :PathIsRelativeW, [:buffer_in], :bool attach_function :PathIsRootW, [:buffer_in], :bool attach_function :PathIsUNCW, [:buffer_in], :bool attach_function :PathIsURLW, [:buffer_in], :bool attach_function :PathRemoveBackslashW, [:buffer_in], :pointer attach_function :PathStripToRootW, [:pointer], :bool attach_function :PathUndecorateW, [:pointer], :void ffi_lib :kernel32 attach_function :GetLongPathNameW, [:buffer_in, :buffer_out, :ulong], :ulong attach_function :GetShortPathNameW, [:buffer_in, :pointer, :ulong], :ulong end public # The version of the pathname2 library VERSION = '1.8.2'.freeze # The maximum length of a path MAXPATH = 1024 unless defined? MAXPATH # Yes, I willfully violate POSIX # Returns the expanded path of the current working directory. # # Synonym for Pathname.new(Dir.pwd). # def self.pwd new(Dir.pwd) end class << self alias getwd pwd end # Creates and returns a new Pathname object. # # On platforms that define File::ALT_SEPARATOR, all forward slashes are # replaced with the value of File::ALT_SEPARATOR. On MS Windows, for # example, all forward slashes are replaced with backslashes. # # File URL's will be converted to Pathname objects, e.g. the file URL # "file:///C:/Documents%20and%20Settings" will become 'C:\Documents and Settings'. # # Examples: # # Pathname.new("/foo/bar/baz") # Pathname.new("foo") # Pathname.new("file:///foo/bar/baz") # Pathname.new("C:\\Documents and Settings\\snoopy") # def initialize(path) if path.length > MAXPATH msg = "string too long. maximum string length is " + MAXPATH.to_s raise ArgumentError, msg end @sep = File::ALT_SEPARATOR || File::SEPARATOR @win = File::ALT_SEPARATOR # Handle File URL's. The separate approach for Windows is necessary # because Ruby's URI class does not (currently) parse absolute file URL's # properly when they include a drive letter. if @win wpath = path.wincode if PathIsURLW(wpath) buf = FFI::MemoryPointer.new(:char, MAXPATH) len = FFI::MemoryPointer.new(:ulong) len.write_ulong(buf.size) if PathCreateFromUrlW(wpath, buf, len, 0) == 0 path = buf.read_string(path.size * 2).tr(0.chr, '') else raise Error, "invalid file url: #{path}" end end else if path.index('file:///', 0) require 'uri' path = URI::Parser.new.unescape(path)[7..-1] end end # Convert forward slashes to backslashes on Windows path = path.tr(File::SEPARATOR, File::ALT_SEPARATOR) if @win super(path) end # Returns a real (absolute) pathname of +self+ in the actual filesystem. # # Unlike most Pathname methods, this one assumes that the path actually # exists on your filesystem. If it doesn't, an error is raised. If a # circular symlink is encountered a system error will be raised. # # Example: # # Dir.pwd # => /usr/local # File.exists?('foo') # => true # Pathname.new('foo').realpath # => /usr/local/foo # def realpath File.stat(self) # Check to ensure that the path exists if File.symlink?(self) file = self.dup while true file = File.join(File.dirname(file), File.readlink(file)) break unless File.symlink?(file) end self.class.new(file).clean else self.class.new(Dir.pwd) + self end end # Returns the children of the directory, files and subdirectories, as an # array of Pathname objects. If you set +with_directory+ to +false+, then # the returned pathnames will contain the filename only. # # Note that the result never contain the entries '.' and '..' in the # the directory because they are not children. Also note that this method # is *not* recursive. # # Example: # # path = Pathname.new('/usr/bin') # path.children # => ['/usr/bin/ruby', '/usr/bin/perl', ...] # path.children(false) # => ['ruby', 'perl', ...] # def children(with_directory = true) with_directory = false if self == '.' result = [] Dir.foreach(self) { |file| next if file == '.' || file == '..' if with_directory result << self.class.new(File.join(self, file)) else result << self.class.new(file) end } result end # Windows only # # Removes the decoration from a path string. Non-destructive. # # Example: # # path = Pathname.new('C:\Path\File[5].txt') # path.undecorate # => C:\Path\File.txt. # def undecorate unless @win raise NotImplementedError, "not supported on this platform" end wpath = FFI::MemoryPointer.from_string(self.wincode) PathUndecorateW(wpath) self.class.new(wpath.read_string(wpath.size).split("\000\000").first.tr(0.chr, '')) end # Windows only # # Performs the substitution of Pathname#undecorate in place. # def undecorate! self.replace(undecorate) end # Windows only # # Returns the short path for a long path name. # # Example: # # path = Pathname.new('C:\Program Files\Java') # path.short_path # => C:\Progra~1\Java. # def short_path raise NotImplementedError, "not supported on this platform" unless @win buf = FFI::MemoryPointer.new(:char, MAXPATH) wpath = self.wincode size = GetShortPathNameW(wpath, buf, buf.size) raise SystemCallError.new('GetShortPathName', FFI.errno) if size == 0 self.class.new(buf.read_bytes(size * 2).delete(0.chr)) end # Windows only # # Returns the long path for a long path name. # # Example: # # path = Pathname.new('C:\Progra~1\Java') # path.long_path # => C:\Program Files\Java. # def long_path raise NotImplementedError, "not supported on this platform" unless @win buf = FFI::MemoryPointer.new(:char, MAXPATH) wpath = self.wincode size = GetLongPathNameW(wpath, buf, buf.size) raise SystemCallError.new('GetShortPathName', FFI.errno) if size == 0 self.class.new(buf.read_bytes(size * 2).delete(0.chr)) end # Removes all trailing slashes, if present. Non-destructive. # # Example: # # path = Pathname.new('/usr/local/') # path.pstrip # => '/usr/local' # def pstrip str = self.dup return str if str.empty? while ["/", "\\"].include?(str.to_s[-1].chr) str.strip! str.chop! end self.class.new(str) end # Performs the substitution of Pathname#pstrip in place. # def pstrip! self.replace(pstrip) end # Splits a pathname into strings based on the path separator. # # Examples: # # Pathname.new('/usr/local/bin').to_a # => ['usr', 'local', 'bin'] # Pathname.new('C:\WINNT\Fonts').to_a # => ['C:', 'WINNT', 'Fonts'] # def to_a # Split string by path separator if @win array = tr(File::SEPARATOR, File::ALT_SEPARATOR).split(@sep) else array = split(@sep) end array.delete("") # Remove empty elements array end # Yields each component of the path name to a block. # # Example: # # Pathname.new('/usr/local/bin').each{ |element| # puts "Element: #{element}" # } # # Yields 'usr', 'local', and 'bin', in turn # def each to_a.each{ |element| yield element } end # Returns the path component at +index+, up to +length+ components, joined # by the path separator. If the +index+ is a Range, then that is used # instead and the +length+ is ignored. # # Keep in mind that on MS Windows the drive letter is the first element. # # Examples: # # path = Pathname.new('/home/john/source/ruby') # path[0] # => 'home' # path[1] # => 'john' # path[0, 3] # => '/home/john/source' # path[0..1] # => '/home/john' # # path = Pathname.new('C:/Documents and Settings/John/Source/Ruby') # path[0] # => 'C:\' # path[1] # => 'Documents and Settings' # path[0, 3] # => 'C:\Documents and Settings\John' # path[0..1] # => 'C:\Documents and Settings' # def [](index, length=nil) if index.is_a?(Fixnum) if length path = File.join(to_a[index, length]) else path = to_a[index] end elsif index.is_a?(Range) if length warn 'Length argument ignored' end path = File.join(to_a[index]) else raise TypeError, "Only Fixnums and Ranges allowed as first argument" end if path && @win path = path.tr("/", "\\") end path end # Yields each component of the path, concatenating the next component on # each iteration as a new Pathname object, starting with the root path. # # Example: # # path = Pathname.new('/usr/local/bin') # # path.descend{ |name| # puts name # } # # First iteration => '/' # Second iteration => '/usr' # Third iteration => '/usr/local' # Fourth iteration => '/usr/local/bin' # def descend if root? yield root return end if @win path = unc? ? "#{root}\\" : "" else path = absolute? ? root : "" end # Yield the root directory if an absolute path (and not Windows) unless @win && !unc? yield root if absolute? end each{ |element| if @win && unc? next if root.to_a.include?(element) end path << element << @sep yield self.class.new(path.chop) } end # Yields the path, minus one component on each iteration, as a new # Pathname object, ending with the root path. # # Example: # # path = Pathname.new('/usr/local/bin') # # path.ascend{ |name| # puts name # } # # First iteration => '/usr/local/bin' # Second iteration => '/usr/local' # Third iteration => '/usr' # Fourth iteration => '/' # def ascend if root? yield root return end n = to_a.length while n > 0 path = to_a[0..n-1].join(@sep) if absolute? if @win && unc? path = "\\\\" << path end unless @win path = root << path end end path = self.class.new(path) yield path if @win && unc? break if path.root? end n -= 1 end # Yield the root directory if an absolute path (and not Windows) unless @win yield root if absolute? end end # Returns the root directory of the path, or '.' if there is no root # directory. # # On Unix, this means the '/' character. On Windows, this can refer # to the drive letter, or the server and share path if the path is a # UNC path. # # Examples: # # Pathname.new('/usr/local').root # => '/' # Pathname.new('lib').root # => '.' # # On MS Windows: # # Pathname.new('C:\WINNT').root # => 'C:' # Pathname.new('\\some\share\foo').root # => '\\some\share' # def root dir = "." if @win wpath = FFI::MemoryPointer.from_string(self.wincode) if PathStripToRootW(wpath) dir = wpath.read_string(wpath.size).split("\000\000").first.tr(0.chr, '') end else dir = "/" if self =~ /^\// end self.class.new(dir) end # Returns whether or not the path consists only of a root directory. # # Examples: # # Pathname.new('/').root? # => true # Pathname.new('/foo').root? # => false # def root? if @win PathIsRootW(self.wincode) else self == root end end # MS Windows only # # Determines if the string is a valid Universal Naming Convention (UNC) # for a server and share path. # # Examples: # # Pathname.new("\\\\foo\\bar").unc? # => true # Pathname.new('C:\Program Files').unc? # => false # def unc? raise NotImplementedError, "not supported on this platform" unless @win PathIsUNCW(self.wincode) end # MS Windows only # # Returns the drive number that corresponds to the root, or nil if not # applicable. # # Example: # # Pathname.new("C:\\foo").drive_number # => 2 # def drive_number unless @win raise NotImplementedError, "not supported on this platform" end num = PathGetDriveNumberW(self.wincode) num >= 0 ? num : nil end # Compares two Pathname objects. Note that Pathnames may only be compared # against other Pathnames, not strings. Otherwise nil is returned. # # Example: # # path1 = Pathname.new('/usr/local') # path2 = Pathname.new('/usr/local') # path3 = Pathname.new('/usr/local/bin') # # path1 <=> path2 # => 0 # path1 <=> path3 # => -1 # def <=>(string) return nil unless string.kind_of?(Pathname) super end # Returns the parent directory of the given path. # # Example: # # Pathname.new('/usr/local/bin').parent # => '/usr/local' # def parent return self if root? self + ".." # Use our custom '+' method end # Returns a relative path from the argument to the receiver. If +self+ # is absolute, the argument must be absolute too. If +self+ is relative, # the argument must be relative too. For relative paths, this method uses # an imaginary, common parent path. # # This method does not access the filesystem. It assumes no symlinks. # You should only compare directories against directories, or files against # files, or you may get unexpected results. # # Raises an ArgumentError if it cannot find a relative path. # # Examples: # # path = Pathname.new('/usr/local/bin') # path.relative_path_from('/usr/bin') # => "../local/bin" # # path = Pathname.new("C:\\WINNT\\Fonts") # path.relative_path_from("C:\\Program Files") # => "..\\WINNT\\Fonts" # def relative_path_from(base) base = self.class.new(base) unless base.kind_of?(Pathname) if self.absolute? != base.absolute? raise ArgumentError, "relative path between absolute and relative path" end return self.class.new(".") if self == base return self if base == "." # Because of the way the Windows version handles Pathname#clean, we need # a little extra help here. if @win if root != base.root msg = 'cannot determine relative paths from different root paths' raise ArgumentError, msg end if base == '..' && (self != '..' || self != '.') raise ArgumentError, "base directory may not contain '..'" end end dest_arr = self.clean.to_a base_arr = base.clean.to_a dest_arr.delete('.') base_arr.delete('.') # diff_arr = dest_arr - base_arr while !base_arr.empty? && !dest_arr.empty? && base_arr[0] == dest_arr[0] base_arr.shift dest_arr.shift end if base_arr.include?("..") raise ArgumentError, "base directory may not contain '..'" end base_arr.fill("..") rel_path = base_arr + dest_arr if rel_path.empty? self.class.new(".") else self.class.new(rel_path.join(@sep)) end end # Adds two Pathname objects together, or a Pathname and a String. It # also automatically cleans the Pathname. # # Adding a root path to an existing path merely replaces the current # path. Adding '.' to an existing path does nothing. # # Example: # # path1 = '/foo/bar' # path2 = '../baz' # path1 + path2 # '/foo/baz' # def +(string) unless string.kind_of?(Pathname) string = self.class.new(string) end # Any path plus "." is the same directory return self if string == "." return string if self == "." # Use the builtin PathAppend() function if on Windows - much easier if @win path = FFI::MemoryPointer.new(:char, MAXPATH) path.write_string(self.dup.wincode) more = FFI::MemoryPointer.from_string(string.wincode) PathAppendW(path, more) path = path.read_string(path.size).split("\000\000").first.delete(0.chr) return self.class.new(path) # PathAppend cleans automatically end # If the string is an absolute directory, return it return string if string.absolute? array = to_a + string.to_a new_string = array.join(@sep) unless relative? || @win temp = @sep + new_string # Add root path back if needed new_string.replace(temp) end self.class.new(new_string).clean end alias :/ :+ # Returns whether or not the path is an absolute path. # # Example: # # Pathname.new('/usr/bin').absolute? # => true # Pathname.new('usr').absolute? # => false # def absolute? !relative? end # Returns whether or not the path is a relative path. # # Example: # # Pathname.new('/usr/bin').relative? # => true # Pathname.new('usr').relative? # => false # def relative? if @win PathIsRelativeW(self.wincode) else root == "." end end # Removes unnecessary '.' paths and ellides '..' paths appropriately. # This method is non-destructive. # # Example: # # path = Pathname.new('/usr/./local/../bin') # path.clean # => '/usr/bin' # def clean return self if self.empty? if @win ptr = FFI::MemoryPointer.new(:char, MAXPATH) if PathCanonicalizeW(ptr, self.wincode) return self.class.new(ptr.read_string(ptr.size).delete(0.chr)) else return self end end final = [] to_a.each{ |element| next if element == "." final.push(element) if element == ".." && self != ".." 2.times{ final.pop } end } final = final.join(@sep) final = root._plus_(final) if root != "." final = "." if final.empty? self.class.new(final) end alias :cleanpath :clean # Identical to Pathname#clean, except that it modifies the receiver # in place. # def clean! self.replace(clean) end alias cleanpath! clean! # Similar to File.dirname, but this method allows you to specify the number # of levels up you wish to refer to. # # The default level is 1, i.e. it works the same as File.dirname. A level of # 0 will return the original path. A level equal to or greater than the # number of path elements will return the root path. # # A number less than 0 will raise an ArgumentError. # # Example: # # path = Pathname.new('/usr/local/bin/ruby') # # puts path.dirname # => /usr/local/bin # puts path.dirname(2) # => /usr/local # puts path.dirname(3) # => /usr # puts path.dirname(9) # => / # def dirname(level = 1) raise ArgumentError if level < 0 local_path = self.dup level.times{ |n| local_path = File.dirname(local_path) } self.class.new(local_path) end # Joins the given pathnames onto +self+ to create a new Pathname object. # # path = Pathname.new("C:/Users") # path = path.join("foo", "Downloads") # => C:/Users/foo/Downloads # def join(*args) args.unshift self result = args.pop result = self.class.new(result) unless result === self.class return result if result.absolute? args.reverse_each{ |path| path = self.class.new(path) unless path === self.class result = path + result break if result.absolute? } result end # A custom pretty printer def pretty_print(q) if File::ALT_SEPARATOR q.text(self.to_s.tr(File::SEPARATOR, File::ALT_SEPARATOR)) else q.text(self.to_s) end end #-- Find facade # Pathname#find is an iterator to traverse a directory tree in a depth first # manner. It yields a Pathname for each file under the directory passed to # Pathname.new. # # Since it is implemented by the Find module, Find.prune can be used to # control the traverse. # # If +self+ is ".", yielded pathnames begin with a filename in the current # current directory, not ".". # def find(&block) require "find" if self == "." Find.find(self){ |f| yield self.class.new(f.sub(%r{\A\./}, '')) } else Find.find(self){ |f| yield self.class.new(f) } end end #-- IO methods not handled by facade # IO.foreach def foreach(*args, &block) IO.foreach(self, *args, &block) end # IO.read def read(*args) IO.read(self, *args) end # IO.readlines def readlines(*args) IO.readlines(self, *args) end # IO.sysopen def sysopen(*args) IO.sysopen(self, *args) end #-- Dir methods not handled by facade # Dir.glob # # :no-doc: # This differs from Tanaka's implementation in that it does a temporary # chdir to the path in question, then performs the glob. # def glob(*args) Dir.chdir(self){ if block_given? Dir.glob(*args){ |file| yield self.class.new(file) } else Dir.glob(*args).map{ |file| self.class.new(file) } end } end # Dir.chdir def chdir(&block) Dir.chdir(self, &block) end # Dir.entries def entries Dir.entries(self).map{ |file| self.class.new(file) } end # Dir.mkdir def mkdir(*args) Dir.mkdir(self, *args) end # Dir.opendir def opendir(&block) Dir.open(self, &block) end #-- File methods not handled by facade # File.chmod def chmod(mode) File.chmod(mode, self) end # File.lchmod def lchmod(mode) File.lchmod(mode, self) end # File.chown def chown(owner, group) File.chown(owner, group, self) end # File.lchown def lchown(owner, group) File.lchown(owner, group, self) end # File.fnmatch def fnmatch(pattern, *args) File.fnmatch(pattern, self, *args) end # File.fnmatch? def fnmatch?(pattern, *args) File.fnmatch?(pattern, self, *args) end # File.link def link(old) File.link(old, self) end # File.open def open(*args, &block) File.open(self, *args, &block) end # File.rename def rename(name) File.rename(self, name) end # File.symlink def symlink(old) File.symlink(old, self) end # File.truncate def truncate(length) File.truncate(self, length) end # File.utime def utime(atime, mtime) File.utime(atime, mtime, self) end # File.basename def basename(*args) self.class.new(File.basename(self, *args)) end # File.expand_path def expand_path(*args) self.class.new(File.expand_path(self, *args)) end #-- # FileUtils facade. Note that methods already covered by File and Dir # are not defined here (pwd, mkdir, etc). #++ # FileUtils.cd def cd(*args, &block) FileUtils.cd(self, *args, &block) end # FileUtils.mkdir_p def mkdir_p(*args) FileUtils.mkdir_p(self, *args) end alias mkpath mkdir_p # FileUtils.ln def ln(*args) FileUtils.ln(self, *args) end # FileUtils.ln_s def ln_s(*args) FileUtils.ln_s(self, *args) end # FileUtils.ln_sf def ln_sf(*args) FileUtils.ln_sf(self, *args) end # FileUtils.cp def cp(*args) FileUtils.cp(self, *args) end # FileUtils.cp_r def cp_r(*args) FileUtils.cp_r(self, *args) end # FileUtils.mv def mv(*args) FileUtils.mv(self, *args) end # FileUtils.rm def rm(*args) FileUtils.rm(self, *args) end alias remove rm # FileUtils.rm_f def rm_f(*args) FileUtils.rm_f(self, *args) end # FileUtils.rm_r def rm_r(*args) FileUtils.rm_r(self, *args) end # FileUtils.rm_rf def rm_rf(*args) FileUtils.rm_rf(self, *args) end # FileUtils.rmtree def rmtree(*args) FileUtils.rmtree(self, *args) end # FileUtils.install def install(*args) FileUtils.install(self, *args) end # FileUtils.touch def touch(*args) FileUtils.touch(*args) end # FileUtils.compare_file def compare_file(file) FileUtils.compare_file(self, file) end # FileUtils.uptodate? def uptodate?(*args) FileUtils.uptodate(self, *args) end # FileUtils.copy_file def copy_file(*args) FileUtils.copy_file(self, *args) end # FileUtils.remove_dir def remove_dir(*args) FileUtils.remove_dir(self, *args) end # FileUtils.remove_file def remove_file(*args) FileUtils.remove_dir(self, *args) end # FileUtils.copy_entry def copy_entry(*args) FileUtils.copy_entry(self, *args) end end module Kernel # Usage: pn{ path } # # A shortcut for Pathname.new # def pn instance_eval{ Pathname.new(yield) } end begin remove_method(:Pathname) rescue NoMethodError, NameError # Do nothing, not defined. end # Synonym for Pathname.new # def Pathname(path) Pathname.new(path) end end class String # Convert a string directly into a Pathname object. def to_path Pathname.new(self) end end pathname2-1.8.2/README0000644000004100000410000000610313706321500014306 0ustar www-datawww-data== Description A drop-in replacement for the current Pathname class. == Prerequisites * facade * ffi (Windows only) * test-unit (testing only) == Installation gem install pathname2 == Synopsis require 'pathname2' # Unix path1 = Pathname.new("/foo/bar/baz") path2 = Pathname.new("../zap") path1 + path2 # "/foo/bar/zap" path1 / path2 # "/foo/bar/zap" (same as +) path1.exists? # Does this path exist? path1.dirname # "/foo/bar" path1.to_a # ['foo','bar','baz'] # Windows path1 = Pathname.new("C:/foo/bar/baz") path2 = Pathname.new("../zap") path1 + path2 # "C:\\foo\\bar\\zap" path1.root # "C:\\" path1.to_a # ['C:','foo','bar','baz'] == Windows Notes All forward slashes are converted to backslashes for Pathname objects. == Differences between Unix and Windows If your pathname consists solely of ".", or "..", the return value for Pathname#clean will be different. On Win32, "\\" is returned, while on Unix "." is returned. I consider this an extreme edge case and will not worry myself with it. == Differences between Pathname in the standard library and this version * It is a subclass of String (and thus, mixes in Enumerable). * It has sensical to_a and root instance methods. * It works on Windows and Unix. The current implementation does not work with Windows path names very well, and not at all when it comes to UNC paths. * The Pathname#cleanpath method works differently - it always returns a canonical pathname. In addition, there is no special consideration for symlinks (yet), though I'm not sure it warrants it. * The Pathname#+ method auto cleans. * It uses a facade for all File and Dir methods, as well as most FileUtils methods. * Pathname#clean works slightly differently. In the stdlib version, Pathname#clean("../a") returns "../a". In this version, it returns "a". This affects other methods, such as Pathname#relative_path_from. * Accepts file urls and converts them to paths automatically, e.g. file:///foo%20bar/baz becomes '/foo/bar/baz'. * Adds a Kernel level +pn+ method as a shortcut. * Allows you to add paths together with the '/' operator. == Method Priority Because there is some overlap in method names between File, Dir, and FileUtils, the priority is as follows: * File * Dir * FileUtils In other words, whichever of these defines a given method first is the method that is used by the pathname2 library. == Known Issues On MS Windows, some methods may not work on pathnames greater than 260 characters because of internal function limitations. Any issues you find should be reported on the project page at https://github.com/djberg96/pathname2 == Future Plans Suggestions welcome. == License Apache-2.0 == Copyright (C) 2003-2020 Daniel J. Berger All rights reserved. == Warranty This library is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose. == Author Daniel J. Berger pathname2-1.8.2/benchmarks/0000755000004100000410000000000013706321500015543 5ustar www-datawww-datapathname2-1.8.2/benchmarks/bench_pathname.rb0000644000004100000410000000532113706321500021025 0ustar www-datawww-data##################################################################### # bench_pathname.rb # # Benchmark suite for all methods of the Pathname class, excluding # the facade methods. # # Use the Rake tasks to run this benchmark: # # => rake benchmark to run the pure Ruby benchmark. ##################################################################### require 'benchmark' require 'pathname2' require 'rbconfig' if RbConfig::CONFIG['host_os'] =~ /mingw|mswin/i path1 = Pathname.new("C:\\Program Files\\Windows NT") path2 = Pathname.new("Accessories") path3 = Pathname.new("C:\\Program Files\\..\\.\\Windows NT") else path1 = Pathname.new("/usr/local") path2 = Pathname.new("bin") path3 = Pathname.new("/usr/../local/./bin") path4 = Pathname.new("/dev/stdin") end MAX = 10000 Benchmark.bm(25) do |bench| bench.report("Pathname.new(path)"){ MAX.times{ Pathname.new("/usr/local/bin") } } bench.report("Pathname#+(Pathname)"){ MAX.times{ path1 + path2 } } bench.report("Pathname#+(String)"){ MAX.times{ path1 + path2 } } bench.report("Pathname#children"){ MAX.times{ path1.children } } bench.report("Pathname#pstrip"){ MAX.times{ path1.pstrip } } bench.report("Pathname#pstrip!"){ MAX.times{ path1.pstrip! } } bench.report("Pathname#to_a"){ MAX.times{ path1.to_a } } bench.report("Pathname#descend"){ MAX.times{ path1.descend{} } } bench.report("Pathname#ascend"){ MAX.times{ path1.ascend{} } } bench.report("Pathname#root"){ MAX.times{ path1.root } } bench.report("Pathname#root?"){ MAX.times{ path1.root? } } bench.report("Pathname#<=>"){ MAX.times{ path1 <=> path2 } } bench.report("Pathname#absolute?"){ MAX.times{ path1.absolute? } } bench.report("Pathname#relative?"){ MAX.times{ path1.relative? } } bench.report("Pathname#clean"){ MAX.times{ path3.clean } } bench.report("Pathname#clean!"){ MAX.times{ path3.clean! } } # Platform specific tests if RbConfig::CONFIG['host_os'] =~ /mingw|mswin/i bench.report("Pathname.new(file_url)"){ MAX.times{ Pathname.new("file:///C:/usr/local/bin") } } bench.report("Pathname#drive_number"){ MAX.times{ path1.drive_number } } bench.report("Pathname#unc?"){ MAX.times{ path1.unc? } } bench.report("Pathname#undecorate"){ MAX.times{ path1.undecorate } } bench.report("Pathname#undecorate!"){ MAX.times{ path1.undecorate! } } bench.report("Pathname#short_path"){ MAX.times{ path1.short_path } } bench.report("Pathname#long_path"){ MAX.times{ path1.long_path } } else bench.report("Pathname#realpath"){ MAX.times{ path4.realpath } } end end pathname2-1.8.2/benchmarks/bench_plus.rb0000644000004100000410000000171713706321500020220 0ustar www-datawww-data############################################################################## # Compare File.join vs. Pathname#+ # # This benchmark was inspired by a post by Thomas Sawyer. Note that # Pathname#+ will never be as fast as File.join, but this provides a # good base for further optimizations. # # Also keep in mind that File.join does no path normalization whatsoever, # e.g. File.join("foo", "/bar") behaves differently than Pathname.new("foo") # + Pathname.new("/bar"). This is true of both the pathname and pathname2 # packages. # # You can run this via the 'rake benchmark_plus' task. ############################################################################## require 'benchmark' require 'pathname2' MAX = 10000 s1 = "a/b/c" s2 = "d/e/f" path1 = Pathname.new(s1) path2 = Pathname.new(s2) Benchmark.bm(10) do |bench| bench.report("File.join"){ MAX.times{ File.join(s1, s2) } } bench.report("Pathname#+"){ MAX.times{ path1 + path2 } } end