cuelang.org/go@v0.13.0/internal/core/export/testdata/main/adt.txtar (about)

     1  -- in.cue --
     2  import mystrings "strings"
     3  
     4  @foo(bar)
     5  
     6  p1: [X=string]: name: X
     7  
     8  d1: "foo\(bar)": int
     9  bar: "bar"
    10  
    11  d2: C="foo\(bar)": {
    12  	name: "xx"
    13  	foo:  C.name
    14  }
    15  
    16  // Issue #1910
    17  a: _
    18  comp: {
    19  	for k, v in [0]
    20  	let w = v {
    21  		"\(a)": w
    22  		"\(bar)": w
    23  	}
    24  }
    25  
    26  bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'
    27  
    28  c1: mystrings.Contains("aa", "a")
    29  
    30  s1: """
    31      multi
    32      \(bar)
    33      line
    34      """
    35  
    36  l1: [3, ...int]
    37  l2: [...int]
    38  l3: []
    39  l4: [1, 2]
    40  l5: [1, 3] & {
    41  	[1, 3]
    42  
    43  	#foo: int
    44  }
    45  
    46  #foo: int
    47  l6: [1, #foo] & {
    48  	[1, 3]
    49  
    50  	#foo: int
    51  }
    52  
    53  n1:  1.0
    54  n10: 10
    55  
    56  // Ignored comment.
    57  
    58  // t is true
    59  t: true
    60  
    61  // Dangling comment.
    62  
    63  e1:  <n1
    64  e2:  >n1 & <n10
    65  e3:  l4[2]
    66  e4:  l4[2:3]
    67  e5:  e1 + e2 - e3
    68  e6:  !t
    69  e7:  !t || !false
    70  e8?: !false
    71  
    72  m1: {[string]: uint} & {
    73  	// this is a pattern constraint
    74  	{[string]: int} & {[string]: int64}
    75  
    76  	// foo is an optional field
    77  	foo?: 3
    78  
    79  	// Dangling comment.
    80  
    81  	// bar is a field
    82  	bar: 4
    83  
    84  	// baz is a required field.
    85  	baz!: 5
    86  
    87  	// a comment too many.
    88  
    89  	...
    90  }
    91  
    92  if true {
    93  	x: int
    94  }
    95  
    96  y1: {
    97  	src: [1, 2, 3]
    98  	for i, v in src for j, w in src if i < j {
    99  		"foo\(i)": v
   100  		"bar\(j)": w
   101  	}
   102  
   103  	for i, v in src {
   104  		"foo\(i)": v
   105  	}
   106  
   107  	x: [
   108  		for x in src
   109  		let y = x {
   110  			y
   111  		},
   112  	]
   113  }
   114  
   115  preserveKeyFieldInComprehension: {
   116  	for _, s in [1] {
   117  		s
   118  	}
   119  }
   120  
   121  errorStructDef: {
   122  	a: 1
   123  	b: 1 & 2
   124  
   125  	#Def: 1
   126  }
   127  
   128  errorList: [
   129  	1,
   130  	1 & 2,
   131  ]
   132  
   133  errorListDef: {
   134  	errorList
   135  
   136  	#Def: 1
   137  }
   138  -- out/definition --
   139  import mystrings "strings"
   140  
   141  @foo(bar)
   142  p1: {
   143  	[X=string]: {
   144  		name: X
   145  	}
   146  }
   147  d1: {
   148  	"foobar": int
   149  }
   150  bar: "bar"
   151  d2: {
   152  	C="foobar": {
   153  		name: "xx"
   154  		foo:  C.name
   155  	}
   156  }
   157  
   158  // Issue #1910
   159  a: _
   160  comp: {
   161  	for k, v in [0]
   162  	let w = v {
   163  		"\(a)": w
   164  		"bar":  w
   165  	}
   166  }
   167  bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'
   168  c1:    mystrings.Contains("aa", "a")
   169  s1:    """
   170  		multi
   171  		\(bar)
   172  		line
   173  		"""
   174  l1: [3, ...int]
   175  l2: [...int]
   176  l3: []
   177  l4: [1, 2]
   178  l5: [1, 3] & {
   179  	[1, 3]
   180  	#foo: int
   181  }
   182  #foo: int
   183  l6: [1, #foo] & {
   184  	[1, 3]
   185  	#foo: int
   186  }
   187  n1:  1.0
   188  n10: 10
   189  
   190  // t is true
   191  t:   true
   192  e1:  <n1
   193  e2:  >n1 & <n10
   194  e3:  l4[2]
   195  e4:  l4[2:3]
   196  e5:  e1 + e2 - e3
   197  e6:  !t
   198  e7:  !t || !false
   199  e8?: !false
   200  m1: {
   201  	[string]: int & >=0
   202  } & {
   203  	{
   204  		[string]: int
   205  	} & {
   206  		[string]: int64
   207  	}
   208  
   209  	// foo is an optional field
   210  	foo?: 3
   211  
   212  	// bar is a field
   213  	bar: 4
   214  
   215  	// baz is a required field.
   216  	baz!: 5
   217  	...
   218  }
   219  
   220  if true {
   221  	x: int
   222  }
   223  y1: {
   224  	src: [1, 2, 3]
   225  	for i, v in src for j, w in src if i < j {
   226  		"foo\(i)": v
   227  		"bar\(j)": w
   228  	}
   229  
   230  	for i, v in src {
   231  		"foo\(i)": v
   232  	}
   233  	x: [
   234  		for x in src
   235  		let y = x {
   236  			y
   237  		}]
   238  }
   239  preserveKeyFieldInComprehension: {
   240  	for _, s in [1] {
   241  		s
   242  	}
   243  }
   244  errorStructDef: {
   245  	a:    1
   246  	b:    _|_ // conflicting values 2 and 1
   247  	#Def: 1
   248  }
   249  errorList: [1, 1 & 2]
   250  errorListDef: {
   251  	errorList
   252  	#Def: 1
   253  }
   254  -- diff/doc/explanation --
   255  Reordering.
   256  -- out/doc-v3 --
   257  []
   258  [p1]
   259  [d1]
   260  [d1 foobar]
   261  [bar]
   262  [d2]
   263  [d2 foobar]
   264  [d2 foobar name]
   265  [d2 foobar foo]
   266  [a]
   267  - Issue #1910
   268  
   269  [comp]
   270  [comp bar]
   271  [bytes]
   272  [c1]
   273  [s1]
   274  [l1]
   275  [l1 0]
   276  [l2]
   277  [l3]
   278  [l4]
   279  [l4 0]
   280  [l4 1]
   281  [l5]
   282  [l5 #foo]
   283  [l5 0]
   284  [l5 1]
   285  [#foo]
   286  [l6]
   287  [l6 #foo]
   288  [l6 0]
   289  [l6 1]
   290  [n1]
   291  [n10]
   292  [t]
   293  - t is true
   294  
   295  [e1]
   296  [e2]
   297  [e3]
   298  [e4]
   299  [e5]
   300  [e6]
   301  [e7]
   302  [e8]
   303  [m1]
   304  [m1 foo]
   305  - foo is an optional field
   306  
   307  [m1 bar]
   308  - bar is a field
   309  
   310  [m1 baz]
   311  - baz is a required field.
   312  
   313  [x]
   314  [y1]
   315  [y1 src]
   316  [y1 src 0]
   317  [y1 src 1]
   318  [y1 src 2]
   319  [y1 x]
   320  [y1 x 0]
   321  [y1 x 1]
   322  [y1 x 2]
   323  [y1 foo0]
   324  [y1 foo1]
   325  [y1 foo2]
   326  [y1 bar1]
   327  [y1 bar2]
   328  [preserveKeyFieldInComprehension]
   329  [errorStructDef]
   330  [errorStructDef a]
   331  [errorStructDef b]
   332  [errorStructDef #Def]
   333  [errorList]
   334  [errorList 0]
   335  [errorList 1]
   336  [errorListDef]
   337  [errorListDef #Def]
   338  [errorListDef 0]
   339  [errorListDef 1]
   340  -- diff/-out/doc-v3<==>+out/doc --
   341  diff old new
   342  --- old
   343  +++ new
   344  @@ -65,10 +65,10 @@
   345   [y1 x 1]
   346   [y1 x 2]
   347   [y1 foo0]
   348  -[y1 bar1]
   349  -[y1 bar2]
   350   [y1 foo1]
   351   [y1 foo2]
   352  +[y1 bar1]
   353  +[y1 bar2]
   354   [preserveKeyFieldInComprehension]
   355   [errorStructDef]
   356   [errorStructDef a]
   357  -- out/doc --
   358  []
   359  [p1]
   360  [d1]
   361  [d1 foobar]
   362  [bar]
   363  [d2]
   364  [d2 foobar]
   365  [d2 foobar name]
   366  [d2 foobar foo]
   367  [a]
   368  - Issue #1910
   369  
   370  [comp]
   371  [comp bar]
   372  [bytes]
   373  [c1]
   374  [s1]
   375  [l1]
   376  [l1 0]
   377  [l2]
   378  [l3]
   379  [l4]
   380  [l4 0]
   381  [l4 1]
   382  [l5]
   383  [l5 #foo]
   384  [l5 0]
   385  [l5 1]
   386  [#foo]
   387  [l6]
   388  [l6 #foo]
   389  [l6 0]
   390  [l6 1]
   391  [n1]
   392  [n10]
   393  [t]
   394  - t is true
   395  
   396  [e1]
   397  [e2]
   398  [e3]
   399  [e4]
   400  [e5]
   401  [e6]
   402  [e7]
   403  [e8]
   404  [m1]
   405  [m1 foo]
   406  - foo is an optional field
   407  
   408  [m1 bar]
   409  - bar is a field
   410  
   411  [m1 baz]
   412  - baz is a required field.
   413  
   414  [x]
   415  [y1]
   416  [y1 src]
   417  [y1 src 0]
   418  [y1 src 1]
   419  [y1 src 2]
   420  [y1 x]
   421  [y1 x 0]
   422  [y1 x 1]
   423  [y1 x 2]
   424  [y1 foo0]
   425  [y1 bar1]
   426  [y1 bar2]
   427  [y1 foo1]
   428  [y1 foo2]
   429  [preserveKeyFieldInComprehension]
   430  [errorStructDef]
   431  [errorStructDef a]
   432  [errorStructDef b]
   433  [errorStructDef #Def]
   434  [errorList]
   435  [errorList 0]
   436  [errorList 1]
   437  [errorListDef]
   438  [errorListDef #Def]
   439  [errorListDef 0]
   440  [errorListDef 1]
   441  -- out/value --
   442  == Simplified
   443  _|_ // e3: index out of range [2] with length 2
   444  == Raw
   445  _|_ // e3: index out of range [2] with length 2
   446  == Final
   447  _|_ // e3: index out of range [2] with length 2
   448  == All
   449  {
   450  	@foo(bar)
   451  	x: int
   452  	p1: {}
   453  	d1: {
   454  		foobar: int
   455  	}
   456  	bar: "bar"
   457  	d2: {
   458  		foobar: {
   459  			name: "xx"
   460  			foo:  "xx"
   461  		}
   462  	}
   463  
   464  	// Issue #1910
   465  	a: _
   466  	comp: {
   467  		for k, v in [0]
   468  		let w = v {
   469  			"\(a)": w
   470  			"bar":  w
   471  		}
   472  	}
   473  	bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'
   474  	c1:    true
   475  	s1: """
   476  		multi
   477  		bar
   478  		line
   479  		"""
   480  	l1: [3, ...int]
   481  	l2: [...int]
   482  	l3: []
   483  	l4: [1, 2]
   484  	l5: {
   485  		#foo: int
   486  		[1, 3]
   487  	}
   488  	#foo: int
   489  	l6: {
   490  		#foo: int
   491  		[1, 3]
   492  	}
   493  	n1:  1.0
   494  	n10: 10
   495  
   496  	// t is true
   497  	t:   true
   498  	e1:  <1.0
   499  	e2:  >1.0 & <10
   500  	e3:  _|_ // e3: index out of range [2] with length 2
   501  	e4:  _|_ // e4: index 3 out of range
   502  	e5:  _|_ // e3: index out of range [2] with length 2
   503  	e6:  false
   504  	e7:  true
   505  	e8?: true
   506  	m1: {
   507  		// foo is an optional field
   508  		foo?: 3
   509  
   510  		// bar is a field
   511  		bar: 4
   512  
   513  		// baz is a required field.
   514  		baz!: 5
   515  	}
   516  	y1: {
   517  		foo0: 1
   518  		bar1: 2
   519  		bar2: 3
   520  		foo1: 2
   521  		foo2: 3
   522  		src: [1, 2, 3]
   523  		x: [1, 2, 3]
   524  	}
   525  	preserveKeyFieldInComprehension: 1
   526  	errorStructDef: {
   527  		a:    1
   528  		b:    _|_ // errorStructDef.b: conflicting values 2 and 1
   529  		#Def: 1
   530  	}
   531  	errorList: [1, _|_]
   532  	errorListDef: {
   533  		#Def: 1
   534  		[1, _|_]
   535  	}
   536  }
   537  == Eval
   538  _|_ // e3: index out of range [2] with length 2