cuelang.org/go@v0.10.1/internal/core/runtime/resolve_test.go (about) 1 // Copyright 2020 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package runtime 16 17 import ( 18 "testing" 19 20 "cuelang.org/go/cue/ast" 21 "cuelang.org/go/cue/build" 22 ) 23 24 // TestPartiallyResolved tests that the resolve will detect the usage of 25 // imports that are referenced by previously resolved nodes. 26 func TestPartiallyResolved(t *testing.T) { 27 const importPath = "mod.test/foo" 28 spec1 := &ast.ImportSpec{ 29 Path: ast.NewString(importPath), 30 } 31 spec2 := &ast.ImportSpec{ 32 Name: ast.NewIdent("bar"), 33 Path: ast.NewString(importPath), 34 } 35 36 f := &ast.File{ 37 Decls: []ast.Decl{ 38 &ast.ImportDecl{Specs: []*ast.ImportSpec{spec1, spec2}}, 39 &ast.Field{ 40 Label: ast.NewIdent("X"), 41 Value: &ast.Ident{Name: "foo", Node: spec1}, 42 }, 43 &ast.Alias{ 44 Ident: ast.NewIdent("Y"), 45 Expr: &ast.Ident{Name: "bar", Node: spec2}, 46 }, 47 }, 48 Imports: []*ast.ImportSpec{spec1, spec2}, 49 } 50 51 err := resolveFile(nil, f, &build.Instance{ 52 Imports: []*build.Instance{{ 53 ImportPath: importPath, 54 PkgName: "foo", 55 }}, 56 }, map[string]ast.Node{}) 57 58 if err != nil { 59 t.Errorf("exected no error, found %v", err) 60 } 61 }