...

Text file src/cuelang.org/go/pkg/list/testdata/list.txtar

Documentation: cuelang.org/go/pkg/list/testdata

     1-- in.cue --
     2import "list"
     3
     4repeat: {
     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}
    19concat: {
    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}
    34unique: {
    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// Issue #2099
    45minItems: {
    46	[string]: list.MinItems(1)
    47	incomplete1: [...]
    48	fail1: []
    49	ok1: [0, ...]
    50	ok2: [0]
    51}
    52
    53maxItems: {
    54	[string]: list.MaxItems(1)
    55	ok1: [...]
    56	ok2: [0, ...]
    57	ok3: [0, ...]
    58
    59	fail1: [0, 1]
    60}
    61
    62-- out/list --
    63Errors:
    64repeat.t8.v: error in call to list.Repeat: negative count:
    65    ./in.cue:4:30
    66concat.t8.v: error in call to list.Concat: cannot use value 1 (type int) as list:
    67    ./in.cue:19:22
    68    ./in.cue:31:10
    69concat.t7.v: cannot use 1 (type int) as list in argument 1 to list.Concat:
    70    ./in.cue:30:9
    71minItems.fail1: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
    72    ./in.cue:45:12
    73    ./in.cue:45:26
    74    ./in.cue:47:9
    75maxItems.fail1: invalid value [0,1] (does not satisfy list.MaxItems(1)): len(list) > MaxItems(1) (2 > 1):
    76    ./in.cue:53:12
    77    ./in.cue:53:26
    78    ./in.cue:58:9
    79
    80Result:
    81import "list"
    82
    83repeat: {
    84	t1: {
    85		x: []
    86		n: 0
    87		v: []
    88	}
    89	t2: {
    90		x: [1]
    91		n: 0
    92		v: []
    93	}
    94	t3: {
    95		x: [1]
    96		n: 1
    97		v: [1]
    98	}
    99	t4: {
   100		x: [1, 2]
   101		n: 1
   102		v: [1, 2]
   103	}
   104	t5: {
   105		x: []
   106		n: 3
   107		v: []
   108	}
   109	t6: {
   110		x: [1, 2]
   111		n: 3
   112		v: [1, 2, 1, 2, 1, 2]
   113	}
   114	t7: {
   115		x: [1, 2, 3, 4]
   116		n: 3
   117		v: [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
   118	}
   119	t8: {
   120		x: [1]
   121		n: -1
   122		v: _|_ // repeat.t8.v: error in call to list.Repeat: negative count
   123	}
   124}
   125concat: {
   126	t1: {
   127		x: []
   128		v: []
   129	}
   130	t2: {
   131		x: [[]]
   132		v: []
   133	}
   134	t3: {
   135		x: [[1]]
   136		v: [1]
   137	}
   138	t4: {
   139		x: [[1, 2]]
   140		v: [1, 2]
   141	}
   142	t5: {
   143		x: [[1], [2]]
   144		v: [1, 2]
   145	}
   146	t6: {
   147		x: [[1, 2], [3, 4]]
   148		v: [1, 2, 3, 4]
   149	}
   150	t7: {
   151		x: 1
   152		v: _|_ // concat.t7.v: cannot use 1 (type int) as list in argument 1 to list.Concat
   153	}
   154	t8: {
   155		x: [1, [2]]
   156		v: _|_ // concat.t8.v: error in call to list.Concat: cannot use value 1 (type int) as list
   157	}
   158}
   159unique: {
   160	issue797: {
   161		mylst: [{
   162			foo: "bar"
   163		}, {
   164			foo: "baz"
   165		}]
   166	}
   167}
   168// Issue #2099
   169minItems: {
   170	incomplete1: [...] & list.MinItems(1)
   171	fail1: _|_ // minItems.fail1: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1) (and 1 more errors)
   172	ok1: [0, ...]
   173	ok2: [0]
   174}
   175maxItems: {
   176	ok1: [...]
   177	ok2: [0, ...]
   178	ok3: [0, ...]
   179	fail1: _|_ // maxItems.fail1: invalid value [0,1] (does not satisfy list.MaxItems(1)): len(list) > MaxItems(1) (2 > 1) (and 1 more errors)
   180}

View as plain text