github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/internal/core/export/testdata/alias.txtar (about)

     1  // TODO: merge the resulting files. This can only be done if off-by-one handling
     2  // is moved to expr handling too.
     3  //
     4  // For now this is better than panicking.
     5  
     6  -- x.cue --
     7  fieldAlias: simple: {
     8  	X="a-b": 4
     9  	foo:     X
    10  
    11  	bar?: Y
    12  
    13  	Y="a-c": 5
    14  }
    15  
    16  valueAlias: merge: {
    17  	// Merge fields, rename alias to avoid conflict.
    18  	// TODO: merged values can still be simplified.
    19  	value: X={#value: X.b, b: 2}
    20  	value: Y={#value: Y.b, b: 2, v: X: 3}
    21  }
    22  
    23  valueAlias: selfRef: struct: {
    24  	a: b: X={#foo: X.b, b: 2}
    25  }
    26  
    27  valueAlias: selfRefValue: struct: {
    28  	// Note: this resolves to a cycle error, which is considered
    29  	// to be equal to "incomplete". As a result, in case of
    30  	// non-final evaluation, reference will remain. This is not
    31  	// an issue exclusive to value aliases, and falls within the
    32  	// range of what is acceptable for now.
    33  	// TODO: solve this issue.
    34  	a: X=or(X)
    35  }
    36  
    37  valueAlias: selfRefValue: pattern: {
    38  	// this triggers the verbatim "adt" path. Note that there
    39  	// is no need to rename the variable here as the expression
    40  	// was known to compile and is known to be correct.
    41  	a: [string]: X=or(X)
    42  }
    43  
    44  issue1308: {
    45  	let _xA = 1
    46  	sub: [{_A: _xA}]
    47  }
    48  -- y.cue --
    49  fieldAlias: cross: {
    50  	baz: 3
    51  	X="d-2": E=[D="cue"]: C="foo\(baz)": {
    52  		name: "xx"
    53  		foo:  C.name
    54  		bar:  X
    55  		baz:  D
    56  		qux:  E
    57  	}
    58  }
    59  -- out/definition --
    60  fieldAlias: {
    61  	simple: {
    62  		X_1="a-b": 4
    63  		foo:       X_1
    64  		bar?:      Y_1
    65  		Y_1="a-c": 5
    66  	}
    67  	cross: {
    68  		baz: 3
    69  		X_2="d-2": {
    70  			E=[D="cue"]: {
    71  				C="foo\(baz)": {
    72  					name: "xx"
    73  					foo:  C.name
    74  					bar:  X_2
    75  					baz:  D
    76  					qux:  E
    77  				}
    78  			}
    79  		}
    80  	}
    81  }
    82  valueAlias: {
    83  	merge: {
    84  		// Merge fields, rename alias to avoid conflict.
    85  		// TODO: merged values can still be simplified.
    86  		value: X_3={
    87  			#value: X_3.b & X_3.b
    88  			b:      2
    89  			v: {
    90  				X: 3
    91  			}
    92  		}
    93  	}
    94  	selfRef: {
    95  		struct: {
    96  			a: {
    97  				b: X_4={
    98  					#foo: X_4.b
    99  					b:    2
   100  				}
   101  			}
   102  		}
   103  	}
   104  	selfRefValue: {
   105  		struct: {
   106  			// Note: this resolves to a cycle error, which is considered
   107  			// to be equal to "incomplete". As a result, in case of
   108  			// non-final evaluation, reference will remain. This is not
   109  			// an issue exclusive to value aliases, and falls within the
   110  			// range of what is acceptable for now.
   111  			// TODO: solve this issue.
   112  			a: X_8=or(X_8)
   113  		}
   114  		pattern: {
   115  			// this triggers the verbatim "adt" path. Note that there
   116  			// is no need to rename the variable here as the expression
   117  			// was known to compile and is known to be correct.
   118  			a: {
   119  				[string]: X=or(X)
   120  			}
   121  		}
   122  	}
   123  }
   124  issue1308: {
   125  	let _xA = 1
   126  	sub: [{
   127  		_A: _xA
   128  	}]
   129  }
   130  -- out/doc --
   131  []
   132  [fieldAlias]
   133  [fieldAlias simple]
   134  [fieldAlias simple "a-b"]
   135  [fieldAlias simple foo]
   136  [fieldAlias simple "a-c"]
   137  [fieldAlias cross]
   138  [fieldAlias cross baz]
   139  [fieldAlias cross "d-2"]
   140  [valueAlias]
   141  [valueAlias merge]
   142  [valueAlias merge value]
   143  - Merge fields, rename alias to avoid conflict.
   144  TODO: merged values can still be simplified.
   145  
   146  [valueAlias merge value #value]
   147  [valueAlias merge value b]
   148  [valueAlias merge value v]
   149  [valueAlias merge value v X]
   150  [valueAlias selfRef]
   151  [valueAlias selfRef struct]
   152  [valueAlias selfRef struct a]
   153  [valueAlias selfRef struct a b]
   154  [valueAlias selfRef struct a b #foo]
   155  [valueAlias selfRef struct a b b]
   156  [valueAlias selfRefValue]
   157  [valueAlias selfRefValue struct]
   158  [valueAlias selfRefValue struct a]
   159  - Note: this resolves to a cycle error, which is considered
   160  to be equal to "incomplete". As a result, in case of
   161  non-final evaluation, reference will remain. This is not
   162  an issue exclusive to value aliases, and falls within the
   163  range of what is acceptable for now.
   164  TODO: solve this issue.
   165  
   166  [valueAlias selfRefValue pattern]
   167  [valueAlias selfRefValue pattern a]
   168  - this triggers the verbatim "adt" path. Note that there
   169  is no need to rename the variable here as the expression
   170  was known to compile and is known to be correct.
   171  
   172  [issue1308]
   173  [issue1308 sub]
   174  [issue1308 sub 0]
   175  [issue1308 sub 0 _A]
   176  -- out/value --
   177  == Simplified
   178  {
   179  	fieldAlias: {
   180  		simple: {
   181  			"a-b": 4
   182  			foo:   4
   183  			"a-c": 5
   184  		}
   185  		cross: {
   186  			baz: 3
   187  			"d-2": {}
   188  		}
   189  	}
   190  	valueAlias: {
   191  		merge: {
   192  			// Merge fields, rename alias to avoid conflict.
   193  			// TODO: merged values can still be simplified.
   194  			value: {
   195  				b: 2
   196  				v: {
   197  					X: 3
   198  				}
   199  			}
   200  		}
   201  		selfRef: {
   202  			struct: {
   203  				a: {
   204  					b: {
   205  						b: 2
   206  					}
   207  				}
   208  			}
   209  		}
   210  		selfRefValue: {
   211  			struct: {
   212  				// Note: this resolves to a cycle error, which is considered
   213  				// to be equal to "incomplete". As a result, in case of
   214  				// non-final evaluation, reference will remain. This is not
   215  				// an issue exclusive to value aliases, and falls within the
   216  				// range of what is acceptable for now.
   217  				// TODO: solve this issue.
   218  				a: or(X)
   219  			}
   220  			pattern: {
   221  				// this triggers the verbatim "adt" path. Note that there
   222  				// is no need to rename the variable here as the expression
   223  				// was known to compile and is known to be correct.
   224  				a: {}
   225  			}
   226  		}
   227  	}
   228  	issue1308: {
   229  		sub: [{}]
   230  	}
   231  }
   232  == Raw
   233  {
   234  	fieldAlias: {
   235  		simple: {
   236  			"a-b":     4
   237  			foo:       4
   238  			bar?:      Y_1
   239  			Y_1="a-c": 5
   240  		}
   241  		cross: {
   242  			baz: 3
   243  			"d-2": {}
   244  		}
   245  	}
   246  	valueAlias: {
   247  		merge: {
   248  			// Merge fields, rename alias to avoid conflict.
   249  			// TODO: merged values can still be simplified.
   250  			value: {
   251  				#value: 2
   252  				b:      2
   253  				v: {
   254  					X: 3
   255  				}
   256  			}
   257  		}
   258  		selfRef: {
   259  			struct: {
   260  				a: {
   261  					b: {
   262  						#foo: 2
   263  						b:    2
   264  					}
   265  				}
   266  			}
   267  		}
   268  		selfRefValue: {
   269  			struct: {
   270  				// Note: this resolves to a cycle error, which is considered
   271  				// to be equal to "incomplete". As a result, in case of
   272  				// non-final evaluation, reference will remain. This is not
   273  				// an issue exclusive to value aliases, and falls within the
   274  				// range of what is acceptable for now.
   275  				// TODO: solve this issue.
   276  				a: or(X)
   277  			}
   278  			pattern: {
   279  				// this triggers the verbatim "adt" path. Note that there
   280  				// is no need to rename the variable here as the expression
   281  				// was known to compile and is known to be correct.
   282  				a: {}
   283  			}
   284  		}
   285  	}
   286  	issue1308: {
   287  		sub: [{
   288  			_A: 1
   289  		}]
   290  	}
   291  }
   292  == Final
   293  {
   294  	fieldAlias: {
   295  		simple: {
   296  			"a-b": 4
   297  			foo:   4
   298  			"a-c": 5
   299  		}
   300  		cross: {
   301  			baz: 3
   302  			"d-2": {}
   303  		}
   304  	}
   305  	valueAlias: {
   306  		merge: {
   307  			value: {
   308  				b: 2
   309  				v: {
   310  					X: 3
   311  				}
   312  			}
   313  		}
   314  		selfRef: {
   315  			struct: {
   316  				a: {
   317  					b: {
   318  						b: 2
   319  					}
   320  				}
   321  			}
   322  		}
   323  		selfRefValue: {
   324  			struct: {
   325  				a: _|_ // cycle error
   326  			}
   327  			pattern: {
   328  				a: {}
   329  			}
   330  		}
   331  	}
   332  	issue1308: {
   333  		sub: [{}]
   334  	}
   335  }
   336  == All
   337  {
   338  	fieldAlias: {
   339  		simple: {
   340  			"a-b":     4
   341  			foo:       4
   342  			bar?:      Y_1
   343  			Y_1="a-c": 5
   344  		}
   345  		cross: {
   346  			baz: 3
   347  			"d-2": {}
   348  		}
   349  	}
   350  	valueAlias: {
   351  		merge: {
   352  			// Merge fields, rename alias to avoid conflict.
   353  			// TODO: merged values can still be simplified.
   354  			value: {
   355  				#value: 2
   356  				b:      2
   357  				v: {
   358  					X: 3
   359  				}
   360  			}
   361  		}
   362  		selfRef: {
   363  			struct: {
   364  				a: {
   365  					b: {
   366  						#foo: 2
   367  						b:    2
   368  					}
   369  				}
   370  			}
   371  		}
   372  		selfRefValue: {
   373  			struct: {
   374  				// Note: this resolves to a cycle error, which is considered
   375  				// to be equal to "incomplete". As a result, in case of
   376  				// non-final evaluation, reference will remain. This is not
   377  				// an issue exclusive to value aliases, and falls within the
   378  				// range of what is acceptable for now.
   379  				// TODO: solve this issue.
   380  				a: or(X)
   381  			}
   382  			pattern: {
   383  				// this triggers the verbatim "adt" path. Note that there
   384  				// is no need to rename the variable here as the expression
   385  				// was known to compile and is known to be correct.
   386  				a: {}
   387  			}
   388  		}
   389  	}
   390  	issue1308: {
   391  		sub: [{
   392  			_A: 1
   393  		}]
   394  	}
   395  }
   396  == Eval
   397  {
   398  	fieldAlias: {
   399  		simple: {
   400  			"a-b":     4
   401  			foo:       4
   402  			bar?:      Y_1
   403  			Y_1="a-c": 5
   404  		}
   405  		cross: {
   406  			baz: 3
   407  			"d-2": {}
   408  		}
   409  	}
   410  	valueAlias: {
   411  		merge: {
   412  			value: {
   413  				#value: 2
   414  				b:      2
   415  				v: {
   416  					X: 3
   417  				}
   418  			}
   419  		}
   420  		selfRef: {
   421  			struct: {
   422  				a: {
   423  					b: {
   424  						#foo: 2
   425  						b:    2
   426  					}
   427  				}
   428  			}
   429  		}
   430  		selfRefValue: {
   431  			struct: {
   432  				a: or(X)
   433  			}
   434  			pattern: {
   435  				a: {}
   436  			}
   437  		}
   438  	}
   439  	issue1308: {
   440  		sub: [{}]
   441  	}
   442  }