internal/core/export: allow testing imports
Change-Id: I828cb4fdfc3adb7407d306cabfb93db0f370d09b
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6644
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/internal/core/export/export_test.go b/internal/core/export/export_test.go
index 77032b0..804122e 100644
--- a/internal/core/export/export_test.go
+++ b/internal/core/export/export_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package export
+package export_test
import (
"flag"
@@ -23,8 +23,10 @@
"cuelang.org/go/cue/format"
"cuelang.org/go/internal/core/compile"
"cuelang.org/go/internal/core/eval"
+ "cuelang.org/go/internal/core/export"
"cuelang.org/go/internal/core/runtime"
"cuelang.org/go/internal/cuetxtar"
+ "cuelang.org/go/internal/legacy/cue"
"github.com/rogpeppe/go-internal/txtar"
)
@@ -37,7 +39,7 @@
Update: *update,
}
- r := runtime.New()
+ r := cue.NewRuntime()
test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()
@@ -51,7 +53,7 @@
// TODO: do we need to evaluate v? In principle not necessary.
// v.Finalize(eval.NewContext(r, v))
- file, errs := Def(r, v)
+ file, errs := export.Def(r, v)
errors.Print(t, errs, nil)
_, _ = t.Write(formatNode(t.T, file))
})
@@ -126,7 +128,7 @@
}
v.Finalize(eval.NewContext(r, v))
- file, errs := Def(r, v)
+ file, errs := export.Def(r, v)
if errs != nil {
t.Fatal(errs)
}
diff --git a/internal/core/export/extract_test.go b/internal/core/export/extract_test.go
index 354dae7..2d5153d 100644
--- a/internal/core/export/extract_test.go
+++ b/internal/core/export/extract_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package export
+package export_test
import (
"fmt"
@@ -21,8 +21,9 @@
"cuelang.org/go/internal/core/adt"
"cuelang.org/go/internal/core/compile"
"cuelang.org/go/internal/core/eval"
- "cuelang.org/go/internal/core/runtime"
+ "cuelang.org/go/internal/core/export"
"cuelang.org/go/internal/cuetxtar"
+ "cuelang.org/go/internal/legacy/cue"
)
func TestExtract(t *testing.T) {
@@ -32,7 +33,7 @@
Update: *update,
}
- r := runtime.New()
+ r := cue.NewRuntime()
test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()
@@ -51,7 +52,7 @@
func writeDocs(t *cuetxtar.Test, r adt.Runtime, v *adt.Vertex, path []string) {
fmt.Fprintln(t, path)
- for _, c := range ExtractDoc(v) {
+ for _, c := range export.ExtractDoc(v) {
fmt.Fprintln(t, "-", c.Text())
}
diff --git a/internal/core/export/testdata/simplify.txtar b/internal/core/export/testdata/simplify.txtar
index 2ddd23b..3eaa42e 100644
--- a/internal/core/export/testdata/simplify.txtar
+++ b/internal/core/export/testdata/simplify.txtar
@@ -1,36 +1,45 @@
-- in.cue --
+import "strings"
x: [string]: int64
x: {
y: int
}
+s: strings.MinRunes(4) & strings.MaxRunes(7)
-- out/definition --
+import "strings"
+
x: {
{
[string]: int64
}
y: int
}
+s: strings.MinRunes(4) & strings.MaxRunes(7)
-- out/doc --
[]
[x]
[x y]
+[s]
-- out/value --
== Simplified
{
x: {
y: int64
}
+ s: strings.MinRunes(4) & strings.MaxRunes(7)
}
== Raw
{
x: {
y: >=-9223372036854775808 & <=9223372036854775807 & int
}
+ s: strings.MinRunes(4) & strings.MaxRunes(7)
}
== All
{
x: {
y: int64
}
+ s: strings.MinRunes(4) & strings.MaxRunes(7)
}
diff --git a/internal/core/export/value_test.go b/internal/core/export/value_test.go
index 2467c3d..ac506cd 100644
--- a/internal/core/export/value_test.go
+++ b/internal/core/export/value_test.go
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package export
+package export_test
import (
"fmt"
@@ -23,8 +23,10 @@
"cuelang.org/go/internal/core/adt"
"cuelang.org/go/internal/core/compile"
"cuelang.org/go/internal/core/eval"
+ "cuelang.org/go/internal/core/export"
"cuelang.org/go/internal/core/runtime"
"cuelang.org/go/internal/cuetxtar"
+ "cuelang.org/go/internal/legacy/cue"
"github.com/rogpeppe/go-internal/txtar"
)
@@ -40,7 +42,7 @@
Skip: exclude,
}
- r := runtime.New()
+ r := cue.NewRuntime()
test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()
@@ -57,9 +59,9 @@
name string
fn func(r adt.Runtime, v adt.Value) (ast.Expr, errors.Error)
}{
- {"Simplified", Simplified.Value},
- {"Raw", Raw.Value},
- {"All", All.Value},
+ {"Simplified", export.Simplified.Value},
+ {"Raw", export.Raw.Value},
+ {"All", export.All.Value},
} {
fmt.Fprintln(t, "==", tc.name)
x, errs := tc.fn(r, v)
@@ -76,10 +78,10 @@
in := `
-- in.cue --
-x: [string]: int64
-x: {
- y: int
-}
+import "strings"
+
+strings.MinRunes(4) & strings.MaxRunes(7)
+
`
archive := txtar.Parse([]byte(in))
@@ -94,7 +96,7 @@
ctx := eval.NewContext(r, v)
v.Finalize(ctx)
- x, errs := Value(r, v)
+ x, errs := export.Simplified.Value(r, v)
if errs != nil {
t.Fatal(errs)
}