# Tests that pos=[] placeholders are filled with actual error positions on
# CUE_UPDATE=1. The input has a conflict error (100 & 200) with empty pos=[]
# placeholders; after update, the placeholders are replaced with the actual
# source positions of the conflicting values. This applies to top-level
# @test(err) attrs and to nested @test(err) attrs inside @test(eq, {...}).
# Also tests that wrong (non-placeholder) positions in w are left unchanged by
# CUE_UPDATE=1 (force-only), and that force corrects them on top of filling
# the placeholders, producing a different result than plain update.
-- in/test.cue --
x: 100 & 200 @test(err, code=eval, pos=[])

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

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

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


// 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=[])
		b: _|_ @test(err, code=eval, pos=[])
	})
}
-- out/run/errors.txt --
path x: @test(err, pos=...): got 2 position(s), want 0; extra positions are often acceptable, and after confirming they are relevant to this error you can add them to pos=[...]
path y.b: @test(err, pos=...): got 2 position(s), want 0; extra positions are often acceptable, and after confirming they are relevant to this error you can add them to pos=[...]
path z: c: @test(err, pos=...): got 3 position(s), want 0; extra positions are often acceptable, and after confirming they are relevant to this error you can add them to pos=[...] [test.cue:8:5 test.cue:9:5 test.cue:9:9]
path w: a: @test(err, pos=...): got 2 position(s), want 0; extra positions are often acceptable, and after confirming they are relevant to this error you can add them to pos=[...] [test.cue:21:5 test.cue:21:11]
-- out/update/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/status.txt --
update: output passes run
force:  identical to update
-- 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:21:5
    ./test.cue:21:11
[eval] w.b: conflicting values 200 and 100:
    ./test.cue:22:5
    ./test.cue:22:11
