#name: optionals with label filters
#evalFull
# Tests that optional fields with label filters enforce their constraints:
# fields not matching the pattern or constraint fail with "field not allowed"
# or bound violations. jobs is the happy path; jobs1, jobs2, jobs3 are faulty.
-- in.cue --
#JobID: =~"^[a-zA-Z]*$"
#Job: {
	name: string
	cmd:  string
}
#Jobs: {
	{[#JobID]: #Job}

	{[=~"Test$"]: name: =~"^test"} // Must work without ...
}

jobs: foo: name: "allGood"
jobs: foo: name: "allGood"

jobs1:          #Jobs
jobs1: foo1: {} // faulty

jobs2: #Jobs
jobs2: fooTest: name: "badName" // faulty

jobs3: #Jobs
jobs3: [string]: #Job
jobs3: fooTest1: name: "badName" // faulty
-- out/compile --
--- in.cue
{
  #JobID: =~"^[a-zA-Z]*$"
  #Job: {
    name: string
    cmd: string
  }
  #Jobs: {
    {
      [〈2;#JobID〉]: 〈2;#Job〉
    }
    {
      [=~"Test$"]: {
        name: =~"^test"
      }
    }
  }
  jobs: {
    foo: {
      name: "allGood"
    }
  }
  jobs: {
    foo: {
      name: "allGood"
    }
  }
  jobs1: 〈0;#Jobs〉
  jobs1: {
    foo1: {}
  }
  jobs2: 〈0;#Jobs〉
  jobs2: {
    fooTest: {
      name: "badName"
    }
  }
  jobs3: 〈0;#Jobs〉
  jobs3: {
    [string]: 〈1;#Job〉
  }
  jobs3: {
    fooTest1: {
      name: "badName"
    }
  }
}
