Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/export: allow testing imports
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Jul 23, 2020
1 parent 711bbb1 commit 311f5bc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
10 changes: 6 additions & 4 deletions internal/core/export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,8 +23,10 @@ import (
"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"
)

Expand All @@ -37,7 +39,7 @@ func TestDefinition(t *testing.T) {
Update: *update,
}

r := runtime.New()
r := cue.NewRuntime()

test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()
Expand All @@ -51,7 +53,7 @@ func TestDefinition(t *testing.T) {
// 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))
})
Expand Down Expand Up @@ -126,7 +128,7 @@ d2: C="foo\(bar)": {
}
v.Finalize(eval.NewContext(r, v))

file, errs := Def(r, v)
file, errs := export.Def(r, v)
if errs != nil {
t.Fatal(errs)
}
Expand Down
9 changes: 5 additions & 4 deletions internal/core/export/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,8 +21,9 @@ import (
"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) {
Expand All @@ -32,7 +33,7 @@ func TestExtract(t *testing.T) {
Update: *update,
}

r := runtime.New()
r := cue.NewRuntime()

test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()
Expand All @@ -51,7 +52,7 @@ func TestExtract(t *testing.T) {

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())
}

Expand Down
9 changes: 9 additions & 0 deletions internal/core/export/testdata/simplify.txtar
Original file line number Diff line number Diff line change
@@ -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)
}
22 changes: 12 additions & 10 deletions internal/core/export/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,8 +23,10 @@ import (
"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"
)

Expand All @@ -40,7 +42,7 @@ func TestValue(t *testing.T) {
Skip: exclude,
}

r := runtime.New()
r := cue.NewRuntime()

test.Run(t, func(t *cuetxtar.Test) {
a := t.ValidInstances()
Expand All @@ -57,9 +59,9 @@ func TestValue(t *testing.T) {
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)
Expand All @@ -76,10 +78,10 @@ func TestValueX(t *testing.T) {

in := `
-- in.cue --
x: [string]: int64
x: {
y: int
}
import "strings"
strings.MinRunes(4) & strings.MaxRunes(7)
`

archive := txtar.Parse([]byte(in))
Expand All @@ -94,7 +96,7 @@ x: {
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)
}
Expand Down

0 comments on commit 311f5bc

Please sign in to comment.