summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slice_test.go32
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))
+ }
+}