Skip to content

Commit 078020b

Browse files
NoamTDmvdan
authored andcommitted
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 <[email protected]> Change-Id: I464e0d730fbdfaf5afc8bebd547b7f1590f2dd93 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194862 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 27a0190 commit 078020b

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

encoding/gocode/gocodec/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

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
1616
// CUE constraints.
1717
//
1818
// CUE constraints can be used to validate Go types as well as fill out

encoding/gocode/gocodec/codec_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,20 @@ func TestComplete(t *testing.T) {
208208
}}
209209
for _, tc := range testCases {
210210
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)
213213

214214
v, err := codec.ExtractType(tc.value)
215215
if err != nil {
216216
t.Fatal(err)
217217
}
218218

219219
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 {
222222
t.Fatal(err)
223223
}
224-
v = v.Unify(inst.Value())
224+
v = v.Unify(c)
225225
}
226226

227227
err = codec.Complete(v, tc.value)
@@ -243,17 +243,17 @@ func TestEncode(t *testing.T) {
243243
dst: new(int),
244244
want: 4,
245245
}}
246-
r := &cue.Runtime{}
247-
c := New(r, nil)
246+
ctx := cuecontext.New()
247+
c := New(ctx, nil)
248248

249249
for _, tc := range testCases {
250250
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 {
253253
t.Fatal(err)
254254
}
255255

256-
err = c.Encode(inst.Value(), tc.dst)
256+
err := c.Encode(in, tc.dst)
257257
if err != nil {
258258
t.Fatal(err)
259259
}
@@ -306,7 +306,7 @@ func TestDecode(t *testing.T) {
306306
}
307307
}`,
308308
}}
309-
c := New(&cue.Runtime{}, nil)
309+
c := New(cuecontext.New(), nil)
310310

311311
for _, tc := range testCases {
312312
t.Run("", func(t *testing.T) {
@@ -336,21 +336,20 @@ func TestX(t *testing.T) {
336336
wantErr = fail
337337
)
338338

339-
r := &cue.Runtime{}
340-
codec := New(r, nil)
339+
ctx := cuecontext.New()
340+
codec := New(ctx, nil)
341341

342342
v, err := codec.ExtractType(value)
343343
if err != nil {
344344
t.Fatal(err)
345345
}
346346

347347
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 {
350350
t.Fatal(err)
351351
}
352-
w := inst.Value()
353-
v = v.Unify(w)
352+
v = v.Unify(c)
354353
}
355354

356355
err = codec.Validate(v, value)

0 commit comments

Comments
 (0)