cuelang.org/go@v0.10.1/cue/testdata/comprehensions/nested2.txtar (about)

     1  -- in.cue --
     2  given: {
     3  	INC: USD: 2.0
     4  	USD: GBP: 3.0
     5  }
     6  hydrated: {
     7  	for k, v in given {
     8  		for k1, r in v {
     9  			"\(k)": "\(k)":   1.0
    10  			"\(k1)": "\(k1)": 1.0
    11  			"\(k)": "\(k1)":  r
    12  			"\(k1)": "\(k)":  number
    13  		}
    14  	}
    15  }
    16  
    17  foo: {
    18  	a: 10
    19  	if a < 20 {
    20  		if a < 50 {
    21  			b: 20
    22  		}
    23  	}
    24  }
    25  
    26  indirectlyNested: {
    27  	a: true // must be declared outside of the nested comprehensions for test.
    28  	if true {
    29  		b: {
    30  			if a {
    31  				a
    32  			}
    33  		}
    34  	}
    35  }
    36  
    37  directlyNestedEmpty: {
    38  	a: true
    39  	if true {
    40  		if a {
    41  		}
    42  	}
    43  }
    44  
    45  directlyDoublyNestedEmpty: {
    46  	a: true 
    47  	if true {
    48  		if a {
    49  		}
    50  	}
    51  }
    52  
    53  indirectlyDoublyNestedEmpty: {
    54  	a: true
    55  	b: {
    56  		if true {
    57  			if a {
    58  				if a {
    59  					a
    60  				}
    61  			}
    62  			if a {
    63  				a
    64  			}
    65  		}
    66  	}
    67  }
    68  
    69  indirectlyDoublyNested: {
    70  	a: true
    71  	if true {
    72  		if a {
    73  			if a {
    74  				b: 1
    75  			}
    76  		}
    77  		if a {
    78  			c: 1
    79  		}
    80  	}
    81  }
    82  
    83  // This case used to trigger an over-aggressive deduplication.
    84  issue1974: {
    85  	X: {
    86  		foo: {
    87  			bar: ""
    88  			baz: ""
    89  		}
    90  	}
    91  	out: {
    92  		for k, v in X for vk, vv in v {
    93  			"\(k)": "\(vk)": vv
    94  		}
    95  	}
    96  }
    97  
    98  -- out/eval/stats --
    99  Leaks:  0
   100  Freed:  43
   101  Reused: 38
   102  Allocs: 5
   103  Retain: 4
   104  
   105  Unifications: 43
   106  Conjuncts:    74
   107  Disjuncts:    43
   108  -- out/eval --
   109  (struct){
   110    given: (struct){
   111      INC: (struct){
   112        USD: (float){ 2.0 }
   113      }
   114      USD: (struct){
   115        GBP: (float){ 3.0 }
   116      }
   117    }
   118    hydrated: (struct){
   119      INC: (struct){
   120        INC: (float){ 1.0 }
   121        USD: (float){ 2.0 }
   122      }
   123      USD: (struct){
   124        USD: (float){ 1.0 }
   125        INC: (number){ number }
   126        GBP: (float){ 3.0 }
   127      }
   128      GBP: (struct){
   129        GBP: (float){ 1.0 }
   130        USD: (number){ number }
   131      }
   132    }
   133    foo: (struct){
   134      a: (int){ 10 }
   135      b: (int){ 20 }
   136    }
   137    indirectlyNested: (struct){
   138      a: (bool){ true }
   139      b: (bool){ true }
   140    }
   141    directlyNestedEmpty: (struct){
   142      a: (bool){ true }
   143    }
   144    directlyDoublyNestedEmpty: (struct){
   145      a: (bool){ true }
   146    }
   147    indirectlyDoublyNestedEmpty: (struct){
   148      a: (bool){ true }
   149      b: (bool){ true }
   150    }
   151    indirectlyDoublyNested: (struct){
   152      a: (bool){ true }
   153      c: (int){ 1 }
   154      b: (int){ 1 }
   155    }
   156    issue1974: (struct){
   157      X: (struct){
   158        foo: (struct){
   159          bar: (string){ "" }
   160          baz: (string){ "" }
   161        }
   162      }
   163      out: (struct){
   164        foo: (struct){
   165          bar: (string){ "" }
   166          baz: (string){ "" }
   167        }
   168      }
   169    }
   170  }
   171  -- out/compile --
   172  --- in.cue
   173  {
   174    given: {
   175      INC: {
   176        USD: 2.0
   177      }
   178      USD: {
   179        GBP: 3.0
   180      }
   181    }
   182    hydrated: {
   183      for k, v in 〈1;given〉 {
   184        for k1, r in 〈1;v〉 {
   185          "\(〈3;k〉)": {
   186            "\(〈4;k〉)": 1.0
   187          }
   188          "\(〈1;k1〉)": {
   189            "\(〈2;k1〉)": 1.0
   190          }
   191          "\(〈3;k〉)": {
   192            "\(〈2;k1〉)": 〈2;r〉
   193          }
   194          "\(〈1;k1〉)": {
   195            "\(〈4;k〉)": number
   196          }
   197        }
   198      }
   199    }
   200    foo: {
   201      a: 10
   202      if (〈0;a〉 < 20) {
   203        if (〈1;a〉 < 50) {
   204          b: 20
   205        }
   206      }
   207    }
   208    indirectlyNested: {
   209      a: true
   210      if true {
   211        b: {
   212          if 〈2;a〉 {
   213            〈3;a〉
   214          }
   215        }
   216      }
   217    }
   218    directlyNestedEmpty: {
   219      a: true
   220      if true {
   221        if 〈1;a〉 {}
   222      }
   223    }
   224    directlyDoublyNestedEmpty: {
   225      a: true
   226      if true {
   227        if 〈1;a〉 {}
   228      }
   229    }
   230    indirectlyDoublyNestedEmpty: {
   231      a: true
   232      b: {
   233        if true {
   234          if 〈2;a〉 {
   235            if 〈3;a〉 {
   236              〈4;a〉
   237            }
   238          }
   239          if 〈2;a〉 {
   240            〈3;a〉
   241          }
   242        }
   243      }
   244    }
   245    indirectlyDoublyNested: {
   246      a: true
   247      if true {
   248        if 〈1;a〉 {
   249          if 〈2;a〉 {
   250            b: 1
   251          }
   252        }
   253        if 〈1;a〉 {
   254          c: 1
   255        }
   256      }
   257    }
   258    issue1974: {
   259      X: {
   260        foo: {
   261          bar: ""
   262          baz: ""
   263        }
   264      }
   265      out: {
   266        for k, v in 〈1;X〉 for vk, vv in 〈0;v〉 {
   267          "\(〈2;k〉)": {
   268            "\(〈2;vk〉)": 〈2;vv〉
   269          }
   270        }
   271      }
   272    }
   273  }