cuelang.org/go@v0.10.1/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 --
   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 bar1]
   325  [y1 bar2]
   326  [y1 foo1]
   327  [y1 foo2]
   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/value/todo/p3 --
   341  Error message change.
   342  -- out/value --
   343  == Simplified
   344  _|_ // e3: index out of range [2] with length 2
   345  == Raw
   346  _|_ // e3: index out of range [2] with length 2
   347  == Final
   348  _|_ // e3: index out of range [2] with length 2
   349  == All
   350  {
   351  	@foo(bar)
   352  	p1: {}
   353  	d1: {
   354  		foobar: int
   355  	}
   356  	bar: "bar"
   357  	d2: {
   358  		foobar: {
   359  			name: "xx"
   360  			foo:  "xx"
   361  		}
   362  	}
   363  
   364  	// Issue #1910
   365  	a: _
   366  	comp: {
   367  		for k, v in [0]
   368  		let w = v {
   369  			"\(a)": w
   370  			"bar":  w
   371  		}
   372  	}
   373  	bytes: '\xeb \x1a\xf5\xaa\xf0\xd6\x06)'
   374  	c1:    true
   375  	s1: """
   376  		multi
   377  		bar
   378  		line
   379  		"""
   380  	l1: [3, ...int]
   381  	l2: [...int]
   382  	l3: []
   383  	l4: [1, 2]
   384  	l5: {
   385  		#foo: int
   386  		[1, 3]
   387  	}
   388  	#foo: int
   389  	l6: {
   390  		#foo: int
   391  		[1, 3]
   392  	}
   393  	n1:  1.0
   394  	n10: 10
   395  
   396  	// t is true
   397  	t:   true
   398  	e1:  <1.0
   399  	e2:  >1.0 & <10
   400  	e3:  _|_ // e3: index out of range [2] with length 2
   401  	e4:  _|_ // e4: index 3 out of range
   402  	e5:  _|_ // e3: index out of range [2] with length 2
   403  	e6:  false
   404  	e7:  true
   405  	e8?: true
   406  	m1: {
   407  		// foo is an optional field
   408  		foo?: 3
   409  
   410  		// bar is a field
   411  		bar: 4
   412  
   413  		// baz is a required field.
   414  		baz!: 5
   415  	}
   416  	y1: {
   417  		src: [1, 2, 3]
   418  		foo0: 1
   419  		bar1: 2
   420  		bar2: 3
   421  		foo1: 2
   422  		x: [1, 2, 3]
   423  		foo2: 3
   424  	}
   425  	preserveKeyFieldInComprehension: 1
   426  	errorStructDef: {
   427  		a:    1
   428  		b:    _|_ // errorStructDef.b: conflicting values 2 and 1
   429  		#Def: 1
   430  	}
   431  	errorList: [1, _|_]
   432  	x: int
   433  	errorListDef: {
   434  		#Def: 1
   435  		[1, _|_]
   436  	}
   437  }
   438  == Eval
   439  _|_ // e3: index out of range [2] with length 2