mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
reflect: add SetLen()
This commit is contained in:
committed by
Damian Gryski
parent
e4ef6f85ac
commit
960a0b79bf
@@ -137,7 +137,7 @@ func TestSlice(t *testing.T) {
|
||||
s28ref := refs.Slice(2, 8)
|
||||
|
||||
if len(s28) != s28ref.Len() || cap(s28) != s28ref.Cap() {
|
||||
t.Errorf("len(s28)=%d s28ref.Len()=%d cap(s28)=%d s28ref.Cap()=%d\n", len(s28), s28ref.Len(), cap(s28), s28ref.Cap())
|
||||
t.Errorf("Slice: len(s28)=%d s28ref.Len()=%d cap(s28)=%d s28ref.Cap()=%d\n", len(s28), s28ref.Len(), cap(s28), s28ref.Cap())
|
||||
}
|
||||
|
||||
for i, got := range s28 {
|
||||
@@ -151,7 +151,7 @@ func TestSlice(t *testing.T) {
|
||||
s268ref := refs.Slice3(2, 6, 8)
|
||||
|
||||
if len(s268) != s268ref.Len() || cap(s268) != s268ref.Cap() {
|
||||
t.Errorf("len(s268)=%d s268ref.Len()=%d cap(s268)=%d s268ref.Cap()=%d\n", len(s268), s268ref.Len(), cap(s268), s268ref.Cap())
|
||||
t.Errorf("Slice3: len(s268)=%d s268ref.Len()=%d cap(s268)=%d s268ref.Cap()=%d\n", len(s268), s268ref.Len(), cap(s268), s268ref.Cap())
|
||||
}
|
||||
|
||||
for i, got := range s268 {
|
||||
@@ -161,6 +161,19 @@ func TestSlice(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// should be equivalent to s28 now, except for the capacity which doesn't change
|
||||
s268ref.SetLen(6)
|
||||
if len(s28) != s268ref.Len() || cap(s268) != s268ref.Cap() {
|
||||
t.Errorf("SetLen: len(s268)=%d s268ref.Len()=%d cap(s268)=%d s268ref.Cap()=%d\n", len(s28), s268ref.Len(), cap(s268), s268ref.Cap())
|
||||
}
|
||||
|
||||
for i, got := range s28 {
|
||||
want := int(s268ref.Index(i).Int())
|
||||
if got != want {
|
||||
t.Errorf("s28[%d]=%d, want %d", i, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
refs = MakeSlice(TypeOf(s), 5, 10)
|
||||
s = refs.Interface().([]int)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user