#name: regexp
#evalPartial
-- in.cue --
c1: "a" =~ "a"
c2: "foo" =~ "[a-z]{3}"
c3: "foo" =~ "[a-z]{4}"
c4: "foo" !~ "[a-z]{4}"

b1: =~"a"
b1: "a"
b2: =~"[a-z]{3}"
b2: "foo"
b3: =~"[a-z]{4}"
b3: "foo"
b4: !~"[a-z]{4}"
b4: "foo"

s1: !="b" & =~"c"     // =~"c"
s2: =~"c" & !="b"     // =~"c"
s3: !="b" & =~"[a-z]" // != "b" & =~"[a-z]"
s4: =~"[a-z]" & !="b" // != "b" & =~"[a-z]"

e1: "foo" =~ 1
e2: "foo" !~ true
e3: !="a" & <5
-- out/def --
c1: true
c2: true
c3: false
c4: true
b1: "a"
b2: "foo"
b3: _|_ // invalid value "foo" (does not match =~"[a-z]{4}")
b4: "foo"
s1: =~"c"
s2: !="b" & =~"[a-z]"
e1: _|_ // invalid operation "foo" =~ 1 (mismatched types string and int)
e2: _|_ // invalid operation "foo" !~ true (mismatched types string and bool)
e3: _|_ // conflicting values !="a" and <5 (mismatched types string and number)
-- out/legacy-debug --
<0>{c1: true, c2: true, c3: false, c4: true, b1: "a", b2: "foo", b3: _|_((=~"[a-z]{4}" & "foo"):invalid value "foo" (does not match =~"[a-z]{4}")), b4: "foo", s1: =~"c", s2: (!="b" & =~"[a-z]"), e1: _|_(("foo" =~ 1):invalid operation "foo" =~ 1 (mismatched types string and int)), e2: _|_(("foo" !~ true):invalid operation "foo" !~ true (mismatched types string and bool)), e3: _|_((!="a" & <5):conflicting values !="a" and <5 (mismatched types string and number))}
-- out/compile --
--- in.cue
{
  c1: ("a" =~ "a")
  c2: ("foo" =~ "[a-z]{3}")
  c3: ("foo" =~ "[a-z]{4}")
  c4: ("foo" !~ "[a-z]{4}")
  b1: =~"a"
  b1: "a"
  b2: =~"[a-z]{3}"
  b2: "foo"
  b3: =~"[a-z]{4}"
  b3: "foo"
  b4: !~"[a-z]{4}"
  b4: "foo"
  s1: (!="b" & =~"c")
  s2: (=~"c" & !="b")
  s3: (!="b" & =~"[a-z]")
  s4: (=~"[a-z]" & !="b")
  e1: ("foo" =~ 1)
  e2: ("foo" !~ true)
  e3: (!="a" & <5)
}
-- out/eval/stats --
Leaks:  0
Freed:  16
Reused: 14
Allocs: 2
Retain: 0

Unifications: 16
Conjuncts:    25
Disjuncts:    16
-- out/eval --
Errors:
e3: conflicting values !="a" and <5 (mismatched types string and number):
    ./in.cue:22:5
    ./in.cue:22:13
b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
    ./in.cue:10:5
    ./in.cue:11:5
e1: cannot use 1 (type int) as type (string|bytes):
    ./in.cue:20:5
    ./in.cue:20:14
e2: cannot use true (type bool) as type (string|bytes):
    ./in.cue:21:5
    ./in.cue:21:14

Result:
(_|_){
  // [eval]
  c1: (bool){ true }
  c2: (bool){ true }
  c3: (bool){ false }
  c4: (bool){ true }
  b1: (string){ "a" }
  b2: (string){ "foo" }
  b3: (_|_){
    // [eval] b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
    //     ./in.cue:10:5
    //     ./in.cue:11:5
  }
  b4: (string){ "foo" }
  s1: (string){ =~"c" }
  s2: (string){ =~"c" }
  s3: (string){ &(!="b", =~"[a-z]") }
  s4: (string){ &(=~"[a-z]", !="b") }
  e1: (_|_){
    // [eval] e1: cannot use 1 (type int) as type (string|bytes):
    //     ./in.cue:20:5
    //     ./in.cue:20:14
  }
  e2: (_|_){
    // [eval] e2: cannot use true (type bool) as type (string|bytes):
    //     ./in.cue:21:5
    //     ./in.cue:21:14
  }
  e3: (_|_){
    // [eval] e3: conflicting values !="a" and <5 (mismatched types string and number):
    //     ./in.cue:22:5
    //     ./in.cue:22:13
  }
}
