// Tests that unifying a struct with an embedded scalar and definition fields
// against a definition (or disjunction of definitions) works correctly.
// The `ellipsis`, `bulk`, and `optional` groups cover open definitions with
// `...`, bulk constraints, and optional fields respectively. The `issue783`
// group covers the original bug: unifying such a struct against a disjunction
// of definitions (`{...} | {string, ...}`) was incorrectly failing or dropping
// disjunction branches.
// https://cuelang.org/issue/783
-- in.cue --
elipsis: {
	test1: {
		string
		#foo: "bar"
	}

	#Def: {
		...
		#foo: string
		_
	}
	check: test1 & #Def
}

bulk: {
	test1: {
		string
		#foo: "bar"
	}

	#Def: {
		[string]: int
		#foo:     string
		_
	}
	check: test1 & #Def
}

optional: {
	test1: {
		string
		#foo: "bar"
	}

	#Def: {
		bar?: int
		#foo: string
		_
	}
	check: test1 & #Def
}

// Tests that unifying a struct with an embedded scalar and definition fields
// against a definition (or disjunction of definitions) works correctly.
// The `ellipsis`, `bulk`, and `optional` groups cover open definitions with
// `...`, bulk constraints, and optional fields respectively. The `issue783`
// group covers the original bug: unifying such a struct against a disjunction
// of definitions (`{...} | {string, ...}`) was incorrectly failing or dropping
// disjunction branches.
// https://cuelang.org/issue/783
issue783: {
	test1: {
		string
		#foo: "bar"
	}

	test2: {
		hello: "world"
		#foo:  "bar"
	}

	#Def1: {
		...
		#foo: string
	} | {
		string
		#foo: string
	}

	check1a: test1 & #Def1
	check1b: test2 & #Def1

	#Def2: {
		...
		#foo: string
		_
	}
	check2a: test1 & #Def2
	check2b: test2 & #Def2
}
-- out/compile --
--- in.cue
{
  elipsis: {
    test1: {
      string
      #foo: "bar"
    }
    #Def: {
      ...
      #foo: string
      _
    }
    check: (〈0;test1〉 & 〈0;#Def〉)
  }
  bulk: {
    test1: {
      string
      #foo: "bar"
    }
    #Def: {
      [string]: int
      #foo: string
      _
    }
    check: (〈0;test1〉 & 〈0;#Def〉)
  }
  optional: {
    test1: {
      string
      #foo: "bar"
    }
    #Def: {
      bar?: int
      #foo: string
      _
    }
    check: (〈0;test1〉 & 〈0;#Def〉)
  }
  issue783: {
    test1: {
      string
      #foo: "bar"
    }
    test2: {
      hello: "world"
      #foo: "bar"
    }
    #Def1: ({
      ...
      #foo: string
    }|{
      string
      #foo: string
    })
    check1a: (〈0;test1〉 & 〈0;#Def1〉)
    check1b: (〈0;test2〉 & 〈0;#Def1〉)
    #Def2: {
      ...
      #foo: string
      _
    }
    check2a: (〈0;test1〉 & 〈0;#Def2〉)
    check2b: (〈0;test2〉 & 〈0;#Def2〉)
  }
}
