2023-09-30 02:31:45 +01:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"tailscale.com/cmd/cloner/clonerex"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSliceContainer(t *testing.T) {
|
|
|
|
num := 5
|
|
|
|
examples := []struct {
|
|
|
|
name string
|
2023-09-30 18:09:56 +01:00
|
|
|
in *clonerex.SliceContainer
|
2023-09-30 02:31:45 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "nil",
|
|
|
|
in: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "zero",
|
2023-09-30 18:09:56 +01:00
|
|
|
in: &clonerex.SliceContainer{},
|
2023-09-30 02:31:45 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty",
|
2023-09-30 18:09:56 +01:00
|
|
|
in: &clonerex.SliceContainer{
|
2023-09-30 02:31:45 +01:00
|
|
|
Slice: []*int{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "nils",
|
2023-09-30 18:09:56 +01:00
|
|
|
in: &clonerex.SliceContainer{
|
2023-09-30 02:31:45 +01:00
|
|
|
Slice: []*int{nil, nil, nil, nil, nil},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one",
|
2023-09-30 18:09:56 +01:00
|
|
|
in: &clonerex.SliceContainer{
|
2023-09-30 02:31:45 +01:00
|
|
|
Slice: []*int{&num},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "several",
|
2023-09-30 18:09:56 +01:00
|
|
|
in: &clonerex.SliceContainer{
|
2023-09-30 02:31:45 +01:00
|
|
|
Slice: []*int{&num, &num, &num, &num, &num},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ex := range examples {
|
|
|
|
t.Run(ex.name, func(t *testing.T) {
|
|
|
|
out := ex.in.Clone()
|
|
|
|
if !reflect.DeepEqual(ex.in, out) {
|
|
|
|
t.Errorf("Clone() = %v, want %v", out, ex.in)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|