cuelang.org/go@v0.13.0/cue/testdata/resolve/048_builtins.txtar (about)

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