this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

encoding/gocode/gocodec: remove cue.Runtime usages

This removes most usages of cue.Runtime in gocodec tests, except for a
smoke test that ensures the deprecated cue.Runtime still works with
the API.

Also, the package doc is fixed to reference the correct package name.

Updates #2480.

Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Change-Id: I464e0d730fbdfaf5afc8bebd547b7f1590f2dd93
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194862
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

authored by

Noam Dolovich and committed by
Daniel Martí
078020b3 27a01900

+17 -18
+1 -1
encoding/gocode/gocodec/codec.go
··· 12 12 // See the License for the specific language governing permissions and 13 13 // limitations under the License. 14 14 15 - // Package codec converts Go to and from CUE and validates Go values based on 15 + // Package gocodec converts Go to and from CUE and validates Go values based on 16 16 // CUE constraints. 17 17 // 18 18 // CUE constraints can be used to validate Go types as well as fill out
+16 -17
encoding/gocode/gocodec/codec_test.go
··· 208 208 }} 209 209 for _, tc := range testCases { 210 210 t.Run(tc.name, func(t *testing.T) { 211 - r := &cue.Runtime{} 212 - codec := New(r, nil) 211 + ctx := cuecontext.New() 212 + codec := New(ctx, nil) 213 213 214 214 v, err := codec.ExtractType(tc.value) 215 215 if err != nil { ··· 217 217 } 218 218 219 219 if tc.constraints != "" { 220 - inst, err := r.Compile(tc.name, tc.constraints) 221 - if err != nil { 220 + c := ctx.CompileString(tc.constraints, cue.Filename(tc.name)) 221 + if err := c.Err(); err != nil { 222 222 t.Fatal(err) 223 223 } 224 - v = v.Unify(inst.Value()) 224 + v = v.Unify(c) 225 225 } 226 226 227 227 err = codec.Complete(v, tc.value) ··· 243 243 dst: new(int), 244 244 want: 4, 245 245 }} 246 - r := &cue.Runtime{} 247 - c := New(r, nil) 246 + ctx := cuecontext.New() 247 + c := New(ctx, nil) 248 248 249 249 for _, tc := range testCases { 250 250 t.Run("", func(t *testing.T) { 251 - inst, err := r.Compile("test", tc.in) 252 - if err != nil { 251 + in := ctx.CompileString(tc.in, cue.Filename("test")) 252 + if err := in.Err(); err != nil { 253 253 t.Fatal(err) 254 254 } 255 255 256 - err = c.Encode(inst.Value(), tc.dst) 256 + err := c.Encode(in, tc.dst) 257 257 if err != nil { 258 258 t.Fatal(err) 259 259 } ··· 306 306 } 307 307 }`, 308 308 }} 309 - c := New(&cue.Runtime{}, nil) 309 + c := New(cuecontext.New(), nil) 310 310 311 311 for _, tc := range testCases { 312 312 t.Run("", func(t *testing.T) { ··· 336 336 wantErr = fail 337 337 ) 338 338 339 - r := &cue.Runtime{} 340 - codec := New(r, nil) 339 + ctx := cuecontext.New() 340 + codec := New(ctx, nil) 341 341 342 342 v, err := codec.ExtractType(value) 343 343 if err != nil { ··· 345 345 } 346 346 347 347 if constraints != "" { 348 - inst, err := r.Compile(name, constraints) 349 - if err != nil { 348 + c := ctx.CompileString(constraints, cue.Filename(name)) 349 + if err := c.Err(); err != nil { 350 350 t.Fatal(err) 351 351 } 352 - w := inst.Value() 353 - v = v.Unify(w) 352 + v = v.Unify(c) 354 353 } 355 354 356 355 err = codec.Validate(v, value)