github.com/solo-io/cue@v0.4.7/cue/testdata/cycle/compbottom.txtar (about)

     1  // Issues: #667, #695, #622
     2  
     3  // Comparing against bottom is not officially supported by the spec.
     4  // In practice it is used for a variety of purposes.
     5  //
     6  // TODO: It should really be replaced with two builtins:
     7  //
     8  //    - exists(reference): check if a certain field exists.
     9  //    - isvalid(value):    check if a certain value is valid (recursively).
    10  //
    11  // For now it implements something in between these two: it fails if a value
    12  // resolves to an error, but not necessarily if it does so recursively.
    13  // Although adding a recursive check is easy, it will break existing
    14  // configurations, as a recursive evaluation will trigger cycles where these
    15  // are perhaps not expected.
    16  
    17  // To verify these tests, each result should have a field
    18  //
    19  //     X: "user@example.com"
    20  //
    21  // for the large and medium examples and
    22  //
    23  //     X: "message: hello"
    24  //
    25  // for the simple example.
    26  //
    27  // These are not automatically tested using CUE to avoid interfering with the
    28  // evaluation.
    29  
    30  -- in.cue --
    31  import "regexp"
    32  
    33  simple: {
    34      #message: #"^(message: (?P<message>.*))?$"#
    35  
    36  
    37      p1: {
    38          X: "message: hello"
    39          #aux: {
    40              if Y.message == _|_ {
    41                  message: ""
    42              }
    43              if Y.message != _|_ {
    44                  message: "message: " + Y.message
    45              }
    46          }
    47  
    48          Y: regexp.FindNamedSubmatch(#message, X)
    49          X: #aux.message
    50      }
    51  
    52      p2: {
    53          #aux: {
    54              if Y.message == _|_ {
    55                  message: ""
    56              }
    57              if Y.message != _|_ {
    58                  message: "message: " + Y.message
    59              }
    60          }
    61  
    62          X: "message: hello"
    63          Y: regexp.FindNamedSubmatch(#message, X)
    64          X: #aux.message
    65      }
    66  
    67      p3: {
    68          #aux: {
    69              if Y.message == _|_ {
    70                  message: ""
    71              }
    72              if Y.message != _|_ {
    73                  message: "message: " + Y.message
    74              }
    75          }
    76  
    77          Y: regexp.FindNamedSubmatch(#message, X)
    78          X: "message: hello"
    79          X: #aux.message
    80      }
    81  
    82      p4: {
    83          X: #aux.message
    84          #aux: {
    85              if Y.message == _|_ {
    86                  message: ""
    87              }
    88              if Y.message != _|_ {
    89                  message: "message: " + Y.message
    90              }
    91          }
    92  
    93          Y: regexp.FindNamedSubmatch(#message, X)
    94          X: "message: hello"
    95      }
    96  
    97      p5: {
    98          #aux: {
    99              if Y.message == _|_ {
   100                  message: ""
   101              }
   102              if Y.message != _|_ {
   103                  message: "message: " + Y.message
   104              }
   105          }
   106  
   107          X: #aux.message
   108          Y: regexp.FindNamedSubmatch(#message, X)
   109          X: "message: hello"
   110      }
   111  
   112      p6: {
   113          #aux: {
   114              if Y.message == _|_ {
   115                  message: ""
   116              }
   117              if Y.message != _|_ {
   118                  message: "message: " + Y.message
   119              }
   120          }
   121  
   122          Y: regexp.FindNamedSubmatch(#message, X)
   123          X: #aux.message
   124          X: "message: hello"
   125      }
   126  }
   127  
   128  medium: {
   129      #userHostPort: #"^((?P<userinfo>[[:alnum:]]*)@)?(?P<host>[[:alnum:].]+)$"#
   130  
   131      p1: {
   132          Y: {
   133              userinfo: "user"
   134              host: "example.com"
   135          }
   136  
   137          X: #X.userinfo + #X.host
   138  
   139          #X: {
   140              if Y.userinfo == _|_ {
   141                  userinfo: ""
   142              }
   143              if Y.userinfo != _|_ {
   144                  userinfo: Y.userinfo + "@"
   145              }
   146  
   147              host: Y.host
   148          }
   149  
   150          Y: {
   151              if #Y.userinfo != _|_ {
   152                  userinfo: #Y.userinfo
   153              }
   154  
   155              host: #Y.host
   156          }
   157  
   158          #Y: regexp.FindNamedSubmatch(#userHostPort, X)
   159      }
   160  
   161      p2: {
   162          X: #X.userinfo + #X.host
   163  
   164          Y: {
   165              userinfo: "user"
   166              host: "example.com"
   167          }
   168  
   169          #X: {
   170              if Y.userinfo == _|_ {
   171                  userinfo: ""
   172              }
   173              if Y.userinfo != _|_ {
   174                  userinfo: Y.userinfo + "@"
   175              }
   176  
   177              host: Y.host
   178          }
   179  
   180          Y: {
   181              if #Y.userinfo != _|_ {
   182                  userinfo: #Y.userinfo
   183              }
   184  
   185              host: #Y.host
   186          }
   187  
   188          #Y: regexp.FindNamedSubmatch(#userHostPort, X)
   189      }
   190  
   191      p3: {
   192          X: #X.userinfo + #X.host
   193  
   194          #X: {
   195              if Y.userinfo == _|_ {
   196                  userinfo: ""
   197              }
   198              if Y.userinfo != _|_ {
   199                  userinfo: Y.userinfo + "@"
   200              }
   201  
   202              host: Y.host
   203          }
   204  
   205          Y: {
   206              userinfo: "user"
   207              host: "example.com"
   208          }
   209  
   210          Y: {
   211              if #Y.userinfo != _|_ {
   212                  userinfo: #Y.userinfo
   213              }
   214  
   215              host: #Y.host
   216          }
   217  
   218          #Y: regexp.FindNamedSubmatch(#userHostPort, X)
   219      }
   220  
   221      p4: {
   222          X: #X.userinfo + #X.host
   223  
   224          #X: {
   225              if Y.userinfo == _|_ {
   226                  userinfo: ""
   227              }
   228              if Y.userinfo != _|_ {
   229                  userinfo: Y.userinfo + "@"
   230              }
   231  
   232              host: Y.host
   233          }
   234  
   235          Y: {
   236              if #Y.userinfo != _|_ {
   237                  userinfo: #Y.userinfo
   238              }
   239  
   240              host: #Y.host
   241          }
   242  
   243          #Y: regexp.FindNamedSubmatch(#userHostPort, X)
   244  
   245          Y: {
   246              userinfo: "user"
   247              host: "example.com"
   248          }
   249      }
   250  }
   251  -- out/eval --
   252  (struct){
   253    simple: (struct){
   254      #message: (string){ "^(message: (?P<message>.*))?$" }
   255      p1: (struct){
   256        X: (string){ "message: hello" }
   257        #aux: (#struct){
   258          message: (string){ "message: hello" }
   259        }
   260        Y: (struct){
   261          message: (string){ "hello" }
   262        }
   263      }
   264      p2: (struct){
   265        #aux: (#struct){
   266          message: (string){ "message: hello" }
   267        }
   268        X: (string){ "message: hello" }
   269        Y: (struct){
   270          message: (string){ "hello" }
   271        }
   272      }
   273      p3: (struct){
   274        #aux: (#struct){
   275          message: (string){ "message: hello" }
   276        }
   277        Y: (struct){
   278          message: (string){ "hello" }
   279        }
   280        X: (string){ "message: hello" }
   281      }
   282      p4: (struct){
   283        X: (string){ "message: hello" }
   284        #aux: (#struct){
   285          message: (string){ "message: hello" }
   286        }
   287        Y: (struct){
   288          message: (string){ "hello" }
   289        }
   290      }
   291      p5: (struct){
   292        #aux: (#struct){
   293          message: (string){ "message: hello" }
   294        }
   295        X: (string){ "message: hello" }
   296        Y: (struct){
   297          message: (string){ "hello" }
   298        }
   299      }
   300      p6: (struct){
   301        #aux: (#struct){
   302          message: (string){ "message: hello" }
   303        }
   304        Y: (struct){
   305          message: (string){ "hello" }
   306        }
   307        X: (string){ "message: hello" }
   308      }
   309    }
   310    medium: (struct){
   311      #userHostPort: (string){ "^((?P<userinfo>[[:alnum:]]*)@)?(?P<host>[[:alnum:].]+)$" }
   312      p1: (struct){
   313        Y: (struct){
   314          userinfo: (string){ "user" }
   315          host: (string){ "example.com" }
   316        }
   317        X: (string){ "user@example.com" }
   318        #X: (#struct){
   319          host: (string){ "example.com" }
   320          userinfo: (string){ "user@" }
   321        }
   322        #Y: (#struct){
   323          host: (string){ "example.com" }
   324          userinfo: (string){ "user" }
   325        }
   326      }
   327      p2: (struct){
   328        X: (string){ "user@example.com" }
   329        Y: (struct){
   330          userinfo: (string){ "user" }
   331          host: (string){ "example.com" }
   332        }
   333        #X: (#struct){
   334          host: (string){ "example.com" }
   335          userinfo: (string){ "user@" }
   336        }
   337        #Y: (#struct){
   338          host: (string){ "example.com" }
   339          userinfo: (string){ "user" }
   340        }
   341      }
   342      p3: (struct){
   343        X: (string){ "user@example.com" }
   344        #X: (#struct){
   345          host: (string){ "example.com" }
   346          userinfo: (string){ "user@" }
   347        }
   348        Y: (struct){
   349          userinfo: (string){ "user" }
   350          host: (string){ "example.com" }
   351        }
   352        #Y: (#struct){
   353          host: (string){ "example.com" }
   354          userinfo: (string){ "user" }
   355        }
   356      }
   357      p4: (struct){
   358        X: (string){ "user@example.com" }
   359        #X: (#struct){
   360          host: (string){ "example.com" }
   361          userinfo: (string){ "user@" }
   362        }
   363        Y: (struct){
   364          host: (string){ "example.com" }
   365          userinfo: (string){ "user" }
   366        }
   367        #Y: (#struct){
   368          host: (string){ "example.com" }
   369          userinfo: (string){ "user" }
   370        }
   371      }
   372    }
   373  }
   374  -- out/compile --
   375  --- in.cue
   376  {
   377    simple: {
   378      #message: "^(message: (?P<message>.*))?$"
   379      p1: {
   380        X: "message: hello"
   381        #aux: {
   382          if (〈1;Y〉.message == _|_(explicit error (_|_ literal) in source)) {
   383            message: ""
   384          }
   385          if (〈1;Y〉.message != _|_(explicit error (_|_ literal) in source)) {
   386            message: ("message: " + 〈2;Y〉.message)
   387          }
   388        }
   389        Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#message〉, 〈0;X〉)
   390        X: 〈0;#aux〉.message
   391      }
   392      p2: {
   393        #aux: {
   394          if (〈1;Y〉.message == _|_(explicit error (_|_ literal) in source)) {
   395            message: ""
   396          }
   397          if (〈1;Y〉.message != _|_(explicit error (_|_ literal) in source)) {
   398            message: ("message: " + 〈2;Y〉.message)
   399          }
   400        }
   401        X: "message: hello"
   402        Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#message〉, 〈0;X〉)
   403        X: 〈0;#aux〉.message
   404      }
   405      p3: {
   406        #aux: {
   407          if (〈1;Y〉.message == _|_(explicit error (_|_ literal) in source)) {
   408            message: ""
   409          }
   410          if (〈1;Y〉.message != _|_(explicit error (_|_ literal) in source)) {
   411            message: ("message: " + 〈2;Y〉.message)
   412          }
   413        }
   414        Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#message〉, 〈0;X〉)
   415        X: "message: hello"
   416        X: 〈0;#aux〉.message
   417      }
   418      p4: {
   419        X: 〈0;#aux〉.message
   420        #aux: {
   421          if (〈1;Y〉.message == _|_(explicit error (_|_ literal) in source)) {
   422            message: ""
   423          }
   424          if (〈1;Y〉.message != _|_(explicit error (_|_ literal) in source)) {
   425            message: ("message: " + 〈2;Y〉.message)
   426          }
   427        }
   428        Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#message〉, 〈0;X〉)
   429        X: "message: hello"
   430      }
   431      p5: {
   432        #aux: {
   433          if (〈1;Y〉.message == _|_(explicit error (_|_ literal) in source)) {
   434            message: ""
   435          }
   436          if (〈1;Y〉.message != _|_(explicit error (_|_ literal) in source)) {
   437            message: ("message: " + 〈2;Y〉.message)
   438          }
   439        }
   440        X: 〈0;#aux〉.message
   441        Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#message〉, 〈0;X〉)
   442        X: "message: hello"
   443      }
   444      p6: {
   445        #aux: {
   446          if (〈1;Y〉.message == _|_(explicit error (_|_ literal) in source)) {
   447            message: ""
   448          }
   449          if (〈1;Y〉.message != _|_(explicit error (_|_ literal) in source)) {
   450            message: ("message: " + 〈2;Y〉.message)
   451          }
   452        }
   453        Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#message〉, 〈0;X〉)
   454        X: 〈0;#aux〉.message
   455        X: "message: hello"
   456      }
   457    }
   458    medium: {
   459      #userHostPort: "^((?P<userinfo>[[:alnum:]]*)@)?(?P<host>[[:alnum:].]+)$"
   460      p1: {
   461        Y: {
   462          userinfo: "user"
   463          host: "example.com"
   464        }
   465        X: (〈0;#X〉.userinfo + 〈0;#X〉.host)
   466        #X: {
   467          if (〈1;Y〉.userinfo == _|_(explicit error (_|_ literal) in source)) {
   468            userinfo: ""
   469          }
   470          if (〈1;Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   471            userinfo: (〈2;Y〉.userinfo + "@")
   472          }
   473          host: 〈1;Y〉.host
   474        }
   475        Y: {
   476          if (〈1;#Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   477            userinfo: 〈2;#Y〉.userinfo
   478          }
   479          host: 〈1;#Y〉.host
   480        }
   481        #Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#userHostPort〉, 〈0;X〉)
   482      }
   483      p2: {
   484        X: (〈0;#X〉.userinfo + 〈0;#X〉.host)
   485        Y: {
   486          userinfo: "user"
   487          host: "example.com"
   488        }
   489        #X: {
   490          if (〈1;Y〉.userinfo == _|_(explicit error (_|_ literal) in source)) {
   491            userinfo: ""
   492          }
   493          if (〈1;Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   494            userinfo: (〈2;Y〉.userinfo + "@")
   495          }
   496          host: 〈1;Y〉.host
   497        }
   498        Y: {
   499          if (〈1;#Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   500            userinfo: 〈2;#Y〉.userinfo
   501          }
   502          host: 〈1;#Y〉.host
   503        }
   504        #Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#userHostPort〉, 〈0;X〉)
   505      }
   506      p3: {
   507        X: (〈0;#X〉.userinfo + 〈0;#X〉.host)
   508        #X: {
   509          if (〈1;Y〉.userinfo == _|_(explicit error (_|_ literal) in source)) {
   510            userinfo: ""
   511          }
   512          if (〈1;Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   513            userinfo: (〈2;Y〉.userinfo + "@")
   514          }
   515          host: 〈1;Y〉.host
   516        }
   517        Y: {
   518          userinfo: "user"
   519          host: "example.com"
   520        }
   521        Y: {
   522          if (〈1;#Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   523            userinfo: 〈2;#Y〉.userinfo
   524          }
   525          host: 〈1;#Y〉.host
   526        }
   527        #Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#userHostPort〉, 〈0;X〉)
   528      }
   529      p4: {
   530        X: (〈0;#X〉.userinfo + 〈0;#X〉.host)
   531        #X: {
   532          if (〈1;Y〉.userinfo == _|_(explicit error (_|_ literal) in source)) {
   533            userinfo: ""
   534          }
   535          if (〈1;Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   536            userinfo: (〈2;Y〉.userinfo + "@")
   537          }
   538          host: 〈1;Y〉.host
   539        }
   540        Y: {
   541          if (〈1;#Y〉.userinfo != _|_(explicit error (_|_ literal) in source)) {
   542            userinfo: 〈2;#Y〉.userinfo
   543          }
   544          host: 〈1;#Y〉.host
   545        }
   546        #Y: 〈import;regexp〉.FindNamedSubmatch(〈1;#userHostPort〉, 〈0;X〉)
   547        Y: {
   548          userinfo: "user"
   549          host: "example.com"
   550        }
   551      }
   552    }
   553  }