-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpath_test.go
36 lines (25 loc) · 1.14 KB
/
path_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
package automerge_test
import (
"testing"
"github.com/automerge/automerge-go"
"github.com/stretchr/testify/require"
)
func TestPath_Errors(t *testing.T) {
doc := automerge.New()
require.PanicsWithError(t, "automerge: invalid path segment, expected string or int, got: bool(true)", func() {
doc.Path(true)
})
_, err := doc.Path(0).Get()
require.ErrorContains(t, err, "&automerge.Path{0}: tried to read index 0 of non-list &automerge.Map{}")
err = doc.Path(0).Set(1)
require.ErrorContains(t, err, "&automerge.Path{}: tried to write index 0 of non-list &automerge.Map{}")
err = doc.Path("list", 1).Set(1)
require.ErrorContains(t, err, `&automerge.Path{"list", 1}: tried to write index 1 beyond end of list length 0`)
require.NoError(t, doc.Path("x").Set(true))
_, err = doc.Path("x", "y").Get()
require.ErrorContains(t, err, `&automerge.Path{"x", "y"}: tried to read property "y" of non-map true`)
err = doc.Path("x", "y").Set(1)
require.ErrorContains(t, err, `&automerge.Path{"x"}: tried to write property "y" of non-map true`)
err = doc.Path().Set(1)
require.ErrorContains(t, err, `&automerge.Path{}: tried to overwrite root of document`)
}