cuelang.org/go@v0.13.0/cue/testdata/basicrewrite/001_regexp.txtar (about)

     1  #name: regexp
     2  #evalPartial
     3  -- in.cue --
     4  c1: "a" =~ "a"
     5  c2: "foo" =~ "[a-z]{3}"
     6  c3: "foo" =~ "[a-z]{4}"
     7  c4: "foo" !~ "[a-z]{4}"
     8  
     9  b1: =~"a"
    10  b1: "a"
    11  b2: =~"[a-z]{3}"
    12  b2: "foo"
    13  b3: =~"[a-z]{4}"
    14  b3: "foo"
    15  b4: !~"[a-z]{4}"
    16  b4: "foo"
    17  
    18  s1: !="b" & =~"c"     // =~"c"
    19  s2: =~"c" & !="b"     // =~"c"
    20  s3: !="b" & =~"[a-z]" // != "b" & =~"[a-z]"
    21  s4: =~"[a-z]" & !="b" // != "b" & =~"[a-z]"
    22  
    23  e1: "foo" =~ 1
    24  e2: "foo" !~ true
    25  e3: !="a" & <5
    26  -- out/def --
    27  c1: true
    28  c2: true
    29  c3: false
    30  c4: true
    31  b1: "a"
    32  b2: "foo"
    33  b3: _|_ // invalid value "foo" (does not match =~"[a-z]{4}")
    34  b4: "foo"
    35  s1: =~"c"
    36  s2: !="b" & =~"[a-z]"
    37  e1: _|_ // invalid operation "foo" =~ 1 (mismatched types string and int)
    38  e2: _|_ // invalid operation "foo" !~ true (mismatched types string and bool)
    39  e3: _|_ // conflicting values !="a" and <5 (mismatched types string and number)
    40  -- out/legacy-debug --
    41  <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))}
    42  -- out/compile --
    43  --- in.cue
    44  {
    45    c1: ("a" =~ "a")
    46    c2: ("foo" =~ "[a-z]{3}")
    47    c3: ("foo" =~ "[a-z]{4}")
    48    c4: ("foo" !~ "[a-z]{4}")
    49    b1: =~"a"
    50    b1: "a"
    51    b2: =~"[a-z]{3}"
    52    b2: "foo"
    53    b3: =~"[a-z]{4}"
    54    b3: "foo"
    55    b4: !~"[a-z]{4}"
    56    b4: "foo"
    57    s1: (!="b" & =~"c")
    58    s2: (=~"c" & !="b")
    59    s3: (!="b" & =~"[a-z]")
    60    s4: (=~"[a-z]" & !="b")
    61    e1: ("foo" =~ 1)
    62    e2: ("foo" !~ true)
    63    e3: (!="a" & <5)
    64  }
    65  -- out/eval/stats --
    66  Leaks:  0
    67  Freed:  16
    68  Reused: 14
    69  Allocs: 2
    70  Retain: 0
    71  
    72  Unifications: 16
    73  Conjuncts:    25
    74  Disjuncts:    16
    75  -- out/eval --
    76  Errors:
    77  e3: conflicting values !="a" and <5 (mismatched types string and number):
    78      ./in.cue:22:5
    79      ./in.cue:22:13
    80  b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
    81      ./in.cue:10:5
    82      ./in.cue:11:5
    83  e1: cannot use 1 (type int) as type (string|bytes):
    84      ./in.cue:20:5
    85      ./in.cue:20:14
    86  e2: cannot use true (type bool) as type (string|bytes):
    87      ./in.cue:21:5
    88      ./in.cue:21:14
    89  
    90  Result:
    91  (_|_){
    92    // [eval]
    93    c1: (bool){ true }
    94    c2: (bool){ true }
    95    c3: (bool){ false }
    96    c4: (bool){ true }
    97    b1: (string){ "a" }
    98    b2: (string){ "foo" }
    99    b3: (_|_){
   100      // [eval] b3: invalid value "foo" (out of bound =~"[a-z]{4}"):
   101      //     ./in.cue:10:5
   102      //     ./in.cue:11:5
   103    }
   104    b4: (string){ "foo" }
   105    s1: (string){ =~"c" }
   106    s2: (string){ =~"c" }
   107    s3: (string){ &(!="b", =~"[a-z]") }
   108    s4: (string){ &(=~"[a-z]", !="b") }
   109    e1: (_|_){
   110      // [eval] e1: cannot use 1 (type int) as type (string|bytes):
   111      //     ./in.cue:20:5
   112      //     ./in.cue:20:14
   113    }
   114    e2: (_|_){
   115      // [eval] e2: cannot use true (type bool) as type (string|bytes):
   116      //     ./in.cue:21:5
   117      //     ./in.cue:21:14
   118    }
   119    e3: (_|_){
   120      // [eval] e3: conflicting values !="a" and <5 (mismatched types string and number):
   121      //     ./in.cue:22:5
   122      //     ./in.cue:22:13
   123    }
   124  }