...

Text file src/cuelang.org/go/cue/testdata/comprehensions/for.txtar

Documentation: cuelang.org/go/cue/testdata/comprehensions

     1-- in.cue --
     2b: {for k, v in a {"\(k)": v + 1}}
     3a: {b: 1, c: 2}
     4
     5x: {for k, v in y {"\(k)": v}}
     6y: {} // check that empty struct after reference works.
     7
     8k: {for v in e {v}}
     9e: int
    10
    11comprehensionBinds: {
    12	a: {for _ in [1] {a: _}}
    13	b: {for _, _ in [1] {a: _}}
    14}
    15-- out/eval/stats --
    16Leaks:  2
    17Freed:  16
    18Reused: 12
    19Allocs: 6
    20Retain: 7
    21
    22Unifications: 18
    23Conjuncts:    18
    24Disjuncts:    21
    25-- out/eval --
    26Errors:
    27k: cannot range over e (found int, want list or struct):
    28    ./in.cue:7:14
    29
    30Result:
    31(_|_){
    32  // [eval]
    33  b: (struct){
    34    b: (int){ 2 }
    35    c: (int){ 3 }
    36  }
    37  a: (struct){
    38    b: (int){ 1 }
    39    c: (int){ 2 }
    40  }
    41  x: (struct){
    42  }
    43  y: (struct){
    44  }
    45  k: (_|_){
    46    // [eval] k: cannot range over e (found int, want list or struct):
    47    //     ./in.cue:7:14
    48  }
    49  e: (int){ int }
    50  comprehensionBinds: (struct){
    51    a: (struct){
    52      a: (_){ _ }
    53    }
    54    b: (struct){
    55      a: (_){ _ }
    56    }
    57  }
    58}
    59-- out/compile --
    60--- in.cue
    61{
    62  b: {
    63    for k, v in 〈1;a〉 {
    64      "\(〈1;k〉)": (〈1;v〉 + 1)
    65    }
    66  }
    67  a: {
    68    b: 1
    69    c: 2
    70  }
    71  x: {
    72    for k, v in 〈1;y〉 {
    73      "\(〈1;k〉)": 〈1;v〉
    74    }
    75  }
    76  y: {}
    77  k: {
    78    for _, v in 〈1;e〉 {
    79      〈1;v〉
    80    }
    81  }
    82  e: int
    83  comprehensionBinds: {
    84    a: {
    85      for _, _ in [
    86        1,
    87      ] {
    88        a: _
    89      }
    90    }
    91    b: {
    92      for _, _ in [
    93        1,
    94      ] {
    95        a: _
    96      }
    97    }
    98  }
    99}

View as plain text