-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpointer_test.go
42 lines (37 loc) · 958 Bytes
/
pointer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build goexperiment.rangefunc
package jsontext
import (
"iter"
"slices"
"testing"
)
func TestPointerTokens(t *testing.T) {
// TODO(https://go.dev/issue/61899): Use slices.Collect.
collect := func(seq iter.Seq[string]) (x []string) {
for v := range seq {
x = append(x, v)
}
return x
}
tests := []struct {
in Pointer
want []string
}{
{in: "", want: nil},
{in: "a", want: []string{"a"}},
{in: "~", want: []string{"~"}},
{in: "/a", want: []string{"a"}},
{in: "/foo/bar", want: []string{"foo", "bar"}},
{in: "///", want: []string{"", "", ""}},
{in: "/~0~1", want: []string{"~/"}},
}
for _, tt := range tests {
got := collect(tt.in.Tokens())
if !slices.Equal(got, tt.want) {
t.Errorf("Pointer(%q).Tokens = %q, want %q", tt.in, got, tt.want)
}
}
}