blob: 02a098c923e6916378e88cadb45c4779d72e20a4 [file] [log] [blame]
Marcel van Lohuizen0d12c332020-06-10 12:36:58 +02001// 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
Marcel van Lohuizen311f5bc2020-07-07 15:58:16 +020015package export_test
Marcel van Lohuizen0d12c332020-06-10 12:36:58 +020016
17import (
18 "fmt"
19 "testing"
20
Marcel van Lohuizen845df052020-07-26 13:15:45 +020021 "cuelang.org/go/cue"
Marcel van Lohuizen0d12c332020-06-10 12:36:58 +020022 "cuelang.org/go/internal/core/adt"
23 "cuelang.org/go/internal/core/compile"
24 "cuelang.org/go/internal/core/eval"
Marcel van Lohuizen311f5bc2020-07-07 15:58:16 +020025 "cuelang.org/go/internal/core/export"
Marcel van Lohuizen0d12c332020-06-10 12:36:58 +020026 "cuelang.org/go/internal/cuetxtar"
27)
28
29func TestExtract(t *testing.T) {
30 test := cuetxtar.TxTarTest{
31 Root: "./testdata",
32 Name: "doc",
33 Update: *update,
34 }
35
Marcel van Lohuizen311f5bc2020-07-07 15:58:16 +020036 r := cue.NewRuntime()
Marcel van Lohuizen0d12c332020-06-10 12:36:58 +020037
38 test.Run(t, func(t *cuetxtar.Test) {
39 a := t.ValidInstances()
40
41 v, err := compile.Files(nil, r, a[0].Files...)
42 if err != nil {
43 t.Fatal(err)
44 }
45
46 ctx := eval.NewContext(r, v)
47 v.Finalize(ctx)
48
49 writeDocs(t, r, v, nil)
50 })
51}
52
53func writeDocs(t *cuetxtar.Test, r adt.Runtime, v *adt.Vertex, path []string) {
54 fmt.Fprintln(t, path)
Marcel van Lohuizen311f5bc2020-07-07 15:58:16 +020055 for _, c := range export.ExtractDoc(v) {
Marcel van Lohuizen0d12c332020-06-10 12:36:58 +020056 fmt.Fprintln(t, "-", c.Text())
57 }
58
59 for _, a := range v.Arcs {
60 writeDocs(t, r, a, append(path, a.Label.SelectorString(r)))
61 }
62}