File: test_pstrip.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 (42 lines) | stat: -rw-r--r-- 1,321 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
########################################################################
# 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