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
|
########################################################################
# 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
|