github.com/ipld/go-ipld-prime@v0.21.0/node/tests/util.go (about) 1 package tests 2 3 import ( 4 "strings" 5 6 "github.com/ipld/go-ipld-prime/codec/json" 7 "github.com/ipld/go-ipld-prime/datamodel" 8 "github.com/ipld/go-ipld-prime/must" 9 "github.com/ipld/go-ipld-prime/traversal/selector" 10 ) 11 12 func mustNodeFromJsonString(np datamodel.NodePrototype, str string) datamodel.Node { 13 nb := np.NewBuilder() 14 must.NotError(json.Decode(nb, strings.NewReader(str))) 15 return nb.Build() 16 } 17 18 func mustSelectorFromJsonString(np datamodel.NodePrototype, str string) selector.Selector { 19 // Needing an 'ns' parameter here is sort of off-topic, to be honest. 20 // Someday the selector package will probably contain codegen'd nodes of its own schema, and we'll use those unconditionally. 21 // For now... we'll just use whatever node you're already testing, because it oughta work 22 // (and because it avoids hardcoding any other implementation that might cause import cycle funtimes.). 23 seldefn := mustNodeFromJsonString(np, str) 24 sel, err := selector.ParseSelector(seldefn) 25 must.NotError(err) 26 return sel 27 }