Sha256: 3d8c851cb8424c3345095001af0b632cca83f5cee353b8688e73f8894e42645e

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

########################################################################
# test_ascend.rb
#
# Test suite for the Pathname#ascend method.
########################################################################
require 'pathname2'
require 'test-unit'

class TC_Pathname_Ascend < Test::Unit::TestCase
  def setup
    @path = Pathname.new("C:\\foo\\bar\\baz")
  end

  test "ascend basic functionality" do
    assert_respond_to(@path, :ascend)
    assert_nothing_raised{ @path.ascend{} }
  end

  test "ascend works as expected on a standard absolute path" do
    array = []
    @path.ascend{ |e| array << e }
    assert_equal('C:\foo\bar\baz', array[0])
    assert_equal('C:\foo\bar', array[1])
    assert_equal('C:\foo', array[2])
    assert_equal('C:', array[3])
  end

  test "ascend works as expected on a UNC path" do
    array = []
    Pathname.new('//foo/bar/baz').ascend{ |e| array << e }
    assert_equal("\\\\foo\\bar\\baz", array[0])
    assert_equal("\\\\foo\\bar", array[1])
  end

  test "ascend works as expected on a relative path" do
    array = []
    Pathname.new('foo/bar/baz').ascend{ |e| array << e }
    assert_equal('foo\bar\baz', array[0])
    assert_equal('foo\bar', array[1])
    assert_equal('foo', array[2])
  end

  test "ascend does not modify the receiver" do
    @path.ascend{}
    assert_equal('C:\foo\bar\baz', @path)
  end

  def teardown
    @path = nil
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pathname2-1.8.4 test/windows/test_ascend.rb
pathname2-1.8.3 test/windows/test_ascend.rb
pathname2-1.8.2 test/windows/test_ascend.rb
pathname2-1.8.1 test/windows/test_ascend.rb
pathname2-1.8.0 test/windows/test_ascend.rb
pathname2-1.7.4 test/windows/test_ascend.rb
pathname2-1.7.3 test/windows/test_ascend.rb
pathname2-1.7.2 test/windows/test_ascend.rb
pathname2-1.7.1 test/windows/test_ascend.rb
pathname2-1.7.0 test/windows/test_ascend.rb