1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
########################################################################
# 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
|