|
4 | 4 | "bytes"
|
5 | 5 | "encoding/base64"
|
6 | 6 | . "reflect"
|
| 7 | + "slices" |
7 | 8 | "sort"
|
8 | 9 | "strings"
|
9 | 10 | "testing"
|
@@ -804,6 +805,36 @@ func TestClearMap(t *testing.T) {
|
804 | 805 | }
|
805 | 806 | }
|
806 | 807 |
|
| 808 | +func TestCopyArrayToSlice(t *testing.T) { |
| 809 | + // Test copying array <=64 bits and >64bits |
| 810 | + // See issue #4554 |
| 811 | + a1 := [1]int64{1} |
| 812 | + s1 := make([]int64, 1) |
| 813 | + a2 := [2]int64{1, 2} |
| 814 | + s2 := make([]int64, 2) |
| 815 | + a8 := [8]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} |
| 816 | + s8 := make([]byte, 8) |
| 817 | + a9 := [9]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09} |
| 818 | + s9 := make([]byte, 9) |
| 819 | + |
| 820 | + Copy(ValueOf(s1), ValueOf(a1)) |
| 821 | + if !slices.Equal(s1, a1[:]) { |
| 822 | + t.Errorf("copied slice %x does not match input array %x", s1, a1[:]) |
| 823 | + } |
| 824 | + Copy(ValueOf(s2), ValueOf(a2)) |
| 825 | + if !slices.Equal(s2, a2[:]) { |
| 826 | + t.Errorf("copied slice %x does not match input array %x", s2, a2[:]) |
| 827 | + } |
| 828 | + Copy(ValueOf(s8), ValueOf(a8)) |
| 829 | + if !bytes.Equal(s8, a8[:]) { |
| 830 | + t.Errorf("copied slice %x does not match input array %x", s8, a8[:]) |
| 831 | + } |
| 832 | + Copy(ValueOf(s9), ValueOf(a9)) |
| 833 | + if !bytes.Equal(s9, a9[:]) { |
| 834 | + t.Errorf("copied slice %x does not match input array %x", s9, a9[:]) |
| 835 | + } |
| 836 | +} |
| 837 | + |
807 | 838 | func TestIssue4040(t *testing.T) {
|
808 | 839 | var value interface{} = uint16(0)
|
809 | 840 |
|
|
0 commit comments