github.com/solo-io/cue@v0.4.7/cue/testdata/references/index.txtar (about)

     1  -- in.cue --
     2  intIndex:    [2][0]
     3  stringIndex: {foo: "bar"}["foo"]
     4  
     5  stringOfNumberIndex: {"3": 3}["3"]
     6  
     7  indexToDefault:        (*[0] | {})[0]
     8  outOfBoundsDisjunction: (*[] | {})[1]
     9  
    10  // Ensure these are errors.
    11  indexDoesNotDistribute:     (*[] | [1])[0]
    12  doesNotDistributeType: {
    13      l: []
    14      a: (*l | {"3": 3})["3"]
    15  }
    16  
    17  stringIndexToList: [2][""]
    18  indexOutOfBounds2: 2[2]
    19  booleanIndex: [][true]
    20  indexOutOfBounds3: [1, 2, 3][4]
    21  negativeIndex: [1, 2, 3][-1]
    22  
    23  varIndexTooLarge: {
    24      n: 3
    25      a: [1, 2, 3][n]
    26  }
    27  
    28  varNegativeIndex: {
    29      n: -1
    30      a: [1, 2, 3][n]
    31  }
    32  -- out/eval --
    33  Errors:
    34  outOfBoundsDisjunction: invalid list index 1 (out of bounds):
    35      ./in.cue:7:36
    36  indexDoesNotDistribute: index out of range [0] with length 0:
    37      ./in.cue:10:41
    38  doesNotDistributeType.a: invalid list index "3" (type string):
    39      ./in.cue:13:24
    40  stringIndexToList: invalid list index "" (type string):
    41      ./in.cue:16:24
    42  indexOutOfBounds2: invalid operand 2 (found int, want list or struct):
    43      ./in.cue:17:20
    44  booleanIndex: invalid index true (invalid type bool):
    45      ./in.cue:18:15
    46      ./in.cue:18:18
    47  indexOutOfBounds3: invalid list index 4 (out of bounds):
    48      ./in.cue:19:30
    49  negativeIndex: invalid index -1 (index must be non-negative):
    50      ./in.cue:20:16
    51      ./in.cue:20:26
    52  varIndexTooLarge.a: index out of range [3] with length 3:
    53      ./in.cue:24:18
    54  varNegativeIndex.a: index n out of range [-1]:
    55      ./in.cue:29:8
    56      ./in.cue:28:8
    57      ./in.cue:29:18
    58  
    59  Result:
    60  (_|_){
    61    // [eval]
    62    intIndex: (int){ 2 }
    63    stringIndex: (string){ "bar" }
    64    stringOfNumberIndex: (int){ 3 }
    65    indexToDefault: (int){ 0 }
    66    outOfBoundsDisjunction: (_|_){
    67      // [eval] outOfBoundsDisjunction: invalid list index 1 (out of bounds):
    68      //     ./in.cue:7:36
    69    }
    70    indexDoesNotDistribute: (_|_){
    71      // [eval] indexDoesNotDistribute: index out of range [0] with length 0:
    72      //     ./in.cue:10:41
    73    }
    74    doesNotDistributeType: (_|_){
    75      // [eval]
    76      l: (#list){
    77      }
    78      a: (_|_){
    79        // [eval] doesNotDistributeType.a: invalid list index "3" (type string):
    80        //     ./in.cue:13:24
    81      }
    82    }
    83    stringIndexToList: (_|_){
    84      // [eval] stringIndexToList: invalid list index "" (type string):
    85      //     ./in.cue:16:24
    86    }
    87    indexOutOfBounds2: (_|_){
    88      // [eval] indexOutOfBounds2: invalid operand 2 (found int, want list or struct):
    89      //     ./in.cue:17:20
    90    }
    91    booleanIndex: (_|_){
    92      // [eval] booleanIndex: invalid index true (invalid type bool):
    93      //     ./in.cue:18:15
    94      //     ./in.cue:18:18
    95    }
    96    indexOutOfBounds3: (_|_){
    97      // [eval] indexOutOfBounds3: invalid list index 4 (out of bounds):
    98      //     ./in.cue:19:30
    99    }
   100    negativeIndex: (_|_){
   101      // [eval] negativeIndex: invalid index -1 (index must be non-negative):
   102      //     ./in.cue:20:16
   103      //     ./in.cue:20:26
   104    }
   105    varIndexTooLarge: (_|_){
   106      // [eval]
   107      n: (int){ 3 }
   108      a: (_|_){
   109        // [eval] varIndexTooLarge.a: index out of range [3] with length 3:
   110        //     ./in.cue:24:18
   111      }
   112    }
   113    varNegativeIndex: (_|_){
   114      // [eval]
   115      n: (int){ -1 }
   116      a: (_|_){
   117        // [eval] varNegativeIndex.a: index n out of range [-1]:
   118        //     ./in.cue:29:8
   119        //     ./in.cue:28:8
   120        //     ./in.cue:29:18
   121      }
   122    }
   123  }
   124  -- out/compile --
   125  --- in.cue
   126  {
   127    intIndex: [
   128      2,
   129    ][0]
   130    stringIndex: {
   131      foo: "bar"
   132    }["foo"]
   133    stringOfNumberIndex: {
   134      "3": 3
   135    }["3"]
   136    indexToDefault: (*[
   137      0,
   138    ]|{})[0]
   139    outOfBoundsDisjunction: (*[]|{})[1]
   140    indexDoesNotDistribute: (*[]|[
   141      1,
   142    ])[0]
   143    doesNotDistributeType: {
   144      l: []
   145      a: (*〈0;l〉|{
   146        "3": 3
   147      })["3"]
   148    }
   149    stringIndexToList: [
   150      2,
   151    ][""]
   152    indexOutOfBounds2: 2[2]
   153    booleanIndex: [][true]
   154    indexOutOfBounds3: [
   155      1,
   156      2,
   157      3,
   158    ][4]
   159    negativeIndex: [
   160      1,
   161      2,
   162      3,
   163    ][-1]
   164    varIndexTooLarge: {
   165      n: 3
   166      a: [
   167        1,
   168        2,
   169        3,
   170      ][〈0;n〉]
   171    }
   172    varNegativeIndex: {
   173      n: -1
   174      a: [
   175        1,
   176        2,
   177        3,
   178      ][〈0;n〉]
   179    }
   180  }