github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/jsonschemax/pointer_test.go (about) 1 package jsonschemax 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestJSONPointerToDotNotation(t *testing.T) { 11 for k, tc := range [][]string{ 12 {"#/foo/bar/baz", "foo.bar.baz"}, 13 {"#/baz", "baz"}, 14 {"#/properties/ory.sh~1kratos/type", "properties.ory\\.sh/kratos.type"}, 15 } { 16 t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) { 17 path, err := JSONPointerToDotNotation(tc[0]) 18 require.NoError(t, err) 19 require.Equal(t, tc[1], path) 20 }) 21 } 22 23 _, err := JSONPointerToDotNotation("http://foo/#/bar") 24 require.Error(t, err, "should fail because remote pointers are not supported") 25 26 _, err = JSONPointerToDotNotation("http://foo/#/bar%zz") 27 require.Error(t, err, "should fail because %3b is not a valid escaped path.") 28 }