Marcel van Lohuizen | 0d12c33 | 2020-06-10 12:36:58 +0200 | [diff] [blame] | 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 | |
Marcel van Lohuizen | 311f5bc | 2020-07-07 15:58:16 +0200 | [diff] [blame] | 15 | package export_test |
Marcel van Lohuizen | 0d12c33 | 2020-06-10 12:36:58 +0200 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "testing" |
| 20 | |
Marcel van Lohuizen | 845df05 | 2020-07-26 13:15:45 +0200 | [diff] [blame] | 21 | "cuelang.org/go/cue" |
Marcel van Lohuizen | 0d12c33 | 2020-06-10 12:36:58 +0200 | [diff] [blame] | 22 | "cuelang.org/go/internal/core/adt" |
| 23 | "cuelang.org/go/internal/core/compile" |
| 24 | "cuelang.org/go/internal/core/eval" |
Marcel van Lohuizen | 311f5bc | 2020-07-07 15:58:16 +0200 | [diff] [blame] | 25 | "cuelang.org/go/internal/core/export" |
Marcel van Lohuizen | 0d12c33 | 2020-06-10 12:36:58 +0200 | [diff] [blame] | 26 | "cuelang.org/go/internal/cuetxtar" |
| 27 | ) |
| 28 | |
| 29 | func TestExtract(t *testing.T) { |
| 30 | test := cuetxtar.TxTarTest{ |
| 31 | Root: "./testdata", |
| 32 | Name: "doc", |
| 33 | Update: *update, |
| 34 | } |
| 35 | |
Marcel van Lohuizen | 311f5bc | 2020-07-07 15:58:16 +0200 | [diff] [blame] | 36 | r := cue.NewRuntime() |
Marcel van Lohuizen | 0d12c33 | 2020-06-10 12:36:58 +0200 | [diff] [blame] | 37 | |
| 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 | |
| 53 | func writeDocs(t *cuetxtar.Test, r adt.Runtime, v *adt.Vertex, path []string) { |
| 54 | fmt.Fprintln(t, path) |
Marcel van Lohuizen | 311f5bc | 2020-07-07 15:58:16 +0200 | [diff] [blame] | 55 | for _, c := range export.ExtractDoc(v) { |
Marcel van Lohuizen | 0d12c33 | 2020-06-10 12:36:58 +0200 | [diff] [blame] | 56 | 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 | } |