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

     1  -- in.cue --
     2  import "list"
     3  
     4  repeat: {
     5  	[string]: {x: _, n: int, v: list.Repeat(x, n)}
     6  
     7  	t1: {x: [], n: 0}
     8  	t2: {x: [1], n: 0}
     9  
    10  	t3: {x: [1], n: 1}
    11  	t4: {x: [1, 2], n: 1}
    12  
    13  	t5: {x: [], n: 3}
    14  	t6: {x: [1, 2], n: 3}
    15  	t7: {x: [1, 2, 3, 4], n: 3}
    16  
    17  	t8: {x: [1], n: -1}
    18  }
    19  concat: {
    20  	[string]: {x: _, v: list.Concat(x)}
    21  
    22  	t1: x: []
    23  	t2: x: [[]]
    24  
    25  	t3: x: [[1]]
    26  	t4: x: [[1, 2]]
    27  	t5: x: [[1], [2]]
    28  
    29  	t6: x: [[1, 2], [3, 4]]
    30  
    31  	t7: x: 1
    32  	t8: x: [1, [2]]
    33  }
    34  unique: {
    35  	issue797: {
    36  		mylst: [
    37  			{foo: "bar"},
    38  			{foo: "baz"},
    39  		]
    40  
    41  		_testmylst: list.UniqueItems & [ for x in mylst {x.foo}]
    42  	}
    43  }
    44  -- out/list --
    45  Errors:
    46  error in call to list.Repeat: negative count:
    47      ./in.cue:4:30
    48  error in call to list.Concat: cannot use value 1 (type int) as list:
    49      ./in.cue:19:22
    50      ./in.cue:31:10
    51  concat.t7.v: cannot use 1 (type int) as list in argument 1 to list.Concat:
    52      ./in.cue:30:9
    53  
    54  Result:
    55  repeat: {
    56  	t1: {
    57  		x: []
    58  		n: 0
    59  		v: []
    60  	}
    61  	t2: {
    62  		x: [1]
    63  		n: 0
    64  		v: []
    65  	}
    66  	t3: {
    67  		x: [1]
    68  		n: 1
    69  		v: [1]
    70  	}
    71  	t4: {
    72  		x: [1, 2]
    73  		n: 1
    74  		v: [1, 2]
    75  	}
    76  	t5: {
    77  		x: []
    78  		n: 3
    79  		v: []
    80  	}
    81  	t6: {
    82  		x: [1, 2]
    83  		n: 3
    84  		v: [1, 2, 1, 2, 1, 2]
    85  	}
    86  	t7: {
    87  		x: [1, 2, 3, 4]
    88  		n: 3
    89  		v: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
    90  	}
    91  	t8: {
    92  		x: [1]
    93  		n: -1
    94  		v: _|_ // error in call to list.Repeat: negative count
    95  	}
    96  }
    97  concat: {
    98  	t1: {
    99  		x: []
   100  		v: []
   101  	}
   102  	t2: {
   103  		x: [[]]
   104  		v: []
   105  	}
   106  	t3: {
   107  		x: [[1]]
   108  		v: [1]
   109  	}
   110  	t4: {
   111  		x: [[1, 2]]
   112  		v: [1, 2]
   113  	}
   114  	t5: {
   115  		x: [[1], [2]]
   116  		v: [1, 2]
   117  	}
   118  	t6: {
   119  		x: [[1, 2], [3, 4]]
   120  		v: [1, 2, 3, 4]
   121  	}
   122  	t7: {
   123  		x: 1
   124  		v: _|_ // concat.t7.v: cannot use 1 (type int) as list in argument 1 to list.Concat
   125  	}
   126  	t8: {
   127  		x: [1, [2]]
   128  		v: _|_ // error in call to list.Concat: cannot use value 1 (type int) as list
   129  	}
   130  }
   131  unique: {
   132  	issue797: {
   133  		mylst: [{
   134  			foo: "bar"
   135  		}, {
   136  			foo: "baz"
   137  		}]
   138  	}
   139  }
   140