#name: associativity of defaults
#evalFull
-- in.cue --
a: *"a" | ("b" | "c")  @test(eq, *"a" | "b" | "c")
b: (*"a" | "b") | "c"  @test(eq, *"a" | "b" | "c")
c: *"a" | (*"b" | "c") @test(eq, *"a" | "b" | "c")
x: a & b               @test(eq, *"a" | "b" | "c")
y: b & c               @test(eq, *"a" | "b" | "c")

s1: *1 | ((*2 | 3) & (2 | *3)) @test(eq, *1 | 2 | 3)
s2: *1 | ((*2 | 3) & (*2 | 3)) @test(eq, *1 | 2 | 3)
s3: *1 | ((*2 | 3) & 3)        @test(eq, *1 | 3)
s4: *1 | ((*2 | 3) & 2)        @test(eq, *1 | 2)
s5: *1 | *(*2 | 3)             @test(eq, *1 | *2 | 3)

e1: *(1&2) | (*"x" | string)   @test(eq, "x" | string)
e2: (*"x" | string) | *(1&2)   @test(eq, "x" | string)

-- complex.cue --
// add some test cases suggested by an automated prover based on this pattern:
// 1. ValK = (ValA & ValB_ND) & ValC_D \neq _|_ (the element we track must exist).
// 2. ValC_D & (ValA & ValB_D) = _|_ (for Path 1 Cond(ValC_D, Disj_AB) to be true).
// 3. ValC_D & ValB_D \neq _|_ (for Path 2 Cond(ValC_D, Disj_B) to be false).

// Let's define these CUE values. The trick is that ValA must introduce a
// component that causes ValC_D to conflict with (ValA & ValB_D),
// but ValC_D must *not* conflict with ValB_D on its own.
t1: {
	va:  {a: 1, b: 2}
	vb1: {c: 3}
	vb2: {c: 4}
	vc : {c: 4}
	vd:  string

	A: va | vd          @test(eq, {a: 1, b: 2} | string)
	B: *vb1 | vb2 | vd  @test(eq, *{c: 3} | {c: 4} | string)
	C: *vc | vd         @test(eq, *{c: 4} | string)

	p1: (A & B) & C @test(eq, *{a: 1, b: 2, c: 4} | string)
	p2: A & (B & C) @test(eq, *{a: 1, b: 2, c: 4} | string)
}
t2: {
	va:  0 | 1 | 2
	vb1: 2 | 3
	vb2: 0 | 1 | 4
	vc:  0 | 3 | 4
	vd:  string

	A: va | vd          @test(eq, 0 | 1 | 2 | string)
	B: *vb1 | vb2 | vd  @test(eq, *2 | *3 |0 | 1 | 4 | string)
	C: *vc | vd         @test(eq, *0 | *3 | *4 | string)

	p1: (A & B) & C @test(eq, *0 | string)
	p2: A & (B & C) @test(eq, *0 | string)
}
-- issue3908.cue --
// issue3908: Tests that nested defaults (e.g. null default overridden by a
// string default) are handled correctly in evalv3. https://cuelang.org/issue/3908
issue3908: reduced: {
	@test(permute)
	string | *null
	string | *"str"
	@test(eq, *"str" | string)
}
issue3908: full: {
	out: #Schema & { field: string | *"dataDefault" }
	#Schema: field: string | *null
	@test(eq, {
		out: field: *"dataDefault" | string
		#Schema: field: *null | string
	})
}
-- out/eval/stats --
Leaks:  30
Freed:  352
Reused: 326
Allocs: 56
Retain: 0

Unifications: 62
Conjuncts:    466
Disjuncts:    278

NumCloseIDs: 101
