this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: add testscript to cover exporting CUE comments

Much like encoding_empty.txtar, this is a high-level test for cmd/cue's
ability to export CUE comments in different encodings, including to CUE.

For #1180.
For #3342.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I306c16d590b9c1faa45f8e083d094838cf9635ed
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199689
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.io>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+276
+276
cmd/cue/cmd/testdata/script/encoding_comments.txtar
··· 1 + # Test that the various encodings support encoding comments from CUE. 2 + # We cover multiple output modes (def, eval, export) as well as multiple encodings, 3 + # and also comments coming from definitions, unifications, and disjunctions. 4 + # Note that some encodings have no support for comments, like JSON. 5 + # This is meant mainly as an end-to-end smoke test; specific edge cases 6 + # should be tested in each encoding package. 7 + 8 + # TODO(mvdan): test importing comments into CUE as well. 9 + # TODO(mvdan): comments at the start and end of a file are not exported. 10 + # TODO(mvdan): comments at the start of a struct are not exported. 11 + # TODO(mvdan): comments attached to a list or its elements are not exported. 12 + # TODO(mvdan): comments between fields or list elements are not exported. 13 + 14 + exec cue def --out cue . 15 + cmp stdout def-cue.stdout 16 + 17 + # TODO(mvdan): why does eval not include comments when def and export do? 18 + exec cue eval --out cue . 19 + cmp stdout eval-cue.stdout 20 + 21 + exec cue export --out cue . 22 + cmp stdout export-cue.stdout 23 + 24 + exec cue export --out json . 25 + cmp stdout export-json.stdout 26 + 27 + # TODO(mvdan): YAML should support exporting comments. 28 + exec cue export --out yaml . 29 + cmp stdout export-yaml.stdout 30 + 31 + # TODO(mvdan): TOML should support exporting comments. 32 + exec cue export --out toml . 33 + cmp stdout export-toml.stdout 34 + 35 + -- basic.cue -- 36 + // comment at the start of a file. 37 + 38 + // Package p is an example package. 39 + package p 40 + 41 + // top-level comment before a simple field. 42 + foo: "bar" 43 + // top-level comment after a simple field. 44 + 45 + // top-level comment before a struct 46 + struct: { 47 + // comment at the start of a struct. 48 + 49 + // comment in a struct field 50 + field1: "message1" 51 + 52 + // comment between struct fields. 53 + 54 + field2: "message2" 55 + 56 + // comment at the end of a struct. 57 + } 58 + 59 + // top-level comment before a list. 60 + list: [ 61 + // comment at the start of a list. 62 + 63 + 1, 64 + // comment in a list element. 65 + 2, 66 + 67 + // comment between list elements. 68 + 69 + 3, 70 + 71 + // comment at the end of a list. 72 + ] 73 + 74 + // comment at the end of a file. 75 + -- schema.cue -- 76 + package p 77 + 78 + // Schema declares a schema. 79 + #Schema: { 80 + // name is the schema name. 81 + name?: string 82 + } 83 + -- data.cue -- 84 + package p 85 + 86 + // Data fits the schema. 87 + Data: #Schema & { 88 + // name is a specific name. 89 + name: "Foo" 90 + } 91 + 92 + // implicitUnified is any non-empty string. 93 + implicitUnified: string & != "" 94 + 95 + // implicitUnified is some string value. 96 + implicitUnified: "some value" 97 + 98 + // explicitUnified1 sets a default value. 99 + explicitUnified1: string | *"some default" 100 + 101 + // explicitUnified2 sets a value. 102 + explicitUnified2: "some value" 103 + 104 + // explicitUnified unifies two values. 105 + explicitUnified: explicitUnified1 & explicitUnified2 106 + 107 + // disjunction1 has a default. 108 + _disjunction1: string | *"some default" 109 + 110 + // disjunction2 has no default. 111 + _disjunction2: int 112 + 113 + // disjunction is like a sum type. 114 + disjunction: _disjunction1 | _disjunction2 115 + 116 + -- def-cue.stdout -- 117 + // Package p is an example package. 118 + package p 119 + 120 + // top-level comment before a simple field. 121 + foo: "bar" 122 + 123 + // top-level comment before a struct 124 + struct: { 125 + // comment in a struct field 126 + field1: "message1" 127 + field2: "message2" 128 + 129 + // comment at the end of a struct. 130 + } 131 + 132 + // Data fits the schema. 133 + Data: #Schema & { 134 + // name is a specific name. 135 + name: "Foo" 136 + } 137 + 138 + // Schema declares a schema. 139 + #Schema: { 140 + // name is the schema name. 141 + name?: string 142 + } 143 + 144 + // top-level comment before a list. 145 + list: [1, 2, 3] 146 + 147 + // implicitUnified is any non-empty string. 148 + 149 + // implicitUnified is some string value. 150 + implicitUnified: "some value" 151 + 152 + // explicitUnified1 sets a default value. 153 + explicitUnified1: string | *"some default" 154 + 155 + // explicitUnified2 sets a value. 156 + explicitUnified2: "some value" 157 + 158 + // explicitUnified unifies two values. 159 + explicitUnified: explicitUnified1 & explicitUnified2 160 + 161 + // disjunction1 has a default. 162 + _disjunction1: string | *"some default" 163 + 164 + // disjunction2 has no default. 165 + _disjunction2: int 166 + 167 + // disjunction is like a sum type. 168 + disjunction: _disjunction1 | _disjunction2 169 + -- eval-cue.stdout -- 170 + foo: "bar" 171 + struct: { 172 + field1: "message1" 173 + field2: "message2" 174 + } 175 + Data: { 176 + name: "Foo" 177 + } 178 + #Schema: {} 179 + list: [1, 2, 3] 180 + implicitUnified: "some value" 181 + explicitUnified1: "some default" 182 + explicitUnified2: "some value" 183 + explicitUnified: "some value" 184 + disjunction: "some default" 185 + -- export-cue.stdout -- 186 + // top-level comment before a simple field. 187 + foo: "bar" 188 + 189 + // top-level comment before a struct 190 + struct: { 191 + // comment in a struct field 192 + field1: "message1" 193 + field2: "message2" 194 + 195 + // comment at the end of a struct. 196 + } 197 + 198 + // Data fits the schema. 199 + Data: { 200 + // name is the schema name. 201 + 202 + // name is a specific name. 203 + name: "Foo" 204 + } 205 + 206 + // top-level comment before a list. 207 + list: [1, 2, 3] 208 + 209 + // implicitUnified is any non-empty string. 210 + 211 + // implicitUnified is some string value. 212 + implicitUnified: "some value" 213 + 214 + // explicitUnified1 sets a default value. 215 + explicitUnified1: "some default" 216 + 217 + // explicitUnified2 sets a value. 218 + explicitUnified2: "some value" 219 + 220 + // explicitUnified unifies two values. 221 + explicitUnified: "some value" 222 + 223 + // disjunction is like a sum type. 224 + disjunction: "some default" 225 + -- export-json.stdout -- 226 + { 227 + "foo": "bar", 228 + "struct": { 229 + "field1": "message1", 230 + "field2": "message2" 231 + }, 232 + "Data": { 233 + "name": "Foo" 234 + }, 235 + "list": [ 236 + 1, 237 + 2, 238 + 3 239 + ], 240 + "implicitUnified": "some value", 241 + "explicitUnified1": "some default", 242 + "explicitUnified2": "some value", 243 + "explicitUnified": "some value", 244 + "disjunction": "some default" 245 + } 246 + -- export-yaml.stdout -- 247 + foo: bar 248 + struct: 249 + field1: message1 250 + field2: message2 251 + Data: 252 + name: Foo 253 + list: 254 + - 1 255 + - 2 256 + - 3 257 + implicitUnified: some value 258 + explicitUnified1: some default 259 + explicitUnified2: some value 260 + explicitUnified: some value 261 + disjunction: some default 262 + -- export-toml.stdout -- 263 + disjunction = 'some default' 264 + explicitUnified = 'some value' 265 + explicitUnified1 = 'some default' 266 + explicitUnified2 = 'some value' 267 + foo = 'bar' 268 + implicitUnified = 'some value' 269 + list = [1, 2, 3] 270 + 271 + [Data] 272 + name = 'Foo' 273 + 274 + [struct] 275 + field1 = 'message1' 276 + field2 = 'message2'