File: test_aref.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 (37 lines) | stat: -rw-r--r-- 1,124 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
########################################################################
# test_aref.rb
#
# Test suite for the Pathname#[] method.
########################################################################
require 'test-unit'
require 'pathname2'

class TC_Pathname_Aref < Test::Unit::TestCase
  def setup
    @path = Pathname.new("C:/Program Files/Windows NT/Accessories")
  end

  test "[] with index works as expected" do
    assert_equal("C:", @path[0])
    assert_equal("Program Files", @path[1])
    assert_equal("Accessories", @path[-1])
    assert_nil(@path[10])
  end

  test "[] with range argument works as expected" do
    assert_equal("C:\\Program Files", @path[0..1])
    assert_equal("C:\\Program Files\\Windows NT", @path[0..2])
    assert_equal("Program Files\\Windows NT", @path[1..2])
    #assert_equal(@path, @path[0..-1]) # TODO: Spews tons of warnings
  end

  test "[] with index and length works as expected" do
    assert_equal("C:", @path[0,1])
    assert_equal("C:\\Program Files", @path[0,2])
    assert_equal("Program Files\\Windows NT", @path[1,2])
  end

  def teardown
    @path = nil
  end
end