Sha256: 20c3e60e2ea57a438f16af37e2cd73c6e50a5369d7b6b65033e2e1e889716d45

Contents?: true

Size: 1.61 KB

Versions: 10

Compression:

Stored size: 1.61 KB

Contents

########################################################################
# test_clean_bang.rb
#
# Test suite for the Pathname#clean! method.
########################################################################
require 'test-unit'
require 'pathname2'

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

  test "clean basic functionality" do
    assert_respond_to(@path, :clean!)
    assert_nothing_raised{ @path.clean! }
    assert_kind_of(Pathname, @path.clean!)
  end

  test "clean returns expected results for unclean paths" do
    assert_equal("C:\\a\\c", Pathname.new("C:\\a\\.\\b\\..\\c").clean!)
    assert_equal("C:\\a", Pathname.new("C:\\.\\a").clean!)
    assert_equal("C:\\a\\b", Pathname.new("C:\\a\\.\\b").clean!)
    assert_equal("C:\\b", Pathname.new("C:\\a\\..\\b").clean!)
    assert_equal("C:\\a", Pathname.new("C:\\a\\.").clean!)
    assert_equal("C:\\d", Pathname.new("C:\\..\\..\\..\\d").clean!)
  end

  test "clean returns already clean paths unmodified" do
    assert_equal("C:\\", Pathname.new("C:\\").clean!)
    assert_equal("C:\\a", Pathname.new("C:\\a").clean!)
    assert_equal("C:\\a\\", Pathname.new("C:\\a\\").clean!)
    assert_equal("\\\\foo\\bar", Pathname.new("\\\\foo\\bar").clean!)
    assert_equal("a", Pathname.new("a").clean!)
  end

  test "clean returns a slash for . and .." do
    assert_equal("\\", Pathname.new(".").clean!)
    assert_equal("\\", Pathname.new("..").clean!)
  end

  test "clean! modifies receiver" do
    @path.clean!
    assert_equal("C:\\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_clean_bang.rb
pathname2-1.8.3 test/windows/test_clean_bang.rb
pathname2-1.8.2 test/windows/test_clean_bang.rb
pathname2-1.8.1 test/windows/test_clean_bang.rb
pathname2-1.8.0 test/windows/test_clean_bang.rb
pathname2-1.7.4 test/windows/test_clean_bang.rb
pathname2-1.7.3 test/windows/test_clean_bang.rb
pathname2-1.7.2 test/windows/test_clean_bang.rb
pathname2-1.7.1 test/windows/test_clean_bang.rb
pathname2-1.7.0 test/windows/test_clean_bang.rb