diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-08-18 18:01:24 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-08-18 18:01:24 -0400 |
| commit | 9432f7d1c143c426ab011770431827b9c055b7e9 (patch) | |
| tree | 3864253061280a294e95b32461ca057f4a123a57 | |
| parent | 5accf50ec467aa14e9dcf7541c2ca0c8ab1a497b (diff) | |
| download | share-9432f7d1c143c426ab011770431827b9c055b7e9.zip | |
test ConstSlice
| -rw-r--r-- | slice_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/slice_test.go b/slice_test.go new file mode 100644 index 0000000..f8a1d0b --- /dev/null +++ b/slice_test.go @@ -0,0 +1,32 @@ +package share_test + +import ( + "testing" + + "git.samanthony.xyz/share" +) + +func TestConstSlice(t *testing.T) { + orig := []string{"foo", "bar", "baz"} + shared := share.NewConstSlice(orig) + verifySame(shared, orig, t) + go func() { + defer shared.Close() + verifySame(shared, orig, t) + }() +} + +func verifySame[T comparable](cs share.ConstSlice[T], s []T, t *testing.T) { + i := 0 + for elem := range cs.Elems() { + if i < len(s) { + if elem != s[i] { + t.Errorf("ConstSlice[%d] = %v; expected %v", i, elem, s[i]) + } + } + i++ + } + if i != len(s) { + t.Errorf("ConstSlice.Elems() returned %d elements; expected %d", i, len(s)) + } +} |