Skip to content

Commit

Permalink
ast/astutil: add test for resolving imports with major version suffix
Browse files Browse the repository at this point in the history
Currently astutil.Resolve does not understand major version
suffixes, leading to problems with round-tripping files
through astutil.Sanitize.

We a test for this to be fixed by a subsequent CL.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I89e49348cc357cc84ffb059facfa70e632bfdf4f
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207986
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
rogpeppe committed Jan 30, 2025
1 parent b684a52 commit 5ab4551
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cue/ast/astutil/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestResolve(t *testing.T) {
}

test.Run(t, func(t *cuetxtar.Test) {
a := t.Instance()
// Use RawInstances because we want to allow imports
// without actually providing any dependencies. In general,
// Resolve is used just after parsing anyway, so lower level
// is more appropriate.
a := t.RawInstances()[0]

for _, f := range a.Files {
if filepath.Ext(f.Filename) != ".cue" {
Expand Down
19 changes: 19 additions & 0 deletions cue/ast/astutil/testdata/resolve/import.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- in.cue --
import (
"foo.com/bar"
"foo.com/bar:baz"
"other.org/p@v1"
"other.org/p@v2:q"
)
refs: [
bar,
baz,
p,
q,
]
-- out/resolve/in --
7[refs]: Scope: 0[<nil>] Node: 0[]
8[bar]: Scope: 0[<nil>] Node: 2["foo.com/bar"]
9[baz]: Scope: 0[<nil>] Node: 3["foo.com/bar:baz"]
10[p]: Scope: 0[<nil>] Node: 0[]
11[q]: Scope: 0[<nil>] Node: 5["other.org/p@v2:q"]

0 comments on commit 5ab4551

Please sign in to comment.