# cue mod tidy when a dependency is imported with an implied major version, so
# it is marked as the default in cue.mod/module.cue, and is also replaced in
# cue.mod/local-module.cue. The default field is written only to module.cue;
# local-module.cue omits it (along with the redundant version) and restores it
# from module.cue when the file is read back.

exec cue mod tidy
cmp cue.mod/module.cue want-module
cmp cue.mod/local-module.cue want-local

# The build uses the local directory's content.
exec cue export .
cmp stdout want-stdout

# tidy is idempotent.
exec cue mod tidy --check

-- want-module --
module: "main.org@v0"
language: {
	version: "v0.17.0"
}
deps: {
	"example.com/dep@v0": {
		v:       "v0.1.0"
		default: true
	}
}
-- want-local --
deps: {
	"example.com/dep@v0": {
		replaceWith: "./local_dep"
	}
}
-- want-stdout --
{
    "out": "from local directory"
}
-- cue.mod/module.cue --
module: "main.org@v0"
language: version: "v0.17.0"
deps: "example.com/dep@v0": {
	v:       "v0.1.0"
	default: true
}
-- cue.mod/local-module.cue --
deps: "example.com/dep@v0": replaceWith: "./local_dep"
-- main.cue --
package main

import "example.com/dep:lib"

out: lib.value
-- local_dep/cue.mod/module.cue --
module: "example.com/dep@v0"
language: version: "v0.9.0"
-- local_dep/lib.cue --
package lib

value: "from local directory"
-- _registry/example.com_dep_v0.1.0/cue.mod/module.cue --
module: "example.com/dep@v0"
language: version: "v0.9.0"
-- _registry/example.com_dep_v0.1.0/lib.cue --
package lib

value: "from registry"
