this repo has no description
0
fork

Configure Feed

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

cue: add test case for Value.ReferencePath at top level

Currently Value.ReferencePath does not work correctly
when the value is a top level expression in a file.
We add a test case for this, to be fixed in a subsequent CL.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I9238a168860c77d167cb9b018ff8fee307698072
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1232507
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

+30 -2
+30 -2
cue/types_test.go
··· 3419 3419 func TestReferencePath(t *testing.T) { 3420 3420 testCases := []struct { 3421 3421 input string 3422 + path string 3422 3423 want string 3423 3424 wantImportPath string 3424 3425 alt string 3425 3426 }{{ 3426 3427 input: "v: w: x: _|_", 3428 + path: "v.w.x", 3427 3429 want: "", 3428 3430 }, { 3429 3431 input: "v: w: x: 2", 3432 + path: "v.w.x", 3430 3433 want: "", 3431 3434 }, { 3432 3435 input: "v: w: x: a, a: 1", 3436 + path: "v.w.x", 3433 3437 want: "a", 3434 3438 }, { 3435 3439 input: "v: w: x: a.b.c, a: b: c: 1", 3440 + path: "v.w.x", 3436 3441 want: "a.b.c", 3437 3442 }, { 3438 3443 input: "if true { v: w: x: a, a: 1 }", 3444 + path: "v.w.x", 3439 3445 want: "a", 3440 3446 }, { 3441 3447 input: "v: w: x: w.a.b.c, v: w: a: b: c: 1", 3448 + path: "v.w.x", 3442 3449 want: "v.w.a.b.c", 3443 3450 }, { 3444 3451 input: `v: w: x: w.a.b.c, v: w: a: b: c: 1, #D: 3, opt?: 3, "v\(#D)": 3, X: {a: 3}, X`, 3452 + path: "v.w.x", 3445 3453 want: "v.w.a.b.c", 3446 3454 }, { 3447 3455 input: ` 3448 3456 v: w: x: w.a[bb]["c"] 3449 3457 v: w: a: b: c: 1 3450 3458 bb: "b"`, 3459 + path: "v.w.x", 3451 3460 want: "v.w.a.b.c", 3452 3461 }, { 3453 3462 input: ` 3454 3463 X="\(y)": 1 3455 3464 v: w: x: X // TODO: Move up for crash 3456 3465 y: "foo"`, 3466 + path: "v.w.x", 3457 3467 want: "foo", 3458 3468 }, { 3459 3469 input: ` 3460 3470 v: w: _ 3461 3471 v: [X=string]: x: a[X] 3462 3472 a: w: 1`, 3473 + path: "v.w.x", 3463 3474 want: "a.w", 3464 3475 }, { 3465 3476 input: `v: { ··· 3469 3480 } 3470 3481 }, 3471 3482 src: ["x", "y"]`, 3483 + path: "v.w.x", 3472 3484 want: "v.w.tx", 3473 3485 }, { 3474 3486 input: ` ··· 3477 3489 for i in [] { 3478 3490 } 3479 3491 `, 3492 + path: "v.w.x", 3480 3493 want: "a", 3481 3494 }, { 3482 3495 input: ` 3483 3496 v: w: close({x: a}) 3484 3497 a: 1 3485 3498 `, 3499 + path: "v.w.x", 3486 3500 want: "a", 3487 3501 }, { 3488 3502 input: ` ··· 3492 3506 `, 3493 3507 want: "Pi", 3494 3508 wantImportPath: "math", 3509 + path: "v.w.x", 3495 3510 alt: "3.14159265358979323846264338327950288419716939937510582097494459", 3496 - }} 3511 + }, { 3512 + input: ` 3513 + import "time" 3514 + 3515 + time.RFC3339 3516 + `, 3517 + path: "", 3518 + want: "", 3519 + // TODO this should work 3520 + //want: "RFC3339", 3521 + //wantImportPath: "time", 3522 + alt: `"2006-01-02T15:04:05Z07:00"`, 3523 + }, 3524 + } 3497 3525 for _, tc := range testCases { 3498 3526 cuetdtest.FullMatrix.Run(t, "", func(t *testing.T, m *cuetdtest.M) { 3499 3527 ctx := m.CueContext() 3500 3528 3501 3529 val := ctx.CompileString(tc.input, cue.Filename("in")) 3502 - v := val.Lookup("v", "w", "x") 3530 + v := val.LookupPath(cue.ParsePath(tc.path)) 3503 3531 3504 3532 root, path := v.ReferencePath() 3505 3533 if got := path.String(); got != tc.want {