doc/tutorial/basic: use definitions with "emit" examples
Mixing regular fields with emit clauses is legal now,
but will be forbidden for non-struct emit values
and struct emit values will just be embedded.
Change-Id: I3abe6072ca872cf65dae84768320346fe85304b1
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3660
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/build_test.go b/cue/build_test.go
index 912b452..832ceea 100644
--- a/cue/build_test.go
+++ b/cue/build_test.go
@@ -131,7 +131,7 @@
`package test
import pkg2 "pkg1"
- pkg1: pkg2.Object
+ pkg1 :: pkg2.Object
"Hello \(pkg1)!"`),
}),
diff --git a/cue/types_test.go b/cue/types_test.go
index 281a747..d225375 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -50,135 +50,135 @@
concrete bool
// pos token.Pos
}{{ // Not a concrete value.
- value: `_`,
+ value: `v: _`,
kind: BottomKind,
incompleteKind: nextKind - 1,
}, {
- value: `_|_`,
+ value: `v: _|_`,
kind: BottomKind,
incompleteKind: BottomKind,
concrete: true,
}, {
- value: `1&2`,
+ value: `v: 1&2`,
kind: BottomKind,
incompleteKind: BottomKind,
concrete: true,
}, { // TODO: should be error{
- value: `b`,
+ value: `v: b`,
kind: BottomKind,
incompleteKind: BottomKind,
concrete: true,
}, {
- value: `(b[a])`,
+ value: `v: (b[a])`,
kind: BottomKind,
incompleteKind: BottomKind,
concrete: true,
}, { // TODO: should be error{
- value: `(b)
+ value: `v: (b)
b: bool`,
kind: BottomKind,
incompleteKind: BoolKind,
}, {
- value: `([][b])`,
+ value: `v: ([][b])`,
kind: BottomKind,
incompleteKind: BottomKind,
concrete: true,
}, {
- value: `null`,
+ value: `v: null`,
kind: NullKind,
incompleteKind: NullKind,
concrete: true,
}, {
- value: `true`,
+ value: `v: true`,
kind: BoolKind,
incompleteKind: BoolKind,
concrete: true,
}, {
- value: `false`,
+ value: `v: false`,
kind: BoolKind,
incompleteKind: BoolKind,
concrete: true,
}, {
- value: `bool`,
+ value: `v: bool`,
kind: BottomKind,
incompleteKind: BoolKind,
}, {
- value: `2`,
+ value: `v: 2`,
kind: IntKind,
incompleteKind: IntKind,
concrete: true,
}, {
- value: `2.0`,
+ value: `v: 2.0`,
kind: FloatKind,
incompleteKind: FloatKind,
concrete: true,
}, {
- value: `2.0Mi`,
+ value: `v: 2.0Mi`,
kind: IntKind,
incompleteKind: IntKind,
concrete: true,
}, {
- value: `14_000`,
+ value: `v: 14_000`,
kind: IntKind,
incompleteKind: IntKind,
concrete: true,
}, {
- value: `>=0 & <5`,
+ value: `v: >=0 & <5`,
kind: BottomKind,
incompleteKind: NumberKind,
}, {
- value: `float`,
+ value: `v: float`,
kind: BottomKind,
incompleteKind: FloatKind,
}, {
- value: `"str"`,
+ value: `v: "str"`,
kind: StringKind,
incompleteKind: StringKind,
concrete: true,
}, {
- value: "'''\n'''",
+ value: "v: '''\n'''",
kind: BytesKind,
incompleteKind: BytesKind,
concrete: true,
}, {
- value: "string",
+ value: "v: string",
kind: BottomKind,
incompleteKind: StringKind,
}, {
- value: `{}`,
+ value: `v: {}`,
kind: StructKind,
incompleteKind: StructKind,
concrete: true,
}, {
- value: `[]`,
+ value: `v: []`,
kind: ListKind,
incompleteKind: ListKind,
concrete: true,
}, {
- value: `{a: int, b: [1][a]}.b`,
+ value: `v: {a: int, b: [1][a]}.b`,
kind: BottomKind,
concrete: false,
}, {
value: `import "time"
- {a: time.Time}.a`,
+ v: {a: time.Time}.a`,
kind: BottomKind,
incompleteKind: StringKind,
concrete: false,
}, {
value: `import "time"
- {a: time.Time & string}.a`,
+ v: {a: time.Time & string}.a`,
kind: BottomKind,
incompleteKind: StringKind,
concrete: false,
}, {
value: `import "strings"
- {a: strings.ContainsAny("D")}.a`,
+ v: {a: strings.ContainsAny("D")}.a`,
kind: BottomKind,
incompleteKind: StringKind,
concrete: false,
}, {
value: `import "struct"
- {a: struct.MaxFields(2) & {}}.a`,
+ v: {a: struct.MaxFields(2) & {}}.a`,
kind: StructKind, // Can determine a valid struct already.
incompleteKind: StructKind,
concrete: true,
@@ -186,7 +186,7 @@
for _, tc := range testCases {
t.Run(tc.value, func(t *testing.T) {
inst := getInstance(t, tc.value)
- v := inst.Value()
+ v := inst.Lookup("v")
if got := v.Kind(); got != tc.kind {
t.Errorf("Kind: got %x; want %x", got, tc.kind)
}
@@ -423,7 +423,7 @@
str: `Hello world!`,
}, {
value: `"Hello \(world)!"
- world: "world"`,
+ world :: "world"`,
str: `Hello world!`,
}, {
value: `string`,
@@ -479,20 +479,20 @@
value string
err string
}{{
- value: `_|_`,
+ value: `v: _|_`,
err: "from source",
}, {
- value: `"str"`,
+ value: `v: "str"`,
err: "cannot use value \"str\" (type string) as null",
}, {
- value: `null`,
+ value: `v: null`,
}, {
- value: `_`,
+ value: `v: _`,
err: "non-concrete value _",
}}
for _, tc := range testCases {
t.Run(tc.value, func(t *testing.T) {
- err := getInstance(t, tc.value).Value().Null()
+ err := getInstance(t, tc.value).Lookup("v").Null()
checkErr(t, err, tc.err, "init")
})
}
@@ -552,7 +552,7 @@
err: "incomplete",
}, {
value: `[x for x in y if x > 1]
- y: [1,2,3]`,
+ y :: [1,2,3]`,
res: "[2,3,]",
}, {
value: `[int]`,
@@ -603,7 +603,7 @@
res: "{}",
}, {
value: `{ for k, v in y if v > 1 {"\(k)": v} }
- y: {a:1,b:2,c:3}`,
+ y :: {a:1,b:2,c:3}`,
res: "{b:2,c:3,}",
}, {
value: `{ def :: 1, _hidden: 2, opt?: 3, reg: 4 }`,
@@ -1035,7 +1035,7 @@
want: *intList(1, 2, 3),
}, {
value: `[x for x in y if x > 1]
- y: [1,2,3]`,
+ y :: [1,2,3]`,
dst: intList(),
want: *intList(2, 3),
}, {
diff --git a/doc/tutorial/basics/2_types/70_bounds.txt b/doc/tutorial/basics/2_types/70_bounds.txt
index c908892..9f36809 100644
--- a/doc/tutorial/basics/2_types/70_bounds.txt
+++ b/doc/tutorial/basics/2_types/70_bounds.txt
@@ -1,4 +1,4 @@
-cue eval -i bounds.cue
+cue eval -ic bounds.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
@@ -15,20 +15,18 @@
whereas `<0` allows all negative numbers (int or float).
-- bounds.cue --
-rn: >=3 & <8 // type int | float
-ri: >=3 & <8 & int // type int
-rf: >=3 & <=8.0 // type float
-rs: >="a" & <"mo"
+rn :: >=3 & <8 // type int | float
+ri :: >=3 & <8 & int // type int
+rf :: >=3 & <=8.0 // type float
+rs :: >="a" & <"mo"
-{
- a: rn & 3.5
- b: ri & 3.5
- c: rf & 3
- d: rs & "ma"
- e: rs & "mu"
+a: rn & 3.5
+b: ri & 3.5
+c: rf & 3
+d: rs & "ma"
+e: rs & "mu"
- r1: rn & >=5 & <10
-}
+r1: rn & >=5 & <10
-- expect-stdout-cue --
a: 3.5
diff --git a/doc/tutorial/basics/2_types/75_bounddef.txt b/doc/tutorial/basics/2_types/75_bounddef.txt
index 3125ff7..9869fea 100644
--- a/doc/tutorial/basics/2_types/75_bounddef.txt
+++ b/doc/tutorial/basics/2_types/75_bounddef.txt
@@ -1,4 +1,4 @@
-cue eval -i bound.cue
+cue eval -ic bound.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
@@ -29,15 +29,13 @@
```
-- bound.cue --
-positive: uint
-byte: uint8
-word: int32
+positive :: uint
+byte :: uint8
+word :: int32
-{
- a: positive & -1
- b: byte & 128
- c: word & 2_000_000_000
-}
+a: positive & -1
+b: byte & 128
+c: word & 2_000_000_000
-- expect-stdout-cue --
a: _|_ // invalid value -1 (out of bound int & >=0)
diff --git a/doc/tutorial/basics/4_references/50_emit.txt b/doc/tutorial/basics/4_references/50_emit.txt
index fc841a0..c64887b 100644
--- a/doc/tutorial/basics/4_references/50_emit.txt
+++ b/doc/tutorial/basics/4_references/50_emit.txt
@@ -16,7 +16,7 @@
-- emit.cue --
"Hello \(who)!"
-who: "world"
+who :: "world"
-- expect-stdout-cue --
"Hello world!"
diff --git a/doc/tutorial/basics/6_expressions/20_interpolation.txt b/doc/tutorial/basics/6_expressions/20_interpolation.txt
index a741d1f..8c13cce 100644
--- a/doc/tutorial/basics/6_expressions/20_interpolation.txt
+++ b/doc/tutorial/basics/6_expressions/20_interpolation.txt
@@ -14,8 +14,8 @@
-- interpolation.cue --
"You are \( cost - budget ) dollars over budget!"
-cost: 102
-budget: 88
+cost :: 102
+budget :: 88
-- expect-stdout-cue --
"You are 14 dollars over budget!"
diff --git a/doc/tutorial/basics/6_expressions/40_listcomp.txt b/doc/tutorial/basics/6_expressions/40_listcomp.txt
index d87f1e0..88eb177 100644
--- a/doc/tutorial/basics/6_expressions/40_listcomp.txt
+++ b/doc/tutorial/basics/6_expressions/40_listcomp.txt
@@ -13,7 +13,7 @@
-- listcomp.cue --
[ x*x for x in items if x rem 2 == 0]
-items: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
+items :: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-- expect-stdout-cue --
[4, 16, 36, 64]
diff --git a/doc/tutorial/basics/6_expressions/50_fieldcomp.txt b/doc/tutorial/basics/6_expressions/50_fieldcomp.txt
index d32cda2..6470cb9 100644
--- a/doc/tutorial/basics/6_expressions/50_fieldcomp.txt
+++ b/doc/tutorial/basics/6_expressions/50_fieldcomp.txt
@@ -1,4 +1,4 @@
-cue eval fieldcomp.cue
+cue eval -c fieldcomp.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
@@ -14,15 +14,13 @@
-- fieldcomp.cue --
import "strings"
-a: [ "Barcelona", "Shanghai", "Munich" ]
+a:: [ "Barcelona", "Shanghai", "Munich" ]
-{
- for k, v in a {
- "\( strings.ToLower(v) )": {
- pos: k + 1
- name: v
- nameLen: len(v)
- }
+for k, v in a {
+ "\( strings.ToLower(v) )": {
+ pos: k + 1
+ name: v
+ nameLen: len(v)
}
}