File: test_drive_number.rb

package info (click to toggle)
ruby-pathname2 1.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 336 kB
  • sloc: ruby: 2,037; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,808 bytes parent folder | download | duplicates (4)
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
########################################################################
# 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