all: update most tests to not use `::`
Change-Id: I0356417bab7b68b1f6bd8c540902fc049f078cd8
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6200
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/testdata/script/cmd_dep.txt b/cmd/cue/cmd/testdata/script/cmd_dep.txt
index 25484d7..d847cab 100644
--- a/cmd/cue/cmd/testdata/script/cmd_dep.txt
+++ b/cmd/cue/cmd/testdata/script/cmd_dep.txt
@@ -14,8 +14,8 @@
)
foo: {
- a :: string
- b: a
+ #a: string
+ b: #a
}
command: do: {
@@ -25,7 +25,7 @@
}
outputs: print: cli.Print & {
text: json.Marshal(foo & {
- a :: strings.TrimSpace(inputs.name.stdout)
+ #a: strings.TrimSpace(inputs.name.stdout)
})
}
}
diff --git a/cmd/cue/cmd/testdata/script/cmd_echo.txt b/cmd/cue/cmd/testdata/script/cmd_echo.txt
index 4468d6c..ce0e555 100644
--- a/cmd/cue/cmd/testdata/script/cmd_echo.txt
+++ b/cmd/cue/cmd/testdata/script/cmd_echo.txt
@@ -4,11 +4,11 @@
-- data.cue --
package hello
-who :: "World"
+_who: "World"
-- hello.cue --
package hello
-message: "Hello \(who)!" // who declared in data.cue
+message: "Hello \(_who)!" // who declared in data.cue
-- hello_tool.cue --
package hello
diff --git a/cmd/cue/cmd/testdata/script/cmd_print.txt b/cmd/cue/cmd/testdata/script/cmd_print.txt
index 4fb822a..229b70d 100644
--- a/cmd/cue/cmd/testdata/script/cmd_print.txt
+++ b/cmd/cue/cmd/testdata/script/cmd_print.txt
@@ -24,11 +24,11 @@
stdout: string
}
print: cli.Print & {
- text: (f & {arg: runs.t1.stdout + runs.t2.stdout}).result
+ text: (#f & {arg: runs.t1.stdout + runs.t2.stdout}).result
}
}
-f :: {
+#f: {
arg: string
result: strings.Join(strings.Split(arg, ""), ".")
}
diff --git a/cmd/cue/cmd/testdata/script/cmd_run.txt b/cmd/cue/cmd/testdata/script/cmd_run.txt
index 6c1e04e..18e17c4 100644
--- a/cmd/cue/cmd/testdata/script/cmd_run.txt
+++ b/cmd/cue/cmd/testdata/script/cmd_run.txt
@@ -8,7 +8,7 @@
-- task_tool.cue --
package home
-command: run: RunBase & {
+command: run: #RunBase & {
task: echo: cmd: "echo \(message)"
}
@@ -22,7 +22,7 @@
// deliberately put in another file to test resolving top-level identifiers
// in different files.
-RunBase :: {
+#RunBase: {
task: echo: exec.Run & {
stdout: string
}
diff --git a/cmd/cue/cmd/testdata/script/def_basic.txt b/cmd/cue/cmd/testdata/script/def_basic.txt
index 9d15658..1d67977 100644
--- a/cmd/cue/cmd/testdata/script/def_basic.txt
+++ b/cmd/cue/cmd/testdata/script/def_basic.txt
@@ -8,7 +8,7 @@
// foo
package foo
-A :: {
+#A: {
// a is an integer
a: int
b: { c: int } // TODO: should we _not_ simplify?
@@ -22,7 +22,7 @@
// foo
package foo
-A :: {
+#A: {
// a is an integer
a: int
b: c: int
diff --git a/cmd/cue/cmd/testdata/script/def_openapi.txt b/cmd/cue/cmd/testdata/script/def_openapi.txt
index 65430d8..e9a7a62 100644
--- a/cmd/cue/cmd/testdata/script/def_openapi.txt
+++ b/cmd/cue/cmd/testdata/script/def_openapi.txt
@@ -29,13 +29,13 @@
$version: "v1"
-Foo :: {
+#Foo: {
a: int
b: uint & <10
}
-Bar :: {
- foo: Foo
+#Bar: {
+ foo: #Foo
}
-- openapi.json --
diff --git a/cmd/cue/cmd/testdata/script/eval_concrete.txt b/cmd/cue/cmd/testdata/script/eval_concrete.txt
index 825fa3c..c496349 100644
--- a/cmd/cue/cmd/testdata/script/eval_concrete.txt
+++ b/cmd/cue/cmd/testdata/script/eval_concrete.txt
@@ -14,8 +14,8 @@
-- data.cue --
package hello
-who :: "World"
+#who: "World"
-- hello.cue --
package hello
-message: "Hello \(who)!" // who declared in data.cue
+message: "Hello \(#who)!" // who declared in data.cue
diff --git a/cmd/cue/cmd/testdata/script/eval_import.txt b/cmd/cue/cmd/testdata/script/eval_import.txt
index 56f7006..3ecfae3 100644
--- a/cmd/cue/cmd/testdata/script/eval_import.txt
+++ b/cmd/cue/cmd/testdata/script/eval_import.txt
@@ -4,12 +4,12 @@
import "list"
def: {
- types :: list.MinItems(1)
+ #types: list.MinItems(1)
}
-- in.cue --
import (
"list"
)
-def: types :: list.MinItems(1)
+def: #types: list.MinItems(1)
diff --git a/cmd/cue/cmd/testdata/script/export.txt b/cmd/cue/cmd/testdata/script/export.txt
index ad5c5cf..9456ffe 100644
--- a/cmd/cue/cmd/testdata/script/export.txt
+++ b/cmd/cue/cmd/testdata/script/export.txt
@@ -8,10 +8,10 @@
-- hello/data.cue --
package hello
-who :: "World"
+#who: "World"
-- hello/hello.cue --
package hello
$type: "demo"
-message: "Hello \(who)!" // who declared in data.cue
+message: "Hello \(#who)!" // who declared in data.cue
-- hello/cue.mod --
diff --git a/cmd/cue/cmd/testdata/script/export_yaml.txt b/cmd/cue/cmd/testdata/script/export_yaml.txt
index 5677c7b..5d5a3d3 100644
--- a/cmd/cue/cmd/testdata/script/export_yaml.txt
+++ b/cmd/cue/cmd/testdata/script/export_yaml.txt
@@ -6,11 +6,11 @@
-- hello/data.cue --
package hello
-who :: "World"
+_who: "World"
-- hello/hello.cue --
package hello
-message: "Hello \(who)!" // who declared in data.cue
+message: "Hello \(_who)!" // who declared in data.cue
test: {
_foo: string // technically in error, but test anyway.
diff --git a/cmd/cue/cmd/testdata/script/help_doc.txt b/cmd/cue/cmd/testdata/script/help_doc.txt
index fdb55b5..a320526 100644
--- a/cmd/cue/cmd/testdata/script/help_doc.txt
+++ b/cmd/cue/cmd/testdata/script/help_doc.txt
@@ -25,7 +25,7 @@
package bar
name: "foo"
-D :: int
+_D: int
-- bar.cue --
3
diff --git a/cmd/cue/cmd/testdata/script/issue217.txt b/cmd/cue/cmd/testdata/script/issue217.txt
index cedf2f9..ecf9ce6 100644
--- a/cmd/cue/cmd/testdata/script/issue217.txt
+++ b/cmd/cue/cmd/testdata/script/issue217.txt
@@ -8,23 +8,23 @@
package tst
x: {
- a: A
- b: A
+ a: #A
+ b: #A
}
-A :: string | [A]
+#A: string | [#A]
-- def-stdout --
package tst
x: {
- a: A
- b: A
+ a: #A
+ b: #A
}
-A :: string | [A]
+#A: string | [#A]
-- eval-stdout --
x: {
- a: A
- b: A
+ a: #A
+ b: #A
}
-A :: string | [A]
+#A: string | [#A]
diff --git a/cmd/cue/cmd/testdata/script/issue269.txt b/cmd/cue/cmd/testdata/script/issue269.txt
index 30bb2da..8137027 100644
--- a/cmd/cue/cmd/testdata/script/issue269.txt
+++ b/cmd/cue/cmd/testdata/script/issue269.txt
@@ -1,7 +1,7 @@
! cue eval ./struct.cue
cmp stderr expect-stderr
-- struct.cue --
-type :: {
+#type: {
x: 0
y: 0
@@ -10,8 +10,8 @@
}
data: {
- a: type
- b: type
+ a: #type
+ b: #type
b: x: a.x
a: y: b.y
diff --git a/cmd/cue/cmd/testdata/script/issue302.txt b/cmd/cue/cmd/testdata/script/issue302.txt
index 835b558..5758539 100644
--- a/cmd/cue/cmd/testdata/script/issue302.txt
+++ b/cmd/cue/cmd/testdata/script/issue302.txt
@@ -4,13 +4,13 @@
-- foo.cue --
package p
-foo?: Foo
+foo?: #Foo
-Foo :: "hello"
+#Foo: "hello"
-- rewritten --
package p
-foo?: Foo
+foo?: #Foo
-Foo :: "hello"
\ No newline at end of file
+#Foo: "hello"
\ No newline at end of file
diff --git a/cmd/cue/cmd/testdata/script/issue303.txt b/cmd/cue/cmd/testdata/script/issue303.txt
index ca7d9b8..ee8a58c 100644
--- a/cmd/cue/cmd/testdata/script/issue303.txt
+++ b/cmd/cue/cmd/testdata/script/issue303.txt
@@ -5,12 +5,12 @@
package example
foo: c: true
-foo: M
-M :: c?: bool
+foo: #M
+#M: c?: bool
-- rewritten --
package example
foo: c: true
-foo: M
-M :: c?: bool
+foo: #M
+#M: c?: bool
diff --git a/cmd/cue/cmd/testdata/script/issue304.txt b/cmd/cue/cmd/testdata/script/issue304.txt
index d7fe14a..b9c705a 100644
--- a/cmd/cue/cmd/testdata/script/issue304.txt
+++ b/cmd/cue/cmd/testdata/script/issue304.txt
@@ -1,4 +1,4 @@
-cue def -e Foo x.cue
+cue def -e '#Foo' x.cue
cmp stdout expect-stdout
-- expect-stdout --
@@ -13,7 +13,7 @@
-- x.cue --
package example
-Foo :: {
+#Foo: {
x: int
body?: {
a: int
diff --git a/cmd/cue/cmd/testdata/script/issue315.txt b/cmd/cue/cmd/testdata/script/issue315.txt
index 2937c20..b0f4275 100644
--- a/cmd/cue/cmd/testdata/script/issue315.txt
+++ b/cmd/cue/cmd/testdata/script/issue315.txt
@@ -3,17 +3,17 @@
cmp stderr expect-stderr
-- expect-stderr --
-incomplete value 'X.y' in interpolation:
+incomplete value '#X.y' in interpolation:
./file.cue:16:3
./file.cue:3:5
-- file.cue --
-X :: {
+#X: {
x: string
y: string
z: string
}
-X :: {
+#X: {
x: "x"
z: "z"
}
@@ -21,7 +21,7 @@
"""
hello
world
-\(X.x)
-\(X.y)
-\(X.z)
+\(#X.x)
+\(#X.y)
+\(#X.z)
"""
diff --git a/cmd/cue/cmd/testdata/script/vet_data.txt b/cmd/cue/cmd/testdata/script/vet_data.txt
index 5d36377..1fddcd3 100644
--- a/cmd/cue/cmd/testdata/script/vet_data.txt
+++ b/cmd/cue/cmd/testdata/script/vet_data.txt
@@ -5,11 +5,11 @@
cmp stderr export-stderr
-- schema.cue --
-Language :: {
+#Language: {
tag: string
name: =~"^\\p{Lu}" // Must start with an uppercase letter.
}
-languages: [...Language]
+languages: [...#Language]
-- data.yaml --
languages:
diff --git a/cmd/cue/cmd/testdata/script/vet_expr.txt b/cmd/cue/cmd/testdata/script/vet_expr.txt
index 0a79f46..4928f1b 100644
--- a/cmd/cue/cmd/testdata/script/vet_expr.txt
+++ b/cmd/cue/cmd/testdata/script/vet_expr.txt
@@ -1,4 +1,4 @@
-! cue vet -d File vet.cue data.yaml
+! cue vet -d '#File' vet.cue data.yaml
cmp stderr expect-stderr
-- expect-stderr --
@@ -10,7 +10,7 @@
field "skip" not allowed in closed struct:
./data.yaml:20:7
-- vet.cue --
-File :: {
+#File: {
translations: [string]: {
lang: string
text: string
diff --git a/cmd/cue/cmd/testdata/script/vet_file.txt b/cmd/cue/cmd/testdata/script/vet_file.txt
index a333535..3ea9df6 100644
--- a/cmd/cue/cmd/testdata/script/vet_file.txt
+++ b/cmd/cue/cmd/testdata/script/vet_file.txt
@@ -21,7 +21,7 @@
translations: [string]: lang: string
-File :: {
+#File: {
translations: {...}
}
-- data.yaml --
diff --git a/cmd/cue/cmd/testdata/script/vet_opt.txt b/cmd/cue/cmd/testdata/script/vet_opt.txt
index ac4b0ba..1339bfe 100644
--- a/cmd/cue/cmd/testdata/script/vet_opt.txt
+++ b/cmd/cue/cmd/testdata/script/vet_opt.txt
@@ -3,7 +3,7 @@
-- expect-stdout --
-- vet.cue --
-Schema1 :: {
+#Schema1: {
a?: int
}
-instance1: Schema1
+instance1: #Schema1
diff --git a/cmd/cue/cmd/testdata/script/vet_yaml.txt b/cmd/cue/cmd/testdata/script/vet_yaml.txt
index fe8c513..7019b28 100644
--- a/cmd/cue/cmd/testdata/script/vet_yaml.txt
+++ b/cmd/cue/cmd/testdata/script/vet_yaml.txt
@@ -4,29 +4,29 @@
-- expect-stderr --
phrases: error in call to encoding/yaml.Validate: missing field "text":
./yaml.cue:19:10
- ./yaml.cue:4:12
+ ./yaml.cue:4:11
./yaml.cue:11:17
yaml.Validate:4:6
-- yaml.cue --
import "encoding/yaml"
// Phrases defines a schema for a valid phrase.
-Phrases :: {
+#Phrases: {
phrases: {
- [string]: Phrase
+ [string]: #Phrase
}
- Phrase :: {
- lang: LanguageTag
+ #Phrase: {
+ lang: #LanguageTag
text: !=""
attribution?: !="" // must be non-empty when specified
}
- LanguageTag :: =~"^[a-zA-Z0-9-_]{2,}$" | false
+ #LanguageTag: =~"^[a-zA-Z0-9-_]{2,}$" | false
}
// phrases is a YAML string with a field phrases that is a map of Phrase
// objects.
-phrases: yaml.Validate(Phrases)
+phrases: yaml.Validate(#Phrases)
phrases: """
phrases:
diff --git a/cue/ast_test.go b/cue/ast_test.go
index 40f5fae..1b37205 100644
--- a/cue/ast_test.go
+++ b/cue/ast_test.go
@@ -348,27 +348,6 @@
}, {
in: `
a: d: {
- base
- info :: {
- ...
- }
- Y: info.X
- }
-
- base :: {
- info :: {...}
- }
-
- a: [Name=string]: { info :: {
- X: "foo"
- }}
- `,
- out: `<0>{` +
- `a: (<1>{d: <2>{info :: <3>{...}, Y: <2>.info.X}, <0>.base} & <4>{[]: <5>(Name: string)-><6>{info :: <7>C{X: "foo"}}, }), ` +
- `base :: <8>C{info :: <9>{...}}}`,
- }, {
- in: `
- a: d: {
#base
#info: {
...
@@ -389,13 +368,13 @@
`#base: <8>C{#info: <9>{...}}}`,
}, {
in: `
- def :: {
+ #def: {
Type: string
Text: string
Size: int
}
- def :: {
+ #def: {
Type: "B"
Size: 0
} | {
@@ -404,16 +383,16 @@
}
`,
out: `<0>{` +
- `def :: (<1>C{Size: int, Type: string, Text: string} & (<2>C{Size: 0, Type: "B"} | <3>C{Size: 1, Type: "A"}))` +
+ `#def: (<1>C{Size: int, Type: string, Text: string} & (<2>C{Size: 0, Type: "B"} | <3>C{Size: 1, Type: "A"}))` +
`}`,
}, {
// Issue #172
in: `
package testenv
- env_:: [NAME=_]: [VALUE=_]
- env_:: foo: "bar"
+ #env_: [NAME=_]: [VALUE=_]
+ #env_: foo: "bar"
`,
- out: "env_.*: alias not allowed in list:\n test:3:20\n<0>{}",
+ out: "#env_.*: alias not allowed in list:\n test:3:20\n<0>{}",
}, {
// Issue #276
in: `
diff --git a/cue/build_test.go b/cue/build_test.go
index 14f7479..97bf20b 100644
--- a/cue/build_test.go
+++ b/cue/build_test.go
@@ -170,9 +170,9 @@
`package test
import pkg2 "pkg1"
- pkg1 :: pkg2.Object
+ #pkg1: pkg2.Object
- "Hello \(pkg1)!"`),
+ "Hello \(#pkg1)!"`),
}),
`"Hello World!"`,
}, {
diff --git a/cue/export_test.go b/cue/export_test.go
index 79f6018..24c90d4 100644
--- a/cue/export_test.go
+++ b/cue/export_test.go
@@ -336,21 +336,21 @@
// of topological sort to preserve order.
raw: true,
in: `{
- emb :: {
+ #emb: {
a: 1
sub: {
f: 3
}
}
- def :: {
- emb
+ #def: {
+ #emb
b: 2
}
- f :: { a: 10 }
- e :: {
- f
+ #f: a: 10
+ #e: {
+ #f
b: int
[_]: <100
@@ -359,21 +359,21 @@
}`,
out: unindent(`
{
- emb :: {
+ #emb: {
a: 1
sub: f: 3
}
- f :: {
+ #def: {
+ b: 2
+ #emb
+ }
+ #f: {
a: 10
}
- def :: {
- b: 2
- emb
- }
- e :: {
+ #e: {
{[string]: <100}
b: int
- f
+ #f
{[string]: <300}
}
}`),
@@ -383,16 +383,16 @@
noOpt: true,
in: `{
reg: { foo: 1, bar: { baz: 3 } }
- def :: {
+ #def: {
a: 1
sub: reg
}
- val: def
- def2 :: {
+ val: #def
+ #def2: {
a: { b: int }
}
- val2: def2
+ val2: #def2
}`,
out: unindent(`
{
@@ -400,15 +400,15 @@
foo: 1
bar: baz: 3
}
- def :: {
+ #def: {
a: 1
sub: reg
}
- val: def
- def2 :: {
+ val: #def
+ #def2: {
a: b: int
}
- val2: def2
+ val2: #def2
}`),
}, {
raw: true,
@@ -457,82 +457,88 @@
raw: true,
eval: true,
in: `{
- Foo :: {
- Bar :: Foo | string
+ #Foo: {
+ #Bar: #Foo | string
}
}`,
out: unindent(`
{
- Foo :: {
- Bar :: Foo | string
+ #Foo: {
+ #Bar: #Foo | string
}
}`),
}, {
raw: true,
eval: true,
in: `{
- FindInMap :: {
- "Fn::FindInMap" :: [string | FindInMap]
+ #FindInMap: {
+ #: "Fn::FindInMap": [string | #FindInMap]
}
a: [...string]
}`,
out: unindent(`
{
- FindInMap :: {
- "Fn::FindInMap" :: [string | FindInMap]
+ #FindInMap: {
+ #: {
+ "Fn::FindInMap": [string | #FindInMap]
+ }
}
a: [...string]
- }`)}, {
+ }`),
+ }, {
raw: true,
eval: true,
noOpt: true,
in: `{
- And :: {
- "Fn::And": [...(3 | And)]
+ #And: {
+ #: "Fn::And": [...(3 | #And)]
}
- Ands: And & {
- "Fn::And" : [_]
+ #Ands: #And & {
+ #: "Fn::And" : [_]
}
}`,
out: unindent(`
{
- And :: {
- "Fn::And": [...3 | And]
+ #And: {
+ #: {
+ "Fn::And": [...3 | #And]
+ }
}
- Ands: And & {
- "Fn::And": [_]
+ #Ands: #And & {
+ #: {
+ "Fn::And": [_]
+ }
}
}`),
}, {
raw: true,
eval: true,
in: `{
- Foo :: {
- sgl: Bar
- ref: null | Foo
- ext: Bar | null
- ref: null | Foo
- ref2: null | Foo.sgl
+ #Foo: {
+ sgl: #Bar
+ ref: null | #Foo
+ ext: #Bar | null
+ ref: null | #Foo
+ ref2: null | #Foo.sgl
...
}
- Foo :: {
- Foo: 2
+ #Foo: {
+ "#Foo": 2
...
}
- Bar :: string
+ #Bar: string
}`,
out: unindent(`
{
- FOO = Foo
- Foo :: {
- Foo: 2
- sgl: Bar
- ref: (null | FOO) & (null | FOO)
- ext: Bar | null
- ref2: null | FOO.sgl
+ #Foo: {
+ "#Foo": 2
+ sgl: #Bar
+ ref: (null | #Foo) & (null | #Foo)
+ ext: #Bar | null
+ ref2: null | #Foo.sgl
...
}
- Bar :: string
+ #Bar: string
}`),
}, {
raw: true,
@@ -698,8 +704,8 @@
B: {}
B: {a: int} | {b: int}
- C :: [D]: int
- D :: string
+ #C: [#D]: int
+ #D: string
`,
out: unindent(`
A: {
@@ -710,11 +716,11 @@
} | {
b: int
})
- C :: {
- [D]: int
- [D]: int
+ #C: {
+ [#D]: int
+ [#D]: int
}
- D :: string`),
+ #D: string`),
}, {
in: `
a: {
@@ -747,18 +753,18 @@
eval: true,
opts: []Option{ResolveReferences(true)},
in: `
- A :: { b: int }
- a: A & { [string]: <10 }
- B :: a
+ #A: { b: int }
+ a: #A & { [string]: <10 }
+ #B: a
`,
out: unindent(`
- A :: {
+ #A: {
b: int
}
a: close({
b: <10
})
- B :: {
+ #B: {
b: <10
}`),
}, {
@@ -766,12 +772,12 @@
opts: []Option{Final()},
in: `{
reg: { foo: 1, bar: { baz: 3 } }
- def :: {
+ #def: {
a: 1
sub: reg
}
- val: def
+ val: #def
}`,
out: unindent(`
{
@@ -791,23 +797,23 @@
eval: true,
opts: []Option{ResolveReferences(true)},
in: `
- T :: {
+ #T: {
[_]: int64
}
- X :: {
+ #X: {
x: int
- } & T
- x: X
+ } & #T
+ x: #X
`,
out: unindent(`
- T :: {
- [string]: int64
- }
x: {
{[string]: int64}
x: int64
}
- X :: {
+ #T: {
+ [string]: int64
+ }
+ #X: {
{[string]: int64}
x: int64
}`),
@@ -815,18 +821,18 @@
eval: true,
opts: []Option{Optional(false), ResolveReferences(true)},
in: `
- T :: {
+ #T: {
[_]: int64
}
- X :: {
+ #X: {
x: int
- } & T
- x: X
+ } & #T
+ x: #X
`,
out: unindent(`
- T :: {}
x: x: int64
- X :: {
+ #T: {}
+ #X: {
x: int64
}`),
}, {
@@ -834,16 +840,16 @@
opts: []Option{ResolveReferences(true)},
in: `{
reg: { foo: 1, bar: { baz: 3 } }
- def :: {
+ #def: {
a: 1
-
+
sub: reg
}
- val: def
- def2 :: {
+ val: #def
+ #def2: {
a: { b: int }
}
- val2: def2
+ val2: #def2
}`,
out: unindent(`
{
@@ -851,7 +857,7 @@
foo: 1
bar: baz: 3
}
- def :: {
+ #def: {
a: 1
sub: {
foo: 1
@@ -869,7 +875,7 @@
bar: baz: 3
}
})
- def2 :: {
+ #def2: {
a: b: int
}
val2: close({
@@ -894,21 +900,21 @@
eval: true,
opts: []Option{ResolveReferences(true)},
in: `
- A :: {
+ #A: {
[=~"^[a-s]*$"]: int
}
- B :: {
+ #B: {
[=~"^[m-z]+"]: int
}
- C: {A & B}
- D :: {A & B}
+ C: {#A & #B}
+ #D: {#A & #B}
`,
// TODO: the outer close of C could be optimized away.
out: unindent(`
- A :: {
+ #A: {
[=~"^[a-s]*$"]: int
}
- B :: {
+ #B: {
[=~"^[m-z]+"]: int
}
C: close({
@@ -918,7 +924,7 @@
[=~"^[m-z]+"]: int
})
})
- D :: {
+ #D: {
close({
[=~"^[a-s]*$"]: int
}) & close({
@@ -930,24 +936,24 @@
opts: []Option{Docs(true)},
in: `
// Definition
- A :: {
+ #A: {
// TODO: support
[string]: int
}
// Field
- a: A
+ a: #A
// Pick first comment only.
a: _
`,
out: unindent(`
// Definition
- A :: {
+ #A: {
[string]: int
}
// Field
- a: A`),
+ a: #A`),
}, {
eval: true,
opts: []Option{Docs(true)},
@@ -983,7 +989,9 @@
a: #A.#B
`,
out: unindent(`
- #A: #B: 4
+ #A: {
+ #B: 4
+ }
a: #A.#B`),
}, {
eval: true,
@@ -1032,21 +1040,21 @@
import "math"
import "tool/exec"
- A :: {
+ #A: {
b: 3
}
- a: A
+ a: #A
pi: math.Pi
run: exec.Run
`,
out: unindent(`
import "tool/exec"
- A :: {
+ #A: {
b: 3
}
- a: A
+ a: #A
pi: 3.14159265358979323846264338327950288419716939937510582097494459
run: exec.Run`),
}, {
@@ -1090,19 +1098,19 @@
package tst
x: {
- a: A
- b: A
+ a: #A
+ b: #A
}
- A :: string | [A]
+ #A: string | [#A]
`,
out: unindent(`
{
x: {
- a: A
- b: A
+ a: #A
+ b: #A
}
- A :: string | [A]
+ #A: string | [#A]
}`),
}, {
eval: true,
@@ -1146,16 +1154,16 @@
}, {
eval: true,
in: `
- A :: {
+ #A: {
foo: int @tag2(2)
} @tag2(1)
- A :: {
+ #A: {
foo: 2 @tag(2)
} @tag(1)
`,
- out: `A :: {
+ out: `#A: {
foo: 2 @tag(2) @tag2(2)
} @tag(1) @tag2(1)`,
}}
diff --git a/cue/format/node.go b/cue/format/node.go
index f626851..3915328 100644
--- a/cue/format/node.go
+++ b/cue/format/node.go
@@ -234,7 +234,7 @@
}
func (f *formatter) inlineField(n *ast.Field) *ast.Field {
- regular := isRegularField(n.Token)
+ regular := internal.IsRegularField(n)
// shortcut single-element structs.
// If the label has a valid position, we assume that an unspecified
// Lbrace signals the intend to collapse fields.
diff --git a/cue/format/testdata/expressions.golden b/cue/format/testdata/expressions.golden
index cfc4124..be50d3d 100644
--- a/cue/format/testdata/expressions.golden
+++ b/cue/format/testdata/expressions.golden
@@ -44,7 +44,7 @@
field: 2
}
- openDef :: {
+ #openDef: {
a: int
...
}
diff --git a/cue/format/testdata/expressions.input b/cue/format/testdata/expressions.input
index 9ea36d0..a1be441 100644
--- a/cue/format/testdata/expressions.input
+++ b/cue/format/testdata/expressions.input
@@ -44,7 +44,7 @@
field: 2
}
- openDef :: {
+ #openDef: {
a: int
...
}
diff --git a/cue/parser/parser_test.go b/cue/parser/parser_test.go
index e717836..20d3e1b 100644
--- a/cue/parser/parser_test.go
+++ b/cue/parser/parser_test.go
@@ -103,7 +103,7 @@
`a: true, b?: "2", c?: 3, "g\("en")"?: 4`,
}, {
"definition",
- `Def :: {
+ `#Def: {
b: "2"
c: 3
@@ -111,7 +111,7 @@
}
#Def: {}
`,
- `Def :: {b: "2", c: 3, embedding}, #Def: {}`,
+ `#Def: {b: "2", c: 3, embedding}, #Def: {}`,
}, {
"one-line embedding",
`{ V1, V2 }`,
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index c0c5b60..2c30c64 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -852,11 +852,11 @@
e6: (*[]|{})[1]
def: {
a: 1
- b :: 3
+ #b: 3
}
e7: def["b"]
`,
- out: `<0>{a: 2, b: "bar", c: _|_("3":invalid list index "3" (type string)), l: [], d: _|_([]:index 0 out of bounds), e1: _|_("":invalid list index "" (type string)), e2: _|_(2:invalid operation: 2[2] (type int does not support indexing)), e3: _|_(true:invalid list index true (type bool)), e4: _|_([1,2,3]:index 3 out of bounds), e5: _|_(-1:invalid list index -1 (index must be non-negative)), e6: _|_([]:index 1 out of bounds), def: <1>{a: 1, b :: 3}, e7: _|_(<2>.def["b"]:field "b" is a definition)}`,
+ out: `<0>{a: 2, b: "bar", c: _|_("3":invalid list index "3" (type string)), l: [], d: _|_([]:index 0 out of bounds), e1: _|_("":invalid list index "" (type string)), e2: _|_(2:invalid operation: 2[2] (type int does not support indexing)), e3: _|_(true:invalid list index true (type bool)), e4: _|_([1,2,3]:index 3 out of bounds), e5: _|_(-1:invalid list index -1 (index must be non-negative)), e6: _|_([]:index 1 out of bounds), def: <1>{a: 1, #b: 3}, e7: <2>.def["b"]}`,
// }, {
// NOTE: string indexing no longer supported.
// Keeping it around until this is no longer an experiment.
@@ -1156,7 +1156,7 @@
}, {
desc: "definitions",
in: `
- Foo :: {
+ #Foo: {
field: int
recursive: {
field: string
@@ -1164,13 +1164,13 @@
}
// Allowed
- Foo1 :: { field: int }
- Foo1 :: { field2: string }
+ #Foo1: { field: int }
+ #Foo1: { field2: string }
- foo: Foo
+ foo: #Foo
foo: { feild: 2 }
- foo1: Foo
+ foo1: #Foo
foo1: {
field: 2
recursive: {
@@ -1178,69 +1178,70 @@
}
}
- Bar :: {
+ #Bar: {
field: int
{[A=_]: int}
}
- bar: Bar
+ bar: #Bar
bar: { feild: 2 }
- Mixed :: string
+ #Mixed: string
Mixed: string
- mixedRec: { Mixed :: string }
+ mixedRec: { #Mixed: string }
mixedRec: { Mixed: string }
`,
out: `<0>{` +
- `Foo :: <1>C{field: int, recursive: <2>C{field: string}}, ` +
- `Foo1 :: <3>C{field: int, field2: string}, ` +
+ `#Foo: <1>C{field: int, recursive: <2>C{field: string}}, ` +
+ `#Foo1: <3>C{field: int, field2: string}, ` +
`foo: _|_(2:field "feild" not allowed in closed struct), ` +
`foo1: <4>C{field: 2, recursive: _|_(2:field "feild" not allowed in closed struct)}, ` +
- `Bar :: <5>{[]: <6>(A: string)->int, field: int}, ` +
+ `#Bar: <5>{[]: <6>(A: string)->int, field: int}, ` +
`bar: <7>{[]: <8>(A: string)->int, field: int, feild: 2}, ` +
- `Mixed: _|_(field "Mixed" declared as definition and regular field), ` +
- `mixedRec: _|_(field "Mixed" declared as definition and regular field)}`,
+ `#Mixed: string, ` +
+ `Mixed: string, ` +
+ `mixedRec: <9>{#Mixed: string, Mixed: string}}`,
}, {
desc: "combined definitions",
in: `
// Allow combining of structs within a definition
- D1 :: {
+ #D1: {
env: a: "A"
env: b: "B"
- def :: {a: "A"}
- def :: {b: "B"}
+ #def: {a: "A"}
+ #def: {b: "B"}
}
- d1: D1 & { env: c: "C" }
+ d1: #D1 & { env: c: "C" }
- D2 :: {
+ #D2: {
a: int
}
- D2 :: {
+ #D2: {
b: int
}
- D3 :: {
+ #D3: {
env: a: "A"
}
- D3 :: {
+ #D3: {
env: b: "B"
}
- D4 :: {
- env: DC
+ #D4: {
+ env: #DC
env: b: int
}
- DC :: { a: int }
+ #DC: { a: int }
`,
out: `<0>{` +
- `D1 :: <1>C{env: <2>C{a: "A", b: "B"}, def :: <3>C{a: "A", b: "B"}}, ` +
- `d1: <4>C{env: _|_("C":field "c" not allowed in closed struct), def :: <5>C{a: "A", b: "B"}}, ` +
- `D2 :: <6>C{a: int, b: int}, ` +
- `D3 :: <7>C{env: <8>C{a: "A", b: "B"}}, ` +
- `D4 :: <9>C{env: _|_(int:field "b" not allowed in closed struct)}, ` +
- `DC :: <10>C{a: int}` +
+ `#D1: <1>C{env: <2>C{a: "A", b: "B"}, #def: <3>C{a: "A", b: "B"}}, ` +
+ `d1: <4>C{env: _|_("C":field "c" not allowed in closed struct), #def: <5>C{a: "A", b: "B"}}, ` +
+ `#D2: <6>C{a: int, b: int}, ` +
+ `#D3: <7>C{env: <8>C{a: "A", b: "B"}}, ` +
+ `#D4: <9>C{env: _|_(int:field "b" not allowed in closed struct)}, ` +
+ `#DC: <10>C{a: int}` +
`}`,
}, {
desc: "new-style definitions",
@@ -1266,71 +1267,71 @@
desc: "recursive closing starting at non-definition",
in: `
z: a: {
- B:: {
+ #B: {
c: d: 1
c: f: 1
}
}
- A: z & { a: { B :: { c: e: 2 } } }
+ A: z & { a: { #B: { c: e: 2 } } }
`,
- out: `<0>{z: <1>{a: <2>{B :: <3>C{c: <4>C{d: 1, f: 1}}}}, A: <5>{a: <6>{B :: <7>C{c: _|_(2:field "e" not allowed in closed struct)}}}}`,
+ out: `<0>{z: <1>{a: <2>{#B: <3>C{c: <4>C{d: 1, f: 1}}}}, A: <5>{a: <6>{#B: <7>C{c: _|_(2:field "e" not allowed in closed struct)}}}}`,
}, {
desc: "non-closed definition carries over closedness to enclosed template",
in: `
- S :: {
+ #S: {
[string]: { a: int }
}
- a: S & {
+ a: #S & {
v: { b: int }
}
- Q :: {
+ #Q: {
[string]: { a: int } | { b: int }
}
- b: Q & {
+ b: #Q & {
w: { c: int }
}
- R :: {
+ #R: {
[string]: [{ a: int }, { b: int }]
}
- c: R & {
+ c: #R & {
w: [{ d: int }, ...]
}
`,
out: `<0>{` +
- `S :: <1>{[]: <2>(_: string)-><3>C{a: int}, }, ` +
+ `#S: <1>{[]: <2>(_: string)-><3>C{a: int}, }, ` +
`a: <4>{[]: <5>(_: string)-><6>C{a: int}, v: _|_(int:field "b" not allowed in closed struct)}, ` +
`b: <7>{[]: <8>(_: string)->(<9>C{a: int} | <10>C{b: int}), w: _|_(int:empty disjunction: field "c" not allowed in closed struct)}, ` +
- `Q :: <11>{[]: <12>(_: string)->(<13>C{a: int} | <14>C{b: int}), }, ` +
+ `#Q: <11>{[]: <12>(_: string)->(<13>C{a: int} | <14>C{b: int}), }, ` +
`c: <15>{[]: <16>(_: string)->[<17>C{a: int},<18>C{b: int}], w: [_|_(int:field "d" not allowed in closed struct),<19>C{b: int}]}, ` +
- `R :: <20>{[]: <21>(_: string)->[<22>C{a: int},<23>C{b: int}], }}`,
+ `#R: <20>{[]: <21>(_: string)->[<22>C{a: int},<23>C{b: int}], }}`,
}, {
desc: "definitions with disjunctions",
in: `
- Foo :: {
+ #Foo: {
field: int
{ a: 1 } |
{ b: 2 }
}
- foo: Foo
+ foo: #Foo
foo: { a: 1 }
- bar: Foo
+ bar: #Foo
bar: { c: 2 }
- baz: Foo
+ baz: #Foo
baz: { b: 2 }
`,
out: `<0>{` +
- `Foo :: (<1>C{field: int, a: 1} | <2>C{field: int, b: 2}), ` +
+ `#Foo: (<1>C{field: int, a: 1} | <2>C{field: int, b: 2}), ` +
`foo: <3>C{field: int, a: 1}, ` +
`bar: _|_(2:empty disjunction: field "c" not allowed in closed struct), ` +
`baz: <4>C{field: int, b: 2}}`,
}, {
desc: "definitions with disjunctions recurisive",
in: `
- Foo :: {
+ #Foo: {
x: {
field: int
@@ -1341,41 +1342,41 @@
}
`,
out: `<0>{` +
- `Foo :: <1>C{x: (<2>C{field: int, a: 1, c: 3} | <3>C{field: int, b: 2, c: 3})}` +
+ `#Foo: <1>C{x: (<2>C{field: int, a: 1, c: 3} | <3>C{field: int, b: 2, c: 3})}` +
`}`,
}, {
desc: "definitions with embedding",
in: `
- E :: {
+ #E: {
a: { b: int }
}
- S :: {
- E
+ #S: {
+ #E
a: { c: int }
b: 3
}
// adding a field to a nested struct that is closed.
- e1 :: S & { a: d: 4 }
+ #e1: #S & { a: d: 4 }
// literal struct not closed until after unification.
- v1 :: S & { a: c: 4 }
+ #v1: #S & { a: c: 4 }
`,
out: `<0>{` +
- `E :: <1>C{a: <2>C{b: int}}, ` +
- `S :: <3>C{a: <4>C{b: int, c: int}, b: 3}, ` +
- `e1 :: <5>C{a: _|_(4:field "d" not allowed in closed struct), b: 3}, ` +
- `v1 :: <6>C{a: <7>C{b: int, c: 4}, b: 3}}`,
+ `#E: <1>C{a: <2>C{b: int}}, ` +
+ `#S: <3>C{a: <4>C{b: int, c: int}, b: 3}, ` +
+ `#e1: <5>C{a: _|_(4:field "d" not allowed in closed struct), b: 3}, ` +
+ `#v1: <6>C{a: <7>C{b: int, c: 4}, b: 3}}`,
}, {
desc: "top-level definition with struct and disjunction",
in: `
- def :: {
+ #def: {
Type: string
Text: string
Size: int
}
- def :: {
+ #def: {
Type: "B"
Size: 0
} | {
@@ -1383,7 +1384,7 @@
Size: 1
}`,
out: `<0>{` +
- `def :: (<1>C{Size: (0 & int), Type: ("B" & string), Text: string} | ` +
+ `#def: (<1>C{Size: (0 & int), Type: ("B" & string), Text: string} | ` +
`<2>C{Size: (1 & int), Type: ("A" & string), Text: string})` +
`}`,
}, {
@@ -1429,7 +1430,7 @@
}, {
desc: "excluded embedding from closing",
in: `
- S :: {
+ #S: {
a: { c: int }
{
c: { d: int }
@@ -1437,13 +1438,13 @@
B = { open: int }
b: B
}
- V: S & {
+ V: #S & {
c: e: int
b: extra: int
}
`,
out: `<0>{` +
- `S :: <1>C{` +
+ `#S: <1>C{` +
`a: <2>C{c: int}, ` +
`c: <3>{d: int}, ` +
`b: <4>{open: int}}, ` +
@@ -1454,70 +1455,70 @@
}, {
desc: "closing with failed optional",
in: `
- k1 :: {a: int, b?: int} & A // closed({a: int})
- k2 :: A & {a: int, b?: int} // closed({a: int})
+ #k1: {a: int, b?: int} & #A // closed({a: int})
+ #k2: #A & {a: int, b?: int} // closed({a: int})
o1: {a?: 3} & {a?: 4} // {a?: _|_}
// Optional fields with error values can be elimintated when closing
- o2 :: {a?: 3} & {a?: 4} // close({})
+ #o2: {a?: 3} & {a?: 4} // close({})
- d1 :: {a?: 2, b: 4} | {a?: 3, c: 5}
- v1: d1 & {a?: 3, b: 4} // close({b: 4})
+ #d1: {a?: 2, b: 4} | {a?: 3, c: 5}
+ v1: #d1 & {a?: 3, b: 4} // close({b: 4})
- A :: {a: int}
+ #A: {a: int}
`,
out: `<0>{` +
- `k1 :: <1>C{a: int}, ` +
- `A :: <2>C{a: int}, ` +
- `k2 :: <3>C{a: int}, ` +
+ `#k1: <1>C{a: int}, ` +
+ `#A: <2>C{a: int}, ` +
+ `#k2: <3>C{a: int}, ` +
`o1: <4>{a?: _|_((3 & 4):conflicting values 3 and 4)}, ` +
- `o2 :: <5>C{a?: _|_((3 & 4):conflicting values 3 and 4)}, ` +
- `d1 :: (<6>C{a?: 2, b: 4} | <7>C{a?: 3, c: 5}), ` +
+ `#o2: <5>C{a?: _|_((3 & 4):conflicting values 3 and 4)}, ` +
+ `#d1: (<6>C{a?: 2, b: 4} | <7>C{a?: 3, c: 5}), ` +
`v1: <8>C{a?: _|_((2 & 3):conflicting values 2 and 3), b: 4}` +
`}`,
}, {
desc: "closing with comprehensions",
in: `
- A :: {f1: int, f2: int}
+ #A: {f1: int, f2: int}
for k, v in {f3 : int} {
- a: A & { "\(k)": v }
+ a: #A & { "\(k)": v }
}
- B :: {
+ #B: {
for k, v in {f1: int} {
"\(k)": v
}
}
- C :: {
+ #C: {
f1: _
for k, v in {f1: int} {
"\(k)": v
}
}
- D :: {
+ #D: {
for k, v in {f1: int} {
"\(k)": v
}
...
}
- E :: A & {
+ #E: #A & {
for k, v in { f3: int } {
"\(k)": v
}
}
`,
out: `<0>{` +
- `E :: _|_(<1>.v:field "f3" not allowed in closed struct), ` +
- `A :: <2>C{f1: int, f2: int}, ` +
- `a: _|_(<3>.v:field "f3" not allowed in closed struct), ` +
- `B :: <4>C{f1: int}, ` +
- `C :: <5>C{f1: int}, ` +
- `D :: <6>{f1: int, ...}` +
+ `#A: <1>C{f1: int, f2: int}, ` +
+ `a: _|_(<2>.v:field "f3" not allowed in closed struct), ` +
+ `#B: <3>C{f1: int}, ` +
+ `#C: <4>C{f1: int}, ` +
+ `#D: <5>{f1: int, ...}, ` +
+ `#E: _|_(<6>.v:field "f3" not allowed in closed struct)` +
`}`,
}, {
desc: "incomplete comprehensions",
@@ -1792,7 +1793,7 @@
}
}
- for k, v in { def :: 1, opt?: 2, _hid: 3, reg: 4 } {
+ for k, v in { #def: 1, opt?: 2, _hid: 3, reg: 4 } {
"\(k)": v
}
`,
@@ -2535,7 +2536,7 @@
foo: {
opt?: 1
"txt": 2
- def :: 3
+ #def: 3
regular: 4
_hidden: 5
}
@@ -2543,41 +2544,41 @@
select: {
opt: foo.opt
"txt": foo.txt
- def :: foo.def
+ #def: foo.#def
regular: foo.regular
_hidden: foo._hidden
}
index: {
opt: foo["opt"]
"txt": foo["txt"]
- def :: foo["def"]
+ #def: foo["#def"]
regular: foo["regular"]
_hidden: foo["_hidden"]
}
`,
out: `<0>{` +
- `foo: <1>{opt?: 1, txt: 2, def :: 3, regular: 4, _hidden: 5}, ` +
+ `foo: <1>{opt?: 1, txt: 2, #def: 3, regular: 4, _hidden: 5}, ` +
`comp: <2>{txt: 2, regular: 4}, ` +
- `select: <3>{opt: <4>.foo.opt, txt: 2, def :: 3, regular: 4, _hidden: 5}, ` +
- `index: <5>{opt: <4>.foo["opt"], txt: 2, def :: _|_(<4>.foo["def"]:field "def" is a definition), regular: 4, _hidden: <4>.foo["_hidden"]}}`,
+ `select: <3>{opt: <4>.foo.opt, txt: 2, #def: 3, regular: 4, _hidden: 5}, ` +
+ `index: <5>{opt: <4>.foo["opt"], txt: 2, #def: <4>.foo["#def"], regular: 4, _hidden: <4>.foo["_hidden"]}}`,
}, {
desc: "retain references with interleaved embedding",
in: `
a: d: {
- base
- info :: {...}
- Y: info.X
+ #base
+ #info: {...}
+ Y: #info.X
}
- base :: {
- info :: {...}
+ #base: {
+ #info: {...}
}
- a: [Name=string]: { info :: {
+ a: [Name=string]: { #info: {
X: "foo"
}}
`,
- out: `<0>{a: <1>{[]: <2>(Name: string)-><3>{info :: <4>C{X: "foo"}}, d: <5>C{info :: <6>C{X: "foo"}, Y: "foo"}}, base :: <7>C{info :: <8>{...}}}`,
+ out: `<0>{a: <1>{[]: <2>(Name: string)-><3>{#info: <4>C{X: "foo"}}, d: <5>C{#info: <6>C{X: "foo"}, Y: "foo"}}, #base: <7>C{#info: <8>{...}}}`,
}, {
desc: "comparison against bottom",
in: `
@@ -2598,35 +2599,35 @@
}, {
desc: "or builtin should not fail on non-concrete empty list",
in: `
- Workflow :: {
+ #Workflow: {
jobs: {
[jobID=string]: {
}
}
- JobID :: or([ for k, _ in jobs { k } ])
+ #JobID: or([ for k, _ in jobs { k } ])
}
- foo: Workflow & {
+ foo: #Workflow & {
jobs: foo: {
}
}
`,
- out: `<0>{Workflow :: <1>C{jobs: <2>{[]: <3>(jobID: string)-><4>C{}, }, JobID :: or ([ <5>for k, _ in <6>.jobs yield <5>.k ])}, foo: <7>C{jobs: <8>{[]: <9>(jobID: string)-><10>C{}, foo: <11>C{}}, JobID :: "foo"}}`,
+ out: `<0>{#Workflow: <1>C{jobs: <2>{[]: <3>(jobID: string)-><4>C{}, }, #JobID: or ([ <5>for k, _ in <6>.jobs yield <5>.k ])}, foo: <7>C{jobs: <8>{[]: <9>(jobID: string)-><10>C{}, foo: <11>C{}}, #JobID: "foo"}}`,
}, {
desc: "Issue #153",
in: `
Foo: {
- listOfCloseds: [...Closed]
+ listOfCloseds: [...#Closed]
}
-
- Closed :: {
+
+ #Closed: {
a: int | *0
}
-
+
Junk: {
b: 2
}
-
+
Foo & {
listOfCloseds: [{
for k, v in Junk {
@@ -2635,7 +2636,7 @@
}]
}
`,
- out: `<0>{<1>{listOfCloseds: [_|_(<2>.v:field "b" not allowed in closed struct)]}, Foo: <3>{listOfCloseds: []}, Closed :: <4>C{a: 0}, Junk: <5>{b: 2}}`,
+ out: `<0>{<1>{listOfCloseds: [_|_(<2>.v:field "b" not allowed in closed struct)]}, Foo: <3>{listOfCloseds: []}, #Closed: <4>C{a: 0}, Junk: <5>{b: 2}}`,
}, {
desc: "label and field aliases",
in: `
@@ -2657,38 +2658,38 @@
`c: 5, ` +
`str: 5}`,
}, {
- desc: "optionals with label fiters",
+ desc: "optionals with label filters",
in: `
- JobID :: =~"^[a-zA-Z]*$"
- Job :: {
+ #JobID: =~"^[a-zA-Z]*$"
+ #Job: {
name: string
cmd: string
}
- Jobs :: {
- [JobID]: Job
+ #Jobs: {
+ [#JobID]: #Job
[=~"Test$"]: name: =~"^test" // Must work without ...
}
jobs: foo: name: "allGood"
jobs: foo: name: "allGood"
- jobs1: Jobs
+ jobs1: #Jobs
jobs1: foo1: {} // faulty
- jobs2: Jobs
+ jobs2: #Jobs
jobs2: fooTest: name: "badName" // faulty
- jobs3: Jobs
- jobs3: [string]: Job
+ jobs3: #Jobs
+ jobs3: [string]: #Job
jobs3: fooTest1: name: "badName" // faulty
`,
out: `<0>{` +
- `JobID :: =~"^[a-zA-Z]*$", ` +
- `Job :: <1>C{name: string, cmd: string}, ` +
- `Jobs :: <2>C{[=~"^[a-zA-Z]*$"]: <3>(_: string)-><4>.Job, [=~"Test$"]: <5>(_: string)-><6>C{name: =~"^test"}, }, ` +
+ `#JobID: =~"^[a-zA-Z]*$", ` +
+ `#Job: <1>C{name: string, cmd: string}, ` +
+ `#Jobs: <2>C{[=~"^[a-zA-Z]*$"]: <3>(_: string)-><4>.#Job, [=~"Test$"]: <5>(_: string)-><6>C{name: =~"^test"}, }, ` +
`jobs: <7>{foo: <8>{name: "allGood"}}, ` +
`jobs1: _|_(<9>{}:field "foo1" not allowed in closed struct), ` +
- `jobs2: <10>C{[=~"^[a-zA-Z]*$"]: <11>(_: string)-><4>.Job, [=~"Test$"]: <12>(_: string)-><13>C{name: =~"^test"}, fooTest: _|_(string:field "cmd" not allowed in closed struct)}, ` +
+ `jobs2: <10>C{[=~"^[a-zA-Z]*$"]: <11>(_: string)-><4>.#Job, [=~"Test$"]: <12>(_: string)-><13>C{name: =~"^test"}, fooTest: _|_(string:field "cmd" not allowed in closed struct)}, ` +
`jobs3: _|_(<14>{name: "badName"}:field "fooTest1" not allowed in closed struct)}`,
}, {
desc: "optionals in open structs",
@@ -2699,75 +2700,75 @@
B: {
[=~"^[m-z]*$"]: int
}
- C :: {A & B}
- c: C & { aaa: 3 }
+ #C: {A & B}
+ c: #C & { aaa: 3 }
`,
- out: `<0>{A: <1>{[=~"^[a-s]*$"]: <2>(_: string)->int, }, B: <3>{[=~"^[m-z]*$"]: <4>(_: string)->int, }, C :: <5>C{[=~"^[a-s]*$"]: <6>(_: string)->int, [=~"^[m-z]*$"]: <7>(_: string)->int, }, c: <8>C{[=~"^[a-s]*$"]: <9>(_: string)->int, [=~"^[m-z]*$"]: <10>(_: string)->int, aaa: 3}}`,
+ out: `<0>{A: <1>{[=~"^[a-s]*$"]: <2>(_: string)->int, }, B: <3>{[=~"^[m-z]*$"]: <4>(_: string)->int, }, #C: <5>C{[=~"^[a-s]*$"]: <6>(_: string)->int, [=~"^[m-z]*$"]: <7>(_: string)->int, }, c: <8>C{[=~"^[a-s]*$"]: <9>(_: string)->int, [=~"^[m-z]*$"]: <10>(_: string)->int, aaa: 3}}`,
}, {
desc: "conjunction of optional sets",
in: `
- A :: {
+ #A: {
[=~"^[a-s]*$"]: int
}
- B :: {
+ #B: {
[=~"^[m-z]*$"]: int
}
- C :: A & B
- c: C & { aaa: 3 }
+ #C: #A & #B
+ c: #C & { aaa: 3 }
- D :: {A & B}
- d: D & { aaa: 3 }
+ #D: {#A & #B}
+ d: #D & { aaa: 3 }
`,
out: `<0>{` +
- `A :: <1>C{[=~"^[a-s]*$"]: <2>(_: string)->int, }, ` +
- `B :: <3>C{[=~"^[m-z]*$"]: <4>(_: string)->int, }, ` +
- `C :: <5>C{(C{[=~"^[a-s]*$"]: <6>(_: string)->int} & C{[=~"^[m-z]*$"]: <7>(_: string)->int}), }, ` +
+ `#A: <1>C{[=~"^[a-s]*$"]: <2>(_: string)->int, }, ` +
+ `#B: <3>C{[=~"^[m-z]*$"]: <4>(_: string)->int, }, ` +
+ `#C: <5>C{(C{[=~"^[a-s]*$"]: <6>(_: string)->int} & C{[=~"^[m-z]*$"]: <7>(_: string)->int}), }, ` +
`c: _|_(3:field "aaa" not allowed in closed struct), ` +
- `D :: <8>C{(C{[=~"^[a-s]*$"]: <9>(_: string)->int} & C{[=~"^[m-z]*$"]: <10>(_: string)->int}), }, ` +
+ `#D: <8>C{(C{[=~"^[a-s]*$"]: <9>(_: string)->int} & C{[=~"^[m-z]*$"]: <10>(_: string)->int}), }, ` +
`d: _|_(3:field "aaa" not allowed in closed struct)` +
`}`,
}, {
desc: "continue recursive closing for optionals",
in: `
- S :: {
+ #S: {
[string]: { a: int }
}
- a: S & {
+ a: #S & {
v: { b: int }
}
`,
- out: `<0>{S :: <1>{[]: <2>(_: string)-><3>C{a: int}, }, a: <4>{[]: <5>(_: string)-><6>C{a: int}, v: _|_(int:field "b" not allowed in closed struct)}}`,
+ out: `<0>{#S: <1>{[]: <2>(_: string)-><3>C{a: int}, }, a: <4>{[]: <5>(_: string)-><6>C{a: int}, v: _|_(int:field "b" not allowed in closed struct)}}`,
}, {
desc: "augment closed optionals",
in: `
- A :: {
+ #A: {
[=~"^[a-s]*$"]: int
}
- B :: {
+ #B: {
[=~"^[m-z]*?"]: int
}
- C :: {
- A & B
+ #C: {
+ #A & #B
[=~"^Q*$"]: int
}
- c: C & { QQ: 3 }
- D :: {
- A
- B
+ c: #C & { QQ: 3 }
+ #D: {
+ #A
+ #B
}
- d: D & { aaa: 4 }
+ d: #D & { aaa: 4 }
`,
out: `<0>{` +
- `A :: <1>C{[=~"^[a-s]*$"]: <2>(_: string)->int, }, ` +
- `B :: <3>C{[=~"^[m-z]*?"]: <4>(_: string)->int, }, ` +
- `C :: <5>C{C{[=~"^Q*$"]: <6>(_: string)->int}, C{(C{[=~"^[a-s]*$"]: <7>(_: string)->int} & C{[=~"^[m-z]*?"]: <8>(_: string)->int})}, }, ` +
+ `#A: <1>C{[=~"^[a-s]*$"]: <2>(_: string)->int, }, ` +
+ `#B: <3>C{[=~"^[m-z]*?"]: <4>(_: string)->int, }, ` +
+ `#C: <5>C{C{[=~"^Q*$"]: <6>(_: string)->int}, C{(C{[=~"^[a-s]*$"]: <7>(_: string)->int} & C{[=~"^[m-z]*?"]: <8>(_: string)->int})}, }, ` +
`c: <9>C{C{[=~"^Q*$"]: <10>(_: string)->int}, C{(C{[=~"^[a-s]*$"]: <11>(_: string)->int} & C{[=~"^[m-z]*?"]: <12>(_: string)->int})}, QQ: 3}, ` +
- `D :: <13>C{[=~"^[a-s]*$"]: <14>(_: string)->int, [=~"^[m-z]*?"]: <15>(_: string)->int, }, ` +
+ `#D: <13>C{[=~"^[a-s]*$"]: <14>(_: string)->int, [=~"^[m-z]*?"]: <15>(_: string)->int, }, ` +
`d: <16>C{[=~"^[a-s]*$"]: <17>(_: string)->int, [=~"^[m-z]*?"]: <18>(_: string)->int, aaa: 4}}`,
}, {
in: `
- Task :: {
+ #Task: {
{
op: "pull"
tag: *"latest" | string
@@ -2779,21 +2780,21 @@
}
}
- foo: Task & {"op": "pull"}
+ foo: #Task & {"op": "pull"}
`,
- out: `<0>{Task :: (<1>C{op: "pull", tag: (*"latest" | string), refToTag: <1>.tag, tagExpr: (<1>.tag + "dd"), tagInString: ""+<1>.tag+""} | <2>C{op: "scratch"}), foo: <3>C{op: "pull", tag: "latest", refToTag: "latest", tagExpr: "latestdd", tagInString: "latest"}}`,
+ out: `<0>{#Task: (<1>C{op: "pull", tag: (*"latest" | string), refToTag: <1>.tag, tagExpr: (<1>.tag + "dd"), tagInString: ""+<1>.tag+""} | <2>C{op: "scratch"}), foo: <3>C{op: "pull", tag: "latest", refToTag: "latest", tagExpr: "latestdd", tagInString: "latest"}}`,
}, {
in: `
t: {
- ok :: *true | bool
- if ok {
+ #ok: *true | bool
+ if #ok {
x: int
}
}
s: t & {
- ok :: false
+ #ok: false
}`,
- out: `<0>{t: <1>{x: int, ok :: true}, s: <2>{ok :: false}}`,
+ out: `<0>{t: <1>{x: int, #ok: true}, s: <2>{#ok: false}}`,
}, {
desc: "cross-dependent comprehension",
// TODO(eval): fix: c should ultimately be allowed the struct. Current
@@ -2802,18 +2803,18 @@
// checks and allowing this would be more intuitive.
// Until that time, ensure that the behavior is at commutative.
in: `
- a :: {
+ #a: {
if b {
c: 4
}
b: bool
}
- x: (a & { b: true}) & {c: 4 }
+ x: (#a & { b: true}) & {c: 4 }
y: x
`,
// c should not be allowed, as it would break commutativiy.
// See comments above.
- out: `<0>{x: _|_(4:field "c" not allowed in closed struct), y: _|_(4:field "c" not allowed in closed struct), a :: <1>C{b: bool if <2>.b yield <3>C{c: 4}}}`,
+ out: `<0>{x: _|_(4:field "c" not allowed in closed struct), y: _|_(4:field "c" not allowed in closed struct), #a: <1>C{b: bool if <2>.b yield <3>C{c: 4}}}`,
}, {
desc: "optional expanded before lookup",
in: `
@@ -2885,26 +2886,26 @@
}, {
desc: "alias reuse in nested scope",
in: `
- Foo :: {
+ #Foo: {
let X = or([ for k, _ in {} { k } ])
connection: [X]: X
}
- A :: {
+ #A: {
foo: "key"
let X = foo
a: foo: [X]: X
}
- B :: {
+ #B: {
foo: string
let X = foo
a: foo: [X]: X
}
- b: B & { foo: "key" }
+ b: #B & { foo: "key" }
`,
out: `<0>{` +
- `Foo :: <1>C{connection: <2>C{[or ([ <3>for k, _ in <4>{} yield <3>.k ])]: <5>(_: string)->or ([ <3>for k, _ in <4>{} yield <3>.k ]), }}, ` +
- `A :: <6>C{foo: "key", a: <7>C{foo: <8>C{["key"]: <9>(_: string)-><10>.foo, }}}, ` +
- `B :: <11>C{foo: string, a: <12>C{foo: <13>C{[string]: <14>(_: string)-><15>.foo, }}}, ` +
+ `#Foo: <1>C{connection: <2>C{[or ([ <3>for k, _ in <4>{} yield <3>.k ])]: <5>(_: string)->or ([ <3>for k, _ in <4>{} yield <3>.k ]), }}, ` +
+ `#A: <6>C{foo: "key", a: <7>C{foo: <8>C{["key"]: <9>(_: string)-><10>.foo, }}}, ` +
+ `#B: <11>C{foo: string, a: <12>C{foo: <13>C{[string]: <14>(_: string)-><15>.foo, }}}, ` +
`b: <16>C{foo: "key", a: <17>C{foo: <18>C{["key"]: <19>(_: string)-><20>.foo, }}}` +
`}`,
}, {
@@ -2926,22 +2927,22 @@
package foobar
import yaml "encoding/yaml"
-
- Spec :: {
+
+ #Spec: {
_vars: {something: string}
data: {
- foo :: {
+ #foo: {
use: _vars.something
}
baz: yaml.Marshal(_vars.something)
- foobar: yaml.Marshal(foo)
+ foobar: yaml.Marshal(#foo)
}
}
- Val: Spec & {
+ Val: #Spec & {
_vars: something: "var-string"
}
`,
- out: `<0>{Spec :: <1>C{_vars: <2>C{something: string}, data: <3>C{foo :: <4>C{use: string}, baz: <5>.Marshal (<6>._vars.something), foobar: <5>.Marshal (<7>.foo)}}, Val: <8>C{_vars: <9>C{something: "var-string"}, data: <10>C{foo :: <11>C{use: "var-string"}, baz: "var-string\n", foobar: "use: var-string\n"}}}`,
+ out: `<0>{#Spec: <1>C{_vars: <2>C{something: string}, data: <3>C{#foo: <4>C{use: string}, baz: <5>.Marshal (<6>._vars.something), foobar: <5>.Marshal (<7>.#foo)}}, Val: <8>C{_vars: <9>C{something: "var-string"}, data: <10>C{#foo: <11>C{use: "var-string"}, baz: "var-string\n", foobar: "use: var-string\n"}}}`,
}, {
desc: "detectIncompleteJSON",
in: `
@@ -2949,21 +2950,21 @@
import "encoding/json"
- Spec :: {
+ #Spec: {
_vars: {something: string}
data: {
- foo :: {
+ #foo: {
use: _vars.something
}
baz: json.Marshal(_vars.something)
- foobar: json.Marshal(foo)
+ foobar: json.Marshal(#foo)
}
}
- Val: Spec & {
+ Val: #Spec & {
_vars: something: "var-string"
}
`,
- out: `<0>{Spec :: <1>C{_vars: <2>C{something: string}, data: <3>C{foo :: <4>C{use: string}, baz: <5>.Marshal (<6>._vars.something), foobar: <5>.Marshal (<7>.foo)}}, Val: <8>C{_vars: <9>C{something: "var-string"}, data: <10>C{foo :: <11>C{use: "var-string"}, baz: "\"var-string\"", foobar: "{\"use\":\"var-string\"}"}}}`,
+ out: `<0>{#Spec: <1>C{_vars: <2>C{something: string}, data: <3>C{#foo: <4>C{use: string}, baz: <5>.Marshal (<6>._vars.something), foobar: <5>.Marshal (<7>.#foo)}}, Val: <8>C{_vars: <9>C{something: "var-string"}, data: <10>C{#foo: <11>C{use: "var-string"}, baz: "\"var-string\"", foobar: "{\"use\":\"var-string\"}"}}}`,
}, {
desc: "issue312",
in: `
@@ -2985,7 +2986,7 @@
}, {
desc: "issue318",
in: `
- T :: {
+ #T: {
arg: x: string
out1: "\(arg.x) \(arg.y)"
out2: "\(arg.y)"
@@ -2994,7 +2995,7 @@
}
`,
out: `<0>{` +
- `T :: <1>C{` +
+ `#T: <1>C{` +
`arg: <2>C{x: string}, ` +
`out1: _|_(<3>.arg.y:undefined field "y"), ` +
`out2: _|_(<3>.arg.y:undefined field "y"), ` +
@@ -3011,30 +3012,30 @@
x: {
s: "myname"
- T
+ #T
}
- T :: {
+ #T: {
s: string
out: template.Execute("{{.s}}", {
"s": s
})
}
- V :: {
+ #V: {
s: string
out: json.Marshal({"s": s})
}
- U :: {
+ #U: {
s: string
out: yaml.Marshal({"s": s})
}`,
out: `<0>{` +
- `T :: <1>C{s: string, out: <2>.Execute ("{{.s}}",<3>C{s: <4>.s})}, ` +
- `x: <5>C{s: "myname", out: "myname"}, ` +
- `V :: <6>C{s: string, out: <7>.Marshal (<8>C{s: <9>.s})}, ` +
- `U :: <10>C{s: string, out: <11>.Marshal (<12>C{s: <13>.s})}}`,
+ `x: <1>C{s: "myname", out: "myname"}, ` +
+ `#T: <2>C{s: string, out: <3>.Execute ("{{.s}}",<4>C{s: <5>.s})}, ` +
+ `#V: <6>C{s: string, out: <7>.Marshal (<8>C{s: <9>.s})}, ` +
+ `#U: <10>C{s: string, out: <11>.Marshal (<12>C{s: <13>.s})}}`,
}}
rewriteHelper(t, testCases, evalFull)
}
diff --git a/cue/subsume_test.go b/cue/subsume_test.go
index e11681b..8925bd5 100644
--- a/cue/subsume_test.go
+++ b/cue/subsume_test.go
@@ -410,8 +410,8 @@
610: {subsumes: true, in: `a: {foo?:1}, b: close({})`},
// Definitions are not regular fields.
- 630: {subsumes: false, in: `a: {a :: 1}, b: {a: 1}`},
- 631: {subsumes: false, in: `a: {a: 1}, b: {a :: 1}`},
+ 630: {subsumes: false, in: `a: {#a: 1}, b: {a: 1}`},
+ 631: {subsumes: false, in: `a: {a: 1}, b: {#a: 1}`},
// Subsuming final values.
700: {subsumes: true, in: `a: {[string]: 1}, b: {foo: 1}`, mode: subFinal},
diff --git a/cue/types_test.go b/cue/types_test.go
index 0d9ddf9..4155fc1 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -435,8 +435,8 @@
value: `"Hello world!"`,
str: `Hello world!`,
}, {
- value: `"Hello \(world)!"
- world :: "world"`,
+ value: `"Hello \(#world)!"
+ #world: "world"`,
str: `Hello world!`,
}, {
value: `string`,
@@ -564,8 +564,8 @@
value: `>=5*[1,2,3, ...int]`,
err: "incomplete",
}, {
- value: `[for x in y if x > 1 { x }]
- y :: [1,2,3]`,
+ value: `[for x in #y if x > 1 { x }]
+ #y: [1,2,3]`,
res: "[2,3,]",
}, {
value: `[int]`,
@@ -615,11 +615,11 @@
value: `{_a:"a"}`,
res: "{}",
}, {
- value: `{ for k, v in y if v > 1 {"\(k)": v} }
- y :: {a:1,b:2,c:3}`,
+ value: `{ for k, v in #y if v > 1 {"\(k)": v} }
+ #y: {a:1,b:2,c:3}`,
res: "{b:2,c:3,}",
}, {
- value: `{ def :: 1, _hidden: 2, opt?: 3, reg: 4 }`,
+ value: `{ #def: 1, _hidden: 2, opt?: 3, reg: 4 }`,
res: "{reg:4,}",
}, {
value: `{a:1,b:2,c:int}`,
@@ -1226,8 +1226,8 @@
dst: intList(),
want: *intList(1, 2, 3),
}, {
- value: `[for x in y if x > 1 { x }]
- y :: [1,2,3]`,
+ value: `[for x in #y if x > 1 { x }]
+ #y: [1,2,3]`,
dst: intList(),
want: *intList(2, 3),
}, {
@@ -1273,20 +1273,20 @@
}, {
desc: "definition error",
in: `
- b :: 1 & 2
+ #b: 1 & 2
`,
opts: []Option{},
err: true,
}, {
desc: "definition error okay if optional",
in: `
- b? :: 1 & 2
+ #b?: 1 & 2
`,
opts: []Option{},
}, {
desc: "definition with optional",
in: `
- b:: {
+ #b: {
a: int
b?: >=0
}
@@ -1348,10 +1348,10 @@
}, {
desc: "ignore optional in schema",
in: `
- Schema1 :: {
+ #Schema1: {
a?: int
}
- instance1: Schema1
+ instance1: #Schema1
`,
opts: []Option{Concrete(true)},
}, {
@@ -2068,7 +2068,7 @@
json: `{"a":1,"b":1,"c":2,"d":1,"e":1,"f":1.1}`,
}, {
value: `
- Task :: {
+ #Task: {
{
op: "pull"
tag: *"latest" | string
@@ -2078,7 +2078,7 @@
}
}
- foo: Task & {"op": "pull"}
+ foo: #Task & {"op": "pull"}
`,
json: `{"foo":{"op":"pull","tag":"latest","tagInString":"latestdd"}}`,
}, {
@@ -2266,7 +2266,7 @@
input: "v: w: x: w.a.b.c, v: w: a: b: c: 1",
want: "v w a b c",
}, {
- input: `v: w: x: w.a.b.c, v: w: a: b: c: 1, D :: 3, opt?: 3, "v\(D)": 3, X: {a: 3}, X`,
+ input: `v: w: x: w.a.b.c, v: w: a: b: c: 1, #D: 3, opt?: 3, "v\(#D)": 3, X: {a: 3}, X`,
want: "v w a b c",
}, {
input: `v: w: x: w.a[bb]["c"], v: w: a: b: c: 1, bb: "b"`,
@@ -2358,28 +2358,28 @@
want: "T",
}, {
input: `
- a :: {
- T :: {b: 3}
- close({}) | close({c: T}) | close({d: string})
+ #a: {
+ #T: {b: 3}
+ close({}) | close({c: #T}) | close({d: string})
}
`,
lookup: func(i *Instance) Value {
- f, _ := i.LookupField("a")
+ f, _ := i.LookupField("#a")
_, a := f.Value.Expr() // &
_, a = a[1].Expr() // |
return a[1].Lookup("c")
},
- want: "a.T",
+ want: "#a.#T",
}, {
input: `
package foo
- Struct :: {
- T :: int
+ #Struct: {
+ #T: int
- {b?: T}
+ {b?: #T}
}`,
- want: "Struct.T",
+ want: "#Struct.#T",
lookup: func(inst *Instance) Value {
// Locate Struct
i, _ := inst.Value().Fields(Definitions(true))
@@ -2398,17 +2398,17 @@
input: `
package foo
- A :: B :: T
+ #A: #B: #T
- T :: {
- a: S.U
- S :: U:: {}
+ #T: {
+ a: #S.#U
+ #S: #U: {}
}
`,
- want: "T.S.U",
+ want: "#T.#S.#U",
lookup: func(inst *Instance) Value {
- f, _ := inst.Value().LookupField("A")
- f, _ = f.Value.LookupField("B")
+ f, _ := inst.Value().LookupField("#A")
+ f, _ = f.Value.LookupField("#B")
v := f.Value
v = Dereference(v)
v = v.Lookup("a")
@@ -2418,17 +2418,17 @@
input: `
package foo
- A :: B :: T
+ #A: #B: #T
- T :: {
- a: [...S]
- S :: {}
+ #T: {
+ a: [...#S]
+ #S: {}
}
`,
- want: "T.S",
+ want: "#T.#S",
lookup: func(inst *Instance) Value {
- f, _ := inst.Value().LookupField("A")
- f, _ = f.Value.LookupField("B")
+ f, _ := inst.Value().LookupField("#A")
+ f, _ = f.Value.LookupField("#B")
v := f.Value
v = Dereference(v)
v, _ = v.Lookup("a").Elem()
@@ -2436,18 +2436,18 @@
},
}, {
input: `
- A :: {
- b: T
+ #A: {
+ b: #T
}
- T :: {
- a: S
- S :: {}
+ #T: {
+ a: #S
+ #S: {}
}
`,
- want: "T.S",
+ want: "#T.#S",
lookup: func(inst *Instance) Value {
- f, _ := inst.Value().LookupField("A")
+ f, _ := inst.Value().LookupField("#A")
v := f.Value.Lookup("b")
v = Dereference(v)
v = v.Lookup("a")
@@ -2461,22 +2461,22 @@
// This could perhaps be made fixed with dereferencing as well.
skip: true,
input: `
- Tracing :: {
- T :: { address?: string }
- S :: { ip?: string }
+ #Tracing: {
+ #T: { address?: string }
+ #S: { ip?: string }
close({}) | close({
- t: T
+ t: #T
}) | close({
s: S
})
}
- X :: {}
- X // Disconnect top-level struct from the one visible by close.
+ #X: {}
+ #X // Disconnect top-level struct from the one visible by close.
`,
want: "",
lookup: func(inst *Instance) Value {
- f, _ := inst.Value().LookupField("Tracing")
+ f, _ := inst.Value().LookupField("#Tracing")
v := f.Value.Eval()
_, args := v.Expr()
v = args[1].Lookup("t")
diff --git a/doc/ref/impl.md b/doc/ref/impl.md
index ca38ef2..b7c4260 100644
--- a/doc/ref/impl.md
+++ b/doc/ref/impl.md
@@ -233,8 +233,8 @@
Alternatively: use Haskell's approach:
-a :: MyStruct // define a to be MyStruct any other features are allowed but
- // discarded from the model. Unused features are an error.
+#a: MyStruct // define a to be MyStruct any other features are allowed but
+ // discarded from the model. Unused features are an error.
Let's first try to see if we can get away with static usage analysis.
A variant would be to define appropriate features unconditionally, but enforce