summaryrefslogtreecommitdiffstats
path: root/slice_test.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-08-18 18:01:24 -0400
committerSam Anthony <sam@samanthony.xyz>2024-08-18 18:01:24 -0400
commit9432f7d1c143c426ab011770431827b9c055b7e9 (patch)
tree3864253061280a294e95b32461ca057f4a123a57 /slice_test.go
parent5accf50ec467aa14e9dcf7541c2ca0c8ab1a497b (diff)
downloadshare-9432f7d1c143c426ab011770431827b9c055b7e9.zip
test ConstSlice
Diffstat (limited to 'slice_test.go')
-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))
+ }
+}