github.com/solo-io/cue@v0.4.7/internal/core/export/extract_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 export_test 16 17 import ( 18 "fmt" 19 "testing" 20 21 "github.com/solo-io/cue/internal/core/adt" 22 "github.com/solo-io/cue/internal/core/compile" 23 "github.com/solo-io/cue/internal/core/eval" 24 "github.com/solo-io/cue/internal/core/export" 25 "github.com/solo-io/cue/internal/core/runtime" 26 "github.com/solo-io/cue/internal/cuetest" 27 "github.com/solo-io/cue/internal/cuetxtar" 28 ) 29 30 func TestExtract(t *testing.T) { 31 test := cuetxtar.TxTarTest{ 32 Root: "./testdata", 33 Name: "doc", 34 Update: cuetest.UpdateGoldenFiles, 35 } 36 37 r := runtime.New() 38 39 test.Run(t, func(t *cuetxtar.Test) { 40 a := t.ValidInstances() 41 42 v, err := compile.Files(nil, r, "", a[0].Files...) 43 if err != nil { 44 t.Fatal(err) 45 } 46 47 ctx := eval.NewContext(r, v) 48 v.Finalize(ctx) 49 50 writeDocs(t, r, v, nil) 51 }) 52 } 53 54 func writeDocs(t *cuetxtar.Test, r adt.Runtime, v *adt.Vertex, path []string) { 55 fmt.Fprintln(t, path) 56 for _, c := range export.ExtractDoc(v) { 57 fmt.Fprintln(t, "-", c.Text()) 58 } 59 60 for _, a := range v.Arcs { 61 writeDocs(t, r, a, append(path, a.Label.SelectorString(r))) 62 } 63 }