# Test editing go.work files.

go mod initwork m
cmp go.work go.work.want_initial

go mod editwork -directory n
cmp go.work go.work.want_directory_n

go mod editwork -go 1.18
cmp go.work go.work.want_go_118

go mod editwork -dropdirectory m
cmp go.work go.work.want_dropdirectory_m

go mod editwork -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z'
cmp go.work go.work.want_add_replaces

go mod editwork -directory n -directory ../a -directory /b -directory c -directory c
cmp go.work go.work.want_multidirectory

go mod editwork -dropdirectory /b -dropdirectory n
cmp go.work go.work.want_multidropdirectory

go mod editwork -dropreplace='x.1@v1.4.0'
cmp go.work go.work.want_dropreplace

go mod editwork -print -go 1.19 -directory b -dropdirectory c -replace 'x.1@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x.1@v1.3.0
cmp stdout go.work.want_print

go mod editwork -json -go 1.19 -directory b -dropdirectory c -replace 'x.1@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x.1@v1.3.0
cmp stdout go.work.want_json

go mod editwork -print -fmt -workfile unformatted
cmp stdout formatted

-- go.work.want_initial --
go 1.18

directory m
-- go.work.want_directory_n --
go 1.18

directory (
	m
	n
)
-- go.work.want_go_118 --
go 1.18

directory (
	m
	n
)
-- go.work.want_dropdirectory_m --
go 1.18

directory n
-- go.work.want_add_replaces --
go 1.18

directory n

replace (
	x.1 v1.3.0 => y.1 v1.4.0
	x.1 v1.4.0 => ../z
)
-- go.work.want_multidirectory --
go 1.18

directory (
	../a
	/b
	c
	n
)

replace (
	x.1 v1.3.0 => y.1 v1.4.0
	x.1 v1.4.0 => ../z
)
-- go.work.want_multidropdirectory --
go 1.18

directory (
	../a
	c
)

replace (
	x.1 v1.3.0 => y.1 v1.4.0
	x.1 v1.4.0 => ../z
)
-- go.work.want_dropreplace --
go 1.18

directory (
	../a
	c
)

replace x.1 v1.3.0 => y.1 v1.4.0
-- go.work.want_print --
go 1.19

directory (
	../a
	b
)

replace x.1 v1.4.0 => ../z
-- go.work.want_json --
{
	"Go": "1.19",
	"Directory": [
		{
			"DiskPath": "../a"
		},
		{
			"DiskPath": "b"
		}
	],
	"Replace": [
		{
			"Old": {
				"Path": "x.1",
				"Version": "v1.4.0"
			},
			"New": {
				"Path": "../z"
			}
		}
	]
}
-- unformatted --
go 1.18
 directory (
 a
  b
  c
  )
  replace (
  x.1 v1.3.0 => y.1 v1.4.0
                            x.1 v1.4.0 => ../z
                            )
-- formatted --
go 1.18

directory (
	a
	b
	c
)

replace (
	x.1 v1.3.0 => y.1 v1.4.0
	x.1 v1.4.0 => ../z
)