cuelang.org/go@v0.13.0/cue/testdata/fulleval/016_struct_comprehension_with_template.txtar (about)

     1  #name: struct comprehension with template
     2  #evalFull
     3  -- in.cue --
     4  result: [for _, v in service {v}]
     5  
     6  service: [Name=string]: {
     7  	name: *Name | string
     8  	type: "service"
     9  	port: *7080 | int
    10  }
    11  service: foo: {}
    12  service: bar: {port: 8000}
    13  service: baz: {name: "foobar"}
    14  -- out/def --
    15  result: [{
    16  	name: *"foo" | string
    17  	type: "service"
    18  	port: *7080 | int
    19  }, {
    20  	name: *"bar" | string
    21  	type: "service"
    22  	port: 8000
    23  }, {
    24  	name: "foobar"
    25  	type: "service"
    26  	port: *7080 | int
    27  }]
    28  service: {
    29  	{[Name=string]: {
    30  		name: *Name | string, type: "service", port: *7080 | int
    31  	}}
    32  	foo: {
    33  		name: *"foo" | string
    34  		type: "service"
    35  		port: *7080 | int
    36  	}
    37  	bar: {
    38  		name: *"bar" | string
    39  		type: "service"
    40  		port: 8000
    41  	}
    42  	baz: {
    43  		name: "foobar"
    44  		type: "service"
    45  		port: *7080 | int
    46  	}
    47  }
    48  -- out/export --
    49  result: [{
    50  	name: "foo"
    51  	type: "service"
    52  	port: 7080
    53  }, {
    54  	name: "bar"
    55  	type: "service"
    56  	port: 8000
    57  }, {
    58  	name: "foobar"
    59  	type: "service"
    60  	port: 7080
    61  }]
    62  service: {
    63  	foo: {
    64  		name: "foo"
    65  		type: "service"
    66  		port: 7080
    67  	}
    68  	bar: {
    69  		name: "bar"
    70  		type: "service"
    71  		port: 8000
    72  	}
    73  	baz: {
    74  		name: "foobar"
    75  		type: "service"
    76  		port: 7080
    77  	}
    78  }
    79  -- out/yaml --
    80  result:
    81  - name: foo
    82    type: service
    83    port: 7080
    84  - name: bar
    85    type: service
    86    port: 8000
    87  - name: foobar
    88    type: service
    89    port: 7080
    90  service:
    91    foo:
    92      name: foo
    93      type: service
    94      port: 7080
    95    bar:
    96      name: bar
    97      type: service
    98      port: 8000
    99    baz:
   100      name: foobar
   101      type: service
   102      port: 7080
   103  -- out/json --
   104  {"result":[{"name":"foo","type":"service","port":7080},{"name":"bar","type":"service","port":8000},{"name":"foobar","type":"service","port":7080}],"service":{"foo":{"name":"foo","type":"service","port":7080},"bar":{"name":"bar","type":"service","port":8000},"baz":{"name":"foobar","type":"service","port":7080}}}
   105  -- out/legacy-debug --
   106  <0>{result: [<1>{name: "foo", type: "service", port: 7080},<2>{name: "bar", type: "service", port: 8000},<3>{name: "foobar", type: "service", port: 7080}], service: <4>{[]: <5>(Name: string)-><6>{name: (*<5>.Name | string), type: "service", port: (*7080 | int)}, foo: <7>{name: "foo", type: "service", port: 7080}, bar: <8>{name: "bar", type: "service", port: 8000}, baz: <9>{name: "foobar", type: "service", port: 7080}}}
   107  -- out/compile --
   108  --- in.cue
   109  {
   110    result: [
   111      for _, v in 〈1;service〉 {
   112        〈1;v〉
   113      },
   114    ]
   115    service: {
   116      [string]: {
   117        name: (*〈1;-〉|string)
   118        type: "service"
   119        port: (*7080|int)
   120      }
   121    }
   122    service: {
   123      foo: {}
   124    }
   125    service: {
   126      bar: {
   127        port: 8000
   128      }
   129    }
   130    service: {
   131      baz: {
   132        name: "foobar"
   133      }
   134    }
   135  }
   136  -- out/eval/stats --
   137  Leaks:  0
   138  Freed:  51
   139  Reused: 43
   140  Allocs: 8
   141  Retain: 4
   142  
   143  Unifications: 27
   144  Conjuncts:    70
   145  Disjuncts:    55
   146  -- out/eval --
   147  (struct){
   148    result: (#list){
   149      0: (struct){
   150        name: (string){ |(*(string){ "foo" }, (string){ string }) }
   151        type: (string){ "service" }
   152        port: (int){ |(*(int){ 7080 }, (int){ int }) }
   153      }
   154      1: (struct){
   155        port: (int){ 8000 }
   156        name: (string){ |(*(string){ "bar" }, (string){ string }) }
   157        type: (string){ "service" }
   158      }
   159      2: (struct){
   160        name: (string){ "foobar" }
   161        type: (string){ "service" }
   162        port: (int){ |(*(int){ 7080 }, (int){ int }) }
   163      }
   164    }
   165    service: (struct){
   166      foo: (struct){
   167        name: (string){ |(*(string){ "foo" }, (string){ string }) }
   168        type: (string){ "service" }
   169        port: (int){ |(*(int){ 7080 }, (int){ int }) }
   170      }
   171      bar: (struct){
   172        port: (int){ 8000 }
   173        name: (string){ |(*(string){ "bar" }, (string){ string }) }
   174        type: (string){ "service" }
   175      }
   176      baz: (struct){
   177        name: (string){ "foobar" }
   178        type: (string){ "service" }
   179        port: (int){ |(*(int){ 7080 }, (int){ int }) }
   180      }
   181    }
   182  }