]>
Commit | Line | Data |
---|---|---|
1 | // Licensed to the Apache Software Foundation (ASF) under one | |
2 | // or more contributor license agreements. See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership. The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, software | |
12 | // distributed under the License is distributed on an "AS IS" BASIS, | |
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | // See the License for the specific language governing permissions and | |
15 | // limitations under the License. | |
16 | ||
17 | package array | |
18 | ||
19 | import ( | |
20 | "testing" | |
21 | ||
22 | "github.com/apache/arrow/go/v6/arrow" | |
23 | "github.com/apache/arrow/go/v6/arrow/memory" | |
24 | "github.com/stretchr/testify/assert" | |
25 | ) | |
26 | ||
27 | func TestDataReset(t *testing.T) { | |
28 | var ( | |
29 | buffers1 = make([]*memory.Buffer, 0, 3) | |
30 | buffers2 = make([]*memory.Buffer, 0, 3) | |
31 | ) | |
32 | for i := 0; i < cap(buffers1); i++ { | |
33 | buffers1 = append(buffers1, memory.NewBufferBytes([]byte("some-bytes1"))) | |
34 | buffers2 = append(buffers2, memory.NewBufferBytes([]byte("some-bytes2"))) | |
35 | } | |
36 | ||
37 | data := NewData(&arrow.StringType{}, 10, buffers1, nil, 0, 0) | |
38 | data.Reset(&arrow.Int64Type{}, 5, buffers2, nil, 1, 2) | |
39 | ||
40 | for i := 0; i < 2; i++ { | |
41 | assert.Equal(t, buffers2, data.Buffers()) | |
42 | assert.Equal(t, &arrow.Int64Type{}, data.DataType()) | |
43 | assert.Equal(t, 1, data.NullN()) | |
44 | assert.Equal(t, 2, data.Offset()) | |
45 | assert.Equal(t, 5, data.Len()) | |
46 | ||
47 | // Make sure it works when resetting the data with its own buffers (new buffers are retained | |
48 | // before old ones are released.) | |
49 | data.Reset(&arrow.Int64Type{}, 5, data.Buffers(), nil, 1, 2) | |
50 | } | |
51 | } |