# Tests that CUE_UPDATE=force overwrites wrong (non-placeholder) positions, while
# CUE_UPDATE=1 leaves them unchanged and reports a position mismatch error.
# Also tests that two wrong positions inside the same @test(eq, {...}) are both
# corrected — exercising the nestedPosFills accumulator that merges multiple
# nested pos writes for the same outer attribute into a single write.
-- in/test.cue --
x: 100 & 200 @test(err, code=eval, pos=[0:4, 0:999999])

y: {
	b: 100 & 200 @test(err, code=eval, pos=[0:5, 0:99999])
}

z: {
	b: int
	c: b & "foo"

	@test(eq, {
		b: int
		c: _|_ @test(err, code=eval, pos=[1:5, 2:5, 2:99999])
	})
}

// w tests two wrong pos= specs inside the same @test(eq, {...}), requiring
// both nested rewrites to be merged before the outer attribute is written back.
w: {
	a: 100 & 200
	b: 100 & 200

	@test(eq, {
		a: _|_ @test(err, code=eval, pos=[1:99999])
		b: _|_ @test(err, code=eval, pos=[2:99999])
	})
}
-- out/run/errors.txt --
path x: @test(err, pos=...): unmatched position 1:999999 (spec 0:999999); actual positions:
path y.b: @test(err, pos=...): unmatched position 4:99999 (spec 0:99999); actual positions:
path z: c: @test(err, pos=...): no match for expected position 9:99999 in [test.cue:8:5 test.cue:9:5 test.cue:9:9]
path w: a: @test(err, pos=...): got 2 position(s), want 1; extra positions are often acceptable, and after confirming they are relevant to this error you can add them to pos=[...] [test.cue:20:5 test.cue:20:11]
-- out/status.txt --
update: output passes run
-- out/force/test.cue --
x: 100 & 200 @test(err, code=eval, pos=[0:4, 0:10])

y: {
	b: 100 & 200 @test(err, code=eval, pos=[0:5, 0:11])
}

z: {
	b: int
	c: b & "foo"

	@test(eq, {
		b: int
		c: _|_ @test(err, code=eval, pos=[1:5, 2:5, 2:9])
	})
}

// w tests two wrong pos= specs inside the same @test(eq, {...}), requiring
// both nested rewrites to be merged before the outer attribute is written back.
w: {
	a: 100 & 200
	b: 100 & 200

	@test(eq, {
		a: _|_ @test(err, code=eval, pos=[1:5, 1:11])
		b: _|_ @test(err, code=eval, pos=[2:5, 2:11])
	})
}
-- out/update/test.cue --
x: 100 & 200 @test(err, code=eval, pos=[0:4, 0:999999])

y: {
	b: 100 & 200 @test(err, code=eval, pos=[0:5, 0:99999])
}

z: {
	b: int
	c: b & "foo"

	@test(eq, {
		b: int
		c: _|_ @test(err, code=eval, pos=[1:5, 2:5, 2:99999])
	})
}

// w tests two wrong pos= specs inside the same @test(eq, {...}), requiring
// both nested rewrites to be merged before the outer attribute is written back.
w: {
	a: 100 & 200
	b: 100 & 200

	@test(eq, {
		a: _|_ @test(err, code=eval, pos=[1:99999])
		b: _|_ @test(err, code=eval, pos=[2:99999])
	})
}
-- out/update/out/errors.txt --
[eval] x: conflicting values 200 and 100:
    ./test.cue:1:4
    ./test.cue:1:10
[eval] y.b: conflicting values 200 and 100:
    ./test.cue:4:5
    ./test.cue:4:11
[eval] z.c: conflicting values "foo" and int (mismatched types string and int):
    ./test.cue:8:5
    ./test.cue:9:5
    ./test.cue:9:9
[eval] w.a: conflicting values 200 and 100:
    ./test.cue:20:5
    ./test.cue:20:11
[eval] w.b: conflicting values 200 and 100:
    ./test.cue:21:5
    ./test.cue:21:11
-- out/force/out/errors.txt --
[eval] x: conflicting values 200 and 100:
    ./test.cue:1:4
    ./test.cue:1:10
[eval] y.b: conflicting values 200 and 100:
    ./test.cue:4:5
    ./test.cue:4:11
[eval] z.c: conflicting values "foo" and int (mismatched types string and int):
    ./test.cue:8:5
    ./test.cue:9:5
    ./test.cue:9:9
[eval] w.a: conflicting values 200 and 100:
    ./test.cue:20:5
    ./test.cue:20:11
[eval] w.b: conflicting values 200 and 100:
    ./test.cue:21:5
    ./test.cue:21:11
