cuelang.org/go@v0.13.0/cue/testdata/definitions/exclude.txtar (about)

     1  -- in.cue --
     2  package p
     3  
     4  excludeLet: {
     5  	// Two lets with the same name should not unify and checked by definition.
     6  	#D: { let X = {}, #foo: X, f: _ }
     7  	a: #D
     8  	a: { let X = { a: 1 }, f: X }
     9  }
    10  
    11  definition: {
    12  	// Check a definition only if it s contained withing a definition.
    13  	err1: {
    14  		#D: { #foo: a: int }
    15  		a: #D
    16  		a: { #foo: b: int }
    17  	}
    18  	ok1: {
    19  		#D: {}
    20  		a: #D
    21  		a: { #foo: b: int }
    22  	}
    23  }
    24  
    25  hidden: {
    26  	// Check a hidden field only if it s contained withing a definition.
    27  	err1: {
    28  		#D: { _foo: a: int }
    29  		a: #D
    30  		a: { _foo: b: int }
    31  	}
    32  	ok1: {
    33  		#D: {}
    34  		a: #D
    35  		a: { _foo: b: int }
    36  	}
    37  }
    38  -- regress.cue --
    39  package p
    40  
    41  import "encoding/json"
    42  
    43  definition: ok1: {
    44  	org: #Org & {
    45  		#Employee: username: string
    46  	}
    47  	#Org: employees?: [string]: username!: string
    48  }
    49  
    50  definition: ok2: {
    51  	#Tree: {
    52  		#Leaf: leaf: string
    53  		#Branch: branch?: #Leaf
    54  		root: #Branch
    55  	}
    56  	out: json.Marshal(#Tree & {root: {}})
    57  }
    58  
    59  hidden: ok1: {
    60  	out: #Workflow & {
    61  		_hidden: #step & {
    62  			run: "foo bar"
    63  		}
    64  	}
    65  	#Workflow: {
    66  	}
    67  	#step: matchN(1, [{
    68  		"run"!: _
    69  	}])
    70  }
    71  -- out/eval/stats --
    72  Leaks:  1
    73  Freed:  78
    74  Reused: 70
    75  Allocs: 9
    76  Retain: 7
    77  
    78  Unifications: 79
    79  Conjuncts:    120
    80  Disjuncts:    85
    81  -- out/evalalpha --
    82  Errors:
    83  definition.err1.a.#foo.b: field not allowed:
    84      ./in.cue:15:14
    85  hidden.err1.a._foo.b: field not allowed:
    86      ./in.cue:29:14
    87  
    88  Result:
    89  (_|_){
    90    // [eval]
    91    excludeLet: (struct){
    92      #D: (#struct){
    93        let X#1 = (#struct){
    94        }
    95        #foo: (#struct){
    96        }
    97        f: (_){ _ }
    98      }
    99      a: (#struct){
   100        let X#2 = (struct){
   101          a: (int){ 1 }
   102        }
   103        f: (#struct){
   104          a: (int){ 1 }
   105        }
   106        let X#1 = (#struct){
   107        }
   108        #foo: (#struct){
   109        }
   110      }
   111    }
   112    definition: (_|_){
   113      // [eval]
   114      err1: (_|_){
   115        // [eval]
   116        #D: (#struct){
   117          #foo: (#struct){
   118            a: (int){ int }
   119          }
   120        }
   121        a: (_|_){
   122          // [eval]
   123          #foo: (_|_){
   124            // [eval]
   125            b: (_|_){
   126              // [eval] definition.err1.a.#foo.b: field not allowed:
   127              //     ./in.cue:15:14
   128            }
   129            a: (int){ int }
   130          }
   131        }
   132      }
   133      ok1: (struct){
   134        #D: (#struct){
   135        }
   136        a: (#struct){
   137          #foo: (#struct){
   138            b: (int){ int }
   139          }
   140        }
   141        org: (#struct){
   142          #Employee: (#struct){
   143            username: (string){ string }
   144          }
   145          employees?: (#struct){
   146          }
   147        }
   148        #Org: (#struct){
   149          employees?: (#struct){
   150          }
   151        }
   152      }
   153      ok2: (struct){
   154        #Tree: (#struct){
   155          #Leaf: (#struct){
   156            leaf: (string){ string }
   157          }
   158          #Branch: (#struct){
   159            branch?: ~(definition.ok2.#Tree.#Leaf)
   160          }
   161          root: ~(definition.ok2.#Tree.#Branch)
   162        }
   163        out: (string){ "{\"root\":{}}" }
   164      }
   165    }
   166    hidden: (_|_){
   167      // [eval]
   168      err1: (_|_){
   169        // [eval]
   170        #D: (#struct){
   171          _foo(:p): (#struct){
   172            a: (int){ int }
   173          }
   174        }
   175        a: (_|_){
   176          // [eval]
   177          _foo(:p): (_|_){
   178            // [eval]
   179            b: (_|_){
   180              // [eval] hidden.err1.a._foo.b: field not allowed:
   181              //     ./in.cue:29:14
   182            }
   183            a: (int){ int }
   184          }
   185        }
   186      }
   187      ok1: (struct){
   188        #D: (#struct){
   189        }
   190        a: (#struct){
   191          _foo(:p): (struct){
   192            b: (int){ int }
   193          }
   194        }
   195        out: (#struct){
   196          _hidden(:p): (#struct){
   197            run: (string){ "foo bar" }
   198          }
   199        }
   200        #Workflow: (#struct){
   201        }
   202        #step: (_){ matchN(1, (#list){
   203            0: (_|_){// {
   204              //   run!: _
   205              // }
   206            }
   207          }) }
   208      }
   209    }
   210  }
   211  -- diff/-out/evalalpha<==>+out/eval --
   212  diff old new
   213  --- old
   214  +++ new
   215  @@ -1,11 +1,7 @@
   216   Errors:
   217   definition.err1.a.#foo.b: field not allowed:
   218  -    ./in.cue:13:15
   219  -    ./in.cue:14:6
   220       ./in.cue:15:14
   221   hidden.err1.a._foo.b: field not allowed:
   222  -    ./in.cue:27:15
   223  -    ./in.cue:28:6
   224       ./in.cue:29:14
   225   
   226   Result:
   227  @@ -20,16 +16,16 @@
   228         f: (_){ _ }
   229       }
   230       a: (#struct){
   231  -      let X#1 = (#struct){
   232  -      }
   233  -      #foo: (#struct){
   234  -      }
   235  -      f: (struct){
   236  -        a: (int){ 1 }
   237  -      }
   238         let X#2 = (struct){
   239           a: (int){ 1 }
   240         }
   241  +      f: (#struct){
   242  +        a: (int){ 1 }
   243  +      }
   244  +      let X#1 = (#struct){
   245  +      }
   246  +      #foo: (#struct){
   247  +      }
   248       }
   249     }
   250     definition: (_|_){
   251  @@ -45,13 +41,11 @@
   252           // [eval]
   253           #foo: (_|_){
   254             // [eval]
   255  -          a: (int){ int }
   256             b: (_|_){
   257               // [eval] definition.err1.a.#foo.b: field not allowed:
   258  -            //     ./in.cue:13:15
   259  -            //     ./in.cue:14:6
   260               //     ./in.cue:15:14
   261             }
   262  +          a: (int){ int }
   263           }
   264         }
   265       }
   266  @@ -64,11 +58,11 @@
   267           }
   268         }
   269         org: (#struct){
   270  -        employees?: (#struct){
   271  -        }
   272           #Employee: (#struct){
   273             username: (string){ string }
   274           }
   275  +        employees?: (#struct){
   276  +        }
   277         }
   278         #Org: (#struct){
   279           employees?: (#struct){
   280  @@ -81,15 +75,9 @@
   281             leaf: (string){ string }
   282           }
   283           #Branch: (#struct){
   284  -          branch?: (#struct){
   285  -            leaf: (string){ string }
   286  -          }
   287  -        }
   288  -        root: (#struct){
   289  -          branch?: (#struct){
   290  -            leaf: (string){ string }
   291  -          }
   292  -        }
   293  +          branch?: ~(definition.ok2.#Tree.#Leaf)
   294  +        }
   295  +        root: ~(definition.ok2.#Tree.#Branch)
   296         }
   297         out: (string){ "{\"root\":{}}" }
   298       }
   299  @@ -107,13 +95,11 @@
   300           // [eval]
   301           _foo(:p): (_|_){
   302             // [eval]
   303  -          a: (int){ int }
   304             b: (_|_){
   305               // [eval] hidden.err1.a._foo.b: field not allowed:
   306  -            //     ./in.cue:27:15
   307  -            //     ./in.cue:28:6
   308               //     ./in.cue:29:14
   309             }
   310  +          a: (int){ int }
   311           }
   312         }
   313       }
   314  @@ -126,7 +112,7 @@
   315           }
   316         }
   317         out: (#struct){
   318  -        _hidden(:p): (struct){
   319  +        _hidden(:p): (#struct){
   320             run: (string){ "foo bar" }
   321           }
   322         }
   323  -- out/eval --
   324  Errors:
   325  definition.err1.a.#foo.b: field not allowed:
   326      ./in.cue:13:15
   327      ./in.cue:14:6
   328      ./in.cue:15:14
   329  hidden.err1.a._foo.b: field not allowed:
   330      ./in.cue:27:15
   331      ./in.cue:28:6
   332      ./in.cue:29:14
   333  
   334  Result:
   335  (_|_){
   336    // [eval]
   337    excludeLet: (struct){
   338      #D: (#struct){
   339        let X#1 = (#struct){
   340        }
   341        #foo: (#struct){
   342        }
   343        f: (_){ _ }
   344      }
   345      a: (#struct){
   346        let X#1 = (#struct){
   347        }
   348        #foo: (#struct){
   349        }
   350        f: (struct){
   351          a: (int){ 1 }
   352        }
   353        let X#2 = (struct){
   354          a: (int){ 1 }
   355        }
   356      }
   357    }
   358    definition: (_|_){
   359      // [eval]
   360      err1: (_|_){
   361        // [eval]
   362        #D: (#struct){
   363          #foo: (#struct){
   364            a: (int){ int }
   365          }
   366        }
   367        a: (_|_){
   368          // [eval]
   369          #foo: (_|_){
   370            // [eval]
   371            a: (int){ int }
   372            b: (_|_){
   373              // [eval] definition.err1.a.#foo.b: field not allowed:
   374              //     ./in.cue:13:15
   375              //     ./in.cue:14:6
   376              //     ./in.cue:15:14
   377            }
   378          }
   379        }
   380      }
   381      ok1: (struct){
   382        #D: (#struct){
   383        }
   384        a: (#struct){
   385          #foo: (#struct){
   386            b: (int){ int }
   387          }
   388        }
   389        org: (#struct){
   390          employees?: (#struct){
   391          }
   392          #Employee: (#struct){
   393            username: (string){ string }
   394          }
   395        }
   396        #Org: (#struct){
   397          employees?: (#struct){
   398          }
   399        }
   400      }
   401      ok2: (struct){
   402        #Tree: (#struct){
   403          #Leaf: (#struct){
   404            leaf: (string){ string }
   405          }
   406          #Branch: (#struct){
   407            branch?: (#struct){
   408              leaf: (string){ string }
   409            }
   410          }
   411          root: (#struct){
   412            branch?: (#struct){
   413              leaf: (string){ string }
   414            }
   415          }
   416        }
   417        out: (string){ "{\"root\":{}}" }
   418      }
   419    }
   420    hidden: (_|_){
   421      // [eval]
   422      err1: (_|_){
   423        // [eval]
   424        #D: (#struct){
   425          _foo(:p): (#struct){
   426            a: (int){ int }
   427          }
   428        }
   429        a: (_|_){
   430          // [eval]
   431          _foo(:p): (_|_){
   432            // [eval]
   433            a: (int){ int }
   434            b: (_|_){
   435              // [eval] hidden.err1.a._foo.b: field not allowed:
   436              //     ./in.cue:27:15
   437              //     ./in.cue:28:6
   438              //     ./in.cue:29:14
   439            }
   440          }
   441        }
   442      }
   443      ok1: (struct){
   444        #D: (#struct){
   445        }
   446        a: (#struct){
   447          _foo(:p): (struct){
   448            b: (int){ int }
   449          }
   450        }
   451        out: (#struct){
   452          _hidden(:p): (struct){
   453            run: (string){ "foo bar" }
   454          }
   455        }
   456        #Workflow: (#struct){
   457        }
   458        #step: (_){ matchN(1, (#list){
   459            0: (_|_){// {
   460              //   run!: _
   461              // }
   462            }
   463          }) }
   464      }
   465    }
   466  }
   467  -- out/compile --
   468  --- in.cue
   469  {
   470    excludeLet: {
   471      #D: {
   472        let X#1 = {}
   473        #foo: 〈0;let X#1〉
   474        f: _
   475      }
   476      a: 〈0;#D〉
   477      a: {
   478        let X#2 = {
   479          a: 1
   480        }
   481        f: 〈0;let X#2〉
   482      }
   483    }
   484    definition: {
   485      err1: {
   486        #D: {
   487          #foo: {
   488            a: int
   489          }
   490        }
   491        a: 〈0;#D〉
   492        a: {
   493          #foo: {
   494            b: int
   495          }
   496        }
   497      }
   498      ok1: {
   499        #D: {}
   500        a: 〈0;#D〉
   501        a: {
   502          #foo: {
   503            b: int
   504          }
   505        }
   506      }
   507    }
   508    hidden: {
   509      err1: {
   510        #D: {
   511          _foo: {
   512            a: int
   513          }
   514        }
   515        a: 〈0;#D〉
   516        a: {
   517          _foo: {
   518            b: int
   519          }
   520        }
   521      }
   522      ok1: {
   523        #D: {}
   524        a: 〈0;#D〉
   525        a: {
   526          _foo: {
   527            b: int
   528          }
   529        }
   530      }
   531    }
   532  }
   533  --- regress.cue
   534  {
   535    definition: {
   536      ok1: {
   537        org: (〈0;#Org〉 & {
   538          #Employee: {
   539            username: string
   540          }
   541        })
   542        #Org: {
   543          employees?: {
   544            [string]: {
   545              username!: string
   546            }
   547          }
   548        }
   549      }
   550    }
   551    definition: {
   552      ok2: {
   553        #Tree: {
   554          #Leaf: {
   555            leaf: string
   556          }
   557          #Branch: {
   558            branch?: 〈1;#Leaf〉
   559          }
   560          root: 〈0;#Branch〉
   561        }
   562        out: 〈import;"encoding/json"〉.Marshal((〈0;#Tree〉 & {
   563          root: {}
   564        }))
   565      }
   566    }
   567    hidden: {
   568      ok1: {
   569        out: (〈0;#Workflow〉 & {
   570          _hidden: (〈1;#step〉 & {
   571            run: "foo bar"
   572          })
   573        })
   574        #Workflow: {}
   575        #step: matchN(1, [
   576          {
   577            run!: _
   578          },
   579        ])
   580      }
   581    }
   582  }