github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/cycle/builtins.txtar (about)

     1  -- in.cue --
     2  import "regexp"
     3  
     4  // Issue #655
     5  // When evaluating a value into a struct, and then back into a value, the
     6  // evaluation mode flips from Partial to AllArcs to Back. This is typically
     7  // not an issue, but if a referred field is within a struct generated by a
     8  // builtin, effectively the entire struct needs to be evaluated and special care
     9  // should be taking to not evaluate too early.
    10  builtinCyclePerm0: {
    11  	X: "example.com"
    12  
    13  	Y: {
    14  		#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X)
    15  		host:        #components.host
    16  	}
    17  
    18  	X: Y.host
    19  }
    20  
    21  builtinCyclePerm1: {
    22  	X: Y.host
    23  
    24  	Y: {
    25  		#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X)
    26  		host:        #components.host
    27  	}
    28  
    29  	X: "example.com"
    30  }
    31  
    32  builtinCyclePerm2: {
    33  	Y: {
    34  		#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X)
    35  		host:        #components.host
    36  	}
    37  
    38  	X: Y.host
    39  	X: "example.com"
    40  }
    41  
    42  builtinCyclePerm3: {
    43  	Y: {
    44  		#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X)
    45  		host:        #components.host
    46  	}
    47  
    48  	X: "example.com"
    49  	X: Y.host
    50  }
    51  
    52  builtinCyclePerm4: {
    53  	X: "example.com"
    54  	X: Y.host
    55  
    56  	Y: {
    57  		#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X)
    58  		host:        #components.host
    59  	}
    60  }
    61  
    62  builtinCyclePerm5: {
    63  	X: Y.host
    64  	X: "example.com"
    65  
    66  	Y: {
    67  		#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X)
    68  		host:        #components.host
    69  	}
    70  }
    71  -- out/eval --
    72  (struct){
    73    builtinCyclePerm0: (struct){
    74      X: (string){ "example.com" }
    75      Y: (struct){
    76        #components: (#struct){
    77          host: (string){ "example.com" }
    78        }
    79        host: (string){ "example.com" }
    80      }
    81    }
    82    builtinCyclePerm1: (struct){
    83      X: (string){ "example.com" }
    84      Y: (struct){
    85        #components: (#struct){
    86          host: (string){ "example.com" }
    87        }
    88        host: (string){ "example.com" }
    89      }
    90    }
    91    builtinCyclePerm2: (struct){
    92      Y: (struct){
    93        #components: (#struct){
    94          host: (string){ "example.com" }
    95        }
    96        host: (string){ "example.com" }
    97      }
    98      X: (string){ "example.com" }
    99    }
   100    builtinCyclePerm3: (struct){
   101      Y: (struct){
   102        #components: (#struct){
   103          host: (string){ "example.com" }
   104        }
   105        host: (string){ "example.com" }
   106      }
   107      X: (string){ "example.com" }
   108    }
   109    builtinCyclePerm4: (struct){
   110      X: (string){ "example.com" }
   111      Y: (struct){
   112        #components: (#struct){
   113          host: (string){ "example.com" }
   114        }
   115        host: (string){ "example.com" }
   116      }
   117    }
   118    builtinCyclePerm5: (struct){
   119      X: (string){ "example.com" }
   120      Y: (struct){
   121        #components: (#struct){
   122          host: (string){ "example.com" }
   123        }
   124        host: (string){ "example.com" }
   125      }
   126    }
   127  }
   128  -- out/compile --
   129  --- in.cue
   130  {
   131    builtinCyclePerm0: {
   132      X: "example.com"
   133      Y: {
   134        #components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉)
   135        host: 〈0;#components〉.host
   136      }
   137      X: 〈0;Y〉.host
   138    }
   139    builtinCyclePerm1: {
   140      X: 〈0;Y〉.host
   141      Y: {
   142        #components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉)
   143        host: 〈0;#components〉.host
   144      }
   145      X: "example.com"
   146    }
   147    builtinCyclePerm2: {
   148      Y: {
   149        #components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉)
   150        host: 〈0;#components〉.host
   151      }
   152      X: 〈0;Y〉.host
   153      X: "example.com"
   154    }
   155    builtinCyclePerm3: {
   156      Y: {
   157        #components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉)
   158        host: 〈0;#components〉.host
   159      }
   160      X: "example.com"
   161      X: 〈0;Y〉.host
   162    }
   163    builtinCyclePerm4: {
   164      X: "example.com"
   165      X: 〈0;Y〉.host
   166      Y: {
   167        #components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉)
   168        host: 〈0;#components〉.host
   169      }
   170    }
   171    builtinCyclePerm5: {
   172      X: 〈0;Y〉.host
   173      X: "example.com"
   174      Y: {
   175        #components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉)
   176        host: 〈0;#components〉.host
   177      }
   178    }
   179  }