File: test_is_absolute.rb

package info (click to toggle)
ruby-pathname2 1.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 340 kB
  • sloc: ruby: 2,033; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,312 bytes parent folder | download | duplicates (3)
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
########################################################################
# 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