diff --git a/src/OffsetArrays.jl b/src/OffsetArrays.jl index 582661dd..f844b8f6 100644 --- a/src/OffsetArrays.jl +++ b/src/OffsetArrays.jl @@ -367,7 +367,9 @@ Base.show(io::IO, ::MIME"text/plain", r::OffsetRange) = show(io, r) Base.resize!(A::OffsetVector, nl::Integer) = (resize!(A.parent, nl); A) Base.push!(A::OffsetVector, x...) = (push!(A.parent, x...); A) +Base.pushfirst!(A::OffsetVector, x...) = (pushfirst!(A.parent, x...); A) Base.pop!(A::OffsetVector) = pop!(A.parent) +Base.popfirst!(A::OffsetVector) = popfirst!(A.parent) Base.append!(A::OffsetVector, items) = (append!(A.parent, items); A) Base.empty!(A::OffsetVector) = (empty!(A.parent); A) diff --git a/test/runtests.jl b/test/runtests.jl index 91571549..f2804391 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1440,14 +1440,37 @@ end @test push!(o, 2, 3) === o @test axes(o, 1) == 0:2 @test o[end-1:end] == [2, 3] + + # pushfirst! + o = OffsetVector(Int[], -1) + @test pushfirst!(o) === o + @test axes(o, 1) == 0:-1 + @test pushfirst!(o, 1) === o + @test axes(o, 1) == 0:0 + @test o[end] == 1 + @test pushfirst!(o, 2, 3) === o + @test axes(o, 1) == 0:2 + if VERSION >= v"1.5" + @test o[begin:begin+1] == [2, 3] + else + @test o[0:1] == [2, 3] + end + # pop! o = OffsetVector([1, 2, 3], -1) @test pop!(o) == 3 @test axes(o, 1) == 0:1 + + # popfirst! + o = OffsetVector([1, 2, 3], -1) + @test popfirst!(o) == 1 + @test axes(o, 1) == 0:1 + # append! o = OffsetVector([1, 2, 3], -1) append!(o, [4, 5]) @test axes(o, 1) == 0:4 + # empty! o = OffsetVector([1, 2, 3], -1) @test empty!(o) === o