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
|
describe "Array#[]=" do
it "sets the value of the element at index" do
a = [1, 2, 3, 4]
a[2] = 5
a[-1] = 6
a[5] = 3
a.should == [1, 2, 5, 6, nil, 3]
a = []
a[4] = "e"
a.should == [nil, nil, nil, nil, "e"]
a[3] = "d"
a.should == [nil, nil, nil, "d", "e"]
a[0] = "a"
a.should == ["a", nil, nil, "d", "e"]
a[-3] = "C"
a.should == ["a", nil, "C", "d", "e"]
a[-1] = "E"
a.should == ["a", nil, "C", "d", "E"]
a[-5] = "A"
a.should == ["A", nil, "C", "d", "E"]
a[5] = "f"
a.should == ["A", nil, "C", "d", "E", "f"]
a[1] = []
a.should == ["A", [], "C", "d", "E", "f"]
a[-1] = nil
a.should == ["A", [], "C", "d", "E", nil]
end
it "removes the section defined by start, length when set to nil" do
a = ['a', 'b', 'c', 'd', 'e']
a[1, 3] = nil
a.should == ["a", "e"]
end
it "sets the section defined by start, length to other" do
a = [1, 2, 3, 4, 5, 6]
a[0, 1] = 2
a[3, 2] = ['a', 'b', 'c', 'd']
a.should == [2, 2, 3, "a", "b", "c", "d", 6]
end
it "removes the section defined by range when set to nil" do
a = [1, 2, 3, 4, 5]
a[0..1] = nil
a.should == [3, 4, 5]
end
it "sets the section defined by range to other" do
a = [6, 5, 4, 3, 2, 1]
a[1...2] = 9
a[3..6] = [6, 6, 6]
a.should == [6, 9, 4, 6, 6, 6]
end
end
|