...

Source file src/cuelang.org/go/internal/core/export/extract_test.go

Documentation: cuelang.org/go/internal/core/export

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

View as plain text