# A module replace directive that names a bare module path (without a major
# version) must also work under `cue mod tidy`. The major version is resolved
# from the `default: true` entry recorded for the replacement target in
# cue.mod/local-module.cue, matching how the target is resolved at load time.

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

exec cue export .
cmp stdout want-export.txt

exec cue mod tidy --check

-- want-module --
module: "example.com/main@v0"
language: {
	version: "v0.17.0"
}
deps: {
	"example.com/foo@v0": {
		v: "v0.1.0"
	}
}
-- want-local --
deps: {
	"example.com/bar@v0": {
		v:       "v0.1.0"
		default: true
	}
	"example.com/foo@v0": {
		replaceWith: "example.com/bar"
	}
}
-- want-export.txt --
{
    "value": "from bar (bare-path replacement for foo)"
}
-- cue.mod/module.cue --
module: "example.com/main@v0"
language: version: "v0.17.0"

deps: {
	"example.com/foo@v0": {
		v: "v0.1.0"
	}
}
-- cue.mod/local-module.cue --
deps: {
	"example.com/foo@v0": {
		v: "v0.1.0"
		replaceWith: "example.com/bar"
	}
	"example.com/bar@v0": {
		v:       "v0.1.0"
		default: true
	}
}
-- main.cue --
package main

import "example.com/foo@v0:foo"

value: foo.value
-- _registry/example.com_bar_v0.1.0/cue.mod/module.cue --
module: "example.com/bar@v0"
language: version: "v0.9.0"
-- _registry/example.com_bar_v0.1.0/foo.cue --
package foo

value: "from bar (bare-path replacement for foo)"
-- _registry/example.com_foo_v0.1.0/cue.mod/module.cue --
module: "example.com/foo@v0"
language: version: "v0.9.0"
-- _registry/example.com_foo_v0.1.0/foo.cue --
package foo

value: "from foo v0 (should not see this)"
