# Go standard library packages can cause issues, because we cannot generate
# packages such as cue.mod/gen/time which conflict with our own standard library.

exec cue get go --local
cmp src_go_gen.cue src_go_gen.cue.golden

# Check which files were generated under cue.mod/gen and other directories.
# We cannot generate any std packages under cue.mod/gen either.
find-files cue.mod
! stdout '^cue.mod/gen/[^.]+/'

# Verify that the result can be loaded correctly.
exec cue vet -c=false

-- go.mod --
module mod.test

go 1.21
-- cue.mod/module.cue --
module: "mod.test"

language: version: "v0.12.0"
-- src.go --
package x

import (
	"io"
	"reflect"
	"time"
)

type Root struct {
	// reflect types and values in Go are opaque and do not encode as useful JSON.
	ReflectType  reflect.Type
	ReflectValue reflect.Value

	// reflect.ValueError is an example of a struct made up of simple types,
	// in this case a Method string and a Kind uint.
	// TODO: generate that structure as long as we don't place it in cue.mod/pkg/reflect,
	// which conflicts with CUE's own std.
	ReflectValueError reflect.ValueError

	// io.Writer is an interface, so there is no structure to be generated.
	// Moreover, even though "io" is a very common Go package, CUE has no such package.
	IoWriter io.Writer

	// time.Month is just an int type, but this edge case is particularly interesting
	// given that CUE already has a "time" package with e.g. Duration and Time, but no Month.
	// TODO: generate that structure as long as we don't place it in cue.mod/pkg/reflect,
	// which conflicts with CUE's own std, or generate "int" directly.
	TimeMonth time.Month
}
-- src_go_gen.cue.golden --
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go mod.test

package x

#Root: {
	// reflect types and values in Go are opaque and do not encode as useful JSON.
	ReflectType: _ @go(,reflect.Type)

	// reflect.ValueError is an example of a struct made up of simple types,
	// in this case a Method string and a Kind uint.
	// TODO: generate that structure as long as we don't place it in cue.mod/pkg/reflect,
	// which conflicts with CUE's own std.
	ReflectValueError: _ @go(,reflect.ValueError)

	// io.Writer is an interface, so there is no structure to be generated.
	// Moreover, even though "io" is a very common Go package, CUE has no such package.
	IoWriter: _ @go(,io.Writer)

	// time.Month is just an int type, but this edge case is particularly interesting
	// given that CUE already has a "time" package with e.g. Duration and Time, but no Month.
	// TODO: generate that structure as long as we don't place it in cue.mod/pkg/reflect,
	// which conflicts with CUE's own std, or generate "int" directly.
	TimeMonth: _ @go(,time.Month)
}
