this repo has no description
0
fork

Configure Feed

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

pkg: generate per-directory tests from builtin_test.go

- from original tests in cue
- keep some of the original tests around to test builtin logic

Change-Id: I84897b45016034d871b731ba3e76ae9a0cd8a8d0
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6883
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>

+1678 -556
-556
cue/builtin_test.go
··· 16 16 17 17 import ( 18 18 "fmt" 19 - "math/big" 20 - "strconv" 21 - "strings" 22 19 "testing" 23 20 24 21 "cuelang.org/go/cue" ··· 39 36 []string{fmt.Sprintf("(%s)", expr)}, 40 37 }} 41 38 } 42 - hexToDec := func(s string) string { 43 - var x big.Int 44 - x.SetString(s, 16) 45 - return x.String() 46 - } 47 39 testCases := []struct { 48 40 instances []*bimport 49 41 emit string ··· 69 61 test("crypto/md5", `len(md5.Sum("hash me"))`), 70 62 `16`, 71 63 }, { 72 - test("crypto/sha1", `len(sha1.Sum("hash me"))`), 73 - `20`, 74 - }, { 75 - test("crypto/sha256", `len(sha256.Sum256("hash me"))`), 76 - `32`, 77 - }, { 78 - test("crypto/sha256", `len(sha256.Sum224("hash me"))`), 79 - `28`, 80 - }, { 81 - test("crypto/sha512", `len(sha512.Sum512("hash me"))`), 82 - `64`, 83 - }, { 84 - test("crypto/sha512", `len(sha512.Sum384("hash me"))`), 85 - `48`, 86 - }, { 87 - test("crypto/sha512", `len(sha512.Sum512_224("hash me"))`), 88 - `28`, 89 - }, { 90 - test("crypto/sha512", `len(sha512.Sum512_256("hash me"))`), 91 - `32`, 92 - }, { 93 - test("encoding/base64", `base64.Encode(null, "foo")`), 94 - `"Zm9v"`, 95 - }, { 96 - test("encoding/base64", `base64.Decode(null, base64.Encode(null, "foo"))`), 97 - `'foo'`, 98 - }, { 99 - test("encoding/base64", `base64.Decode(null, "foo")`), 100 - `_|_(error in call to encoding/base64.Decode: illegal base64 data at input byte 0 (and 1 more errors))`, 101 - }, { 102 - test("encoding/base64", `base64.Decode({}, "foo")`), 103 - `_|_(error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null (and 1 more errors))`, 104 - }, { 105 - test("encoding/hex", `hex.Encode("foo")`), 106 - `"666f6f"`, 107 - }, { 108 - test("encoding/hex", `hex.Decode(hex.Encode("foo"))`), 109 - `'foo'`, 110 - }, { 111 - test("encoding/hex", `hex.Decode("foo")`), 112 - `_|_(error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o' (and 1 more errors))`, 113 - }, { 114 - test("encoding/hex", `hex.Dump('foo')`), 115 - `"00000000 66 6f 6f |foo|\n"`, 116 - }, { 117 - test("encoding/json", `json.Validate("{\"a\":10}", {b:string})`), 118 - `true`, 119 - }, { 120 - test("encoding/json", `json.Validate("{\"a\":10}", {a:<3})`), 121 - `_|_(error in call to encoding/json.Validate: a: invalid value 10 (out of bound <3) (and 1 more errors))`, 122 - }, { 123 64 test("encoding/yaml", `yaml.Validate("a: 2\n---\na: 4", {a:<3})`), 124 65 `_|_(error in call to encoding/yaml.Validate: a: invalid value 4 (out of bound <3) (and 1 more errors))`, 125 66 }, { ··· 129 70 test("encoding/yaml", `yaml.Validate("a: 2\n", {a:<5, b:int})`), 130 71 `_|_(error in call to encoding/yaml.Validate: b: incomplete value int (and 1 more errors))`, 131 72 }, { 132 - test("encoding/yaml", `yaml.ValidatePartial("a: 2\n---\na: 4", {a:<3})`), 133 - `_|_(error in call to encoding/yaml.ValidatePartial: a: invalid value 4 (out of bound <3) (and 1 more errors))`, 134 - }, { 135 - test("encoding/yaml", `yaml.ValidatePartial("a: 2\n---\na: 4", {a:<5})`), 136 - `true`, 137 - }, { 138 - test("encoding/yaml", `yaml.ValidatePartial("a: 2\n", {a:<5, b:int})`), 139 - `true`, 140 - }, { 141 73 test("strconv", `strconv.FormatUint(64, 16)`), 142 74 `"40"`, 143 75 }, { 144 - // Find a better alternative, as this call should go. 145 - test("strconv", `strconv.FormatFloat(3.02, 300, 4, 64)`), 146 - `_|_(int 300 overflows byte in argument 1 in call to strconv.FormatFloat (and 1 more errors))`, 147 - }, { 148 - // Find a better alternative, as this call should go. 149 - test("strconv", `strconv.FormatFloat(3.02, -1, 4, 64)`), 150 - `_|_(cannot use -1 (type int) as byte in argument 1 to strconv.FormatFloat (and 1 more errors))`, 151 - }, { 152 - // Find a better alternative, as this call should go. 153 - test("strconv", `strconv.FormatFloat(3.02, 1.0, 4, 64)`), 154 - `_|_(cannot use 1.0 (type float) as int in argument 2 to strconv.FormatFloat)`, 155 - }, { 156 - test("list", `list.Avg([1, 2, 3, 4])`), 157 - `2.5`, 158 - }, { 159 - test("list", `list.Avg([])`), 160 - `_|_(error in call to list.Avg: empty list (and 1 more errors))`, 161 - }, { 162 - test("list", `list.Avg("foo")`), 163 - `_|_(cannot use "foo" (type string) as list in argument 1 to list.Avg)`, 164 - }, { 165 - test("list", `list.Drop([1, 2, 3, 4], 0)`), 166 - `[1,2,3,4]`, 167 - }, { 168 - test("list", `list.Drop([1, 2, 3, 4], 2)`), 169 - `[3,4]`, 170 - }, { 171 - test("list", `list.Drop([1, 2, 3, 4], 10)`), 172 - `[]`, 173 - }, { 174 - test("list", `list.Drop([1, 2, 3, 4], -1)`), 175 - `_|_(error in call to list.Drop: negative index (and 1 more errors))`, 176 - }, { 177 - test("list", `list.FlattenN([1, [[2, 3], []], [4]], -1)`), 178 - `[1,2,3,4]`, 179 - }, { 180 - test("list", `list.FlattenN([1, [[2, 3], []], [4]], 0)`), 181 - `[1,[[2,3],[]],[4]]`, 182 - }, { 183 - test("list", `list.FlattenN([1, [[2, 3], []], [4]], 1)`), 184 - `[1,[2,3],[],4]`, 185 - }, { 186 - test("list", `list.FlattenN([1, [[2, 3], []], [4]], 2)`), 187 - `[1,2,3,4]`, 188 - }, { 189 - test("list", `list.FlattenN([[1, 2] | *[]], -1)`), 190 - `[]`, 191 - }, { 192 - test("list", `list.FlattenN("foo", 1)`), 193 - `_|_(error in call to list.FlattenN: cannot use value "foo" (type string) as list (and 1 more errors))`, 194 - }, { 195 - test("list", `list.FlattenN([], "foo")`), 196 - `_|_(cannot use "foo" (type string) as int in argument 2 to list.FlattenN)`, 197 - }, { 198 - test("list", `list.Max([1, 2, 3, 4])`), 199 - `4`, 200 - }, { 201 - test("list", `list.Max([])`), 202 - `_|_(error in call to list.Max: empty list (and 1 more errors))`, 203 - }, { 204 - test("list", `list.Max("foo")`), 205 - `_|_(cannot use "foo" (type string) as list in argument 1 to list.Max)`, 206 - }, { 207 - test("list", `list.Min([1, 2, 3, 4])`), 208 - `1`, 209 - }, { 210 - test("list", `list.Min([])`), 211 - `_|_(error in call to list.Min: empty list (and 1 more errors))`, 212 - }, { 213 - test("list", `list.Min("foo")`), 214 - `_|_(cannot use "foo" (type string) as list in argument 1 to list.Min)`, 215 - }, { 216 - test("list", `list.Product([1, 2, 3, 4])`), 217 - `24`, 218 - }, { 219 - test("list", `list.Product([])`), 220 - `1`, 221 - }, { 222 - test("list", `list.Product("foo")`), 223 - `_|_(cannot use "foo" (type string) as list in argument 1 to list.Product)`, 224 - }, { 225 - test("list", `list.Range(0, 5, 0)`), 226 - `_|_(error in call to list.Range: step must be non zero (and 1 more errors))`, 227 - }, { 228 - test("list", `list.Range(5, 0, 1)`), 229 - `_|_(error in call to list.Range: end must be greater than start when step is positive (and 1 more errors))`, 230 - }, { 231 - test("list", `list.Range(0, 5, -1)`), 232 - `_|_(error in call to list.Range: end must be less than start when step is negative (and 1 more errors))`, 233 - }, { 234 - test("list", `list.Range(0, 5, 1)`), 235 - `[0,1,2,3,4]`, 236 - }, { 237 - test("list", `list.Range(0, 1, 1)`), 238 - `[0]`, 239 - }, { 240 - test("list", `list.Range(0, 5, 2)`), 241 - `[0,2,4]`, 242 - }, { 243 - test("list", `list.Range(5, 0, -1)`), 244 - `[5,4,3,2,1]`, 245 - }, { 246 - test("list", `list.Range(0, 5, 0.5)`), 247 - `[0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5]`, 248 - }, { 249 - test("list", `list.Slice([1, 2, 3, 4], 1, 3)`), 250 - `[2,3]`, 251 - }, { 252 - test("list", `list.Slice([1, 2, 3, 4], -1, 3)`), 253 - `_|_(error in call to list.Slice: negative index (and 1 more errors))`, 254 - }, { 255 - test("list", `list.Slice([1, 2, 3, 4], 3, 1)`), 256 - `_|_(error in call to list.Slice: invalid index: 3 > 1 (and 1 more errors))`, 257 - }, { 258 - test("list", `list.Slice([1, 2, 3, 4], 5, 5)`), 259 - `_|_(error in call to list.Slice: slice bounds out of range (and 1 more errors))`, 260 - }, { 261 - test("list", `list.Slice([1, 2, 3, 4], 1, 5)`), 262 - `_|_(error in call to list.Slice: slice bounds out of range (and 1 more errors))`, 263 - }, { 264 - test("list", `list.Sort([], list.Ascending)`), 265 - `[]`, 266 - }, { 267 - test("list", `list.Sort([2, 3, 1, 4], {x:_, y:_, less: x<y})`), 268 - `[1,2,3,4]`, 269 - }, { 270 - test("list", `list.SortStable([{a:2,v:1}, {a:1,v:2}, {a:1,v:3}], { 271 - x:_, 272 - y:_, 273 - less: (x.a < y.a) 274 - })`), 275 - `[{a:1,v:2},{a:1,v:3},{a:2,v:1}]`, 276 - }, { 277 - test("list", `list.Sort([{a:1}, {b:2}], list.Ascending)`), 278 - `_|_(error in call to list.Sort: x: conflicting values string and {b:2} (mismatched types string and struct) (and 1 more errors) (and 1 more errors))`, 279 - }, { 280 - test("list", `list.SortStrings(["b", "a"])`), 281 - `["a","b"]`, 282 - }, { 283 - // TODO: path error. This should be done as part of builtin refactoring. 284 - test("list", `list.SortStrings([1, 2])`), 285 - `_|_(error in call to list.SortStrings: element 0 of list argument 0: 0: cannot use value 1 (type int) as string (and 1 more errors))`, 286 - }, { 287 - test("list", `list.Sum([1, 2, 3, 4])`), 288 - `10`, 289 - }, { 290 - test("list", `list.Sum([])`), 291 - `0`, 292 - }, { 293 - test("list", `list.Sum("foo")`), 294 - `_|_(cannot use "foo" (type string) as list in argument 1 to list.Sum)`, 295 - }, { 296 - test("list", `list.Take([1, 2, 3, 4], 0)`), 297 - `[]`, 298 - }, { 299 - test("list", `list.Take([1, 2, 3, 4], 2)`), 300 - `[1,2]`, 301 - }, { 302 - test("list", `list.Take([1, 2, 3, 4], 10)`), 303 - `[1,2,3,4]`, 304 - }, { 305 - test("list", `list.Take([1, 2, 3, 4], -1)`), 306 - `_|_(error in call to list.Take: negative index (and 1 more errors))`, 307 - }, { 308 - test("list", `list.MinItems([1, 2, 3, 4], 2)`), 309 - `true`, 310 - }, { 311 - test("list", `list.MinItems([1, 2, 3, 4], 5)`), 312 - `false`, 313 - }, { 314 - test("list", `list.MaxItems([1, 2, 3, 4], 5)`), 315 - `true`, 316 - }, { 317 - test("list", `list.MaxItems([1, 2, 3, 4], 2)`), 318 - `false`, 319 - }, { 320 - // Panics 321 - test("math", `math.Jacobi(1000, 2000)`), 322 - `_|_(error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000 (and 1 more errors))`, 323 - }, { 324 - test("math", `math.Jacobi(1000, 201)`), 325 - `1`, 326 - }, { 327 - test("math", `math.Asin(2.0e400)`), 328 - `_|_(cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up (and 1 more errors))`, 329 - }, { 330 - test("math", `math.MultipleOf(4, 2)`), `true`, 331 - }, { 332 - test("math", `math.MultipleOf(5, 2)`), `false`, 333 - }, { 334 - test("math", `math.MultipleOf(5, 0)`), 335 - `_|_(error in call to math.MultipleOf: division by zero (and 1 more errors))`, 336 - }, { 337 - test("math", `math.MultipleOf(100, 1.00001)`), `false`, 338 - }, { 339 - test("math", `math.MultipleOf(1, 1)`), `true`, 340 - }, { 341 - test("math", `math.MultipleOf(5, 2.5)`), `true`, 342 - }, { 343 - test("math", `math.MultipleOf(100e100, 10)`), `true`, 344 - }, { 345 - test("encoding/csv", `csv.Decode("1,2,3\n4,5,6")`), 346 - `[["1","2","3"],["4","5","6"]]`, 347 - }, { 348 76 test("regexp", `regexp.Find(#"f\w\w"#, "afoot")`), 349 77 `"foo"`, 350 78 }, { 351 79 test("regexp", `regexp.Find(#"f\w\w"#, "bar")`), 352 80 `_|_(error in call to regexp.Find: no match (and 1 more errors))`, 353 81 }, { 354 - test("regexp", `regexp.FindAll(#"f\w\w"#, "afoot afloat from", 2)`), 355 - `["foo","flo"]`, 356 - }, { 357 - test("regexp", `regexp.FindAll(#"f\w\w"#, "afoot afloat from", 2)`), 358 - `["foo","flo"]`, 359 - }, { 360 - test("regexp", `regexp.FindAll(#"f\w\w"#, "bla bla", -1)`), 361 - `_|_(error in call to regexp.FindAll: no match (and 1 more errors))`, 362 - }, { 363 - test("regexp", `regexp.FindSubmatch(#"f(\w)(\w)"#, "afloat afoot from")`), 364 - `["flo","l","o"]`, 365 - }, { 366 - test("regexp", `regexp.FindAllSubmatch(#"f(\w)(\w)"#, "afloat afoot from", -1)`), 367 - `[["flo","l","o"],["foo","o","o"],["fro","r","o"]]`, 368 - }, { 369 - test("regexp", `regexp.FindAllSubmatch(#"f(\w)(\w)"#, "aglom", -1)`), 370 - `_|_(error in call to regexp.FindAllSubmatch: no match (and 1 more errors))`, 371 - }, { 372 - test("regexp", `regexp.FindNamedSubmatch(#"f(?P<A>\w)(?P<B>\w)"#, "afloat afoot from")`), 373 - `{A:"l",B:"o"}`, 374 - }, { 375 - test("regexp", `regexp.FindAllNamedSubmatch(#"f(?P<A>\w)(?P<B>\w)"#, "afloat afoot from", -1)`), 376 - `[{A:"l",B:"o"},{A:"o",B:"o"},{A:"r",B:"o"}]`, 377 - }, { 378 - test("regexp", `regexp.FindAllNamedSubmatch(#"f(?P<A>optional)?"#, "fbla", -1)`), 379 - `[{A:""}]`, 380 - }, { 381 - test("regexp", `regexp.FindAllNamedSubmatch(#"f(?P<A>\w)(?P<B>\w)"#, "aglom", -1)`), 382 - `_|_(error in call to regexp.FindAllNamedSubmatch: no match (and 1 more errors))`, 383 - }, { 384 - test("regexp", `regexp.Valid & "valid"`), 385 - `"valid"`, 386 - }, { 387 - test("regexp", `regexp.Valid & "invalid)"`), 388 - "_|_(error in call to regexp.Valid: error parsing regexp: unexpected ): `invalid)`)", 389 - }, { 390 - test("strconv", `strconv.FormatBool(true)`), 391 - `"true"`, 392 - }, { 393 - test("strings", `strings.Join(["Hello", "World!"], " ")`), 394 - `"Hello World!"`, 395 - }, { 396 - test("strings", `strings.Join([1, 2], " ")`), 397 - `_|_(error in call to strings.Join: element 0 of list argument 0: 0: cannot use value 1 (type int) as string (and 1 more errors))`, 398 - }, { 399 - test("strings", `strings.ByteAt("a", 0)`), 400 - strconv.Itoa('a'), 401 - }, { 402 - test("strings", `strings.ByteSlice("Hello", 2, 5)`), 403 - `'llo'`, 404 - }, { 405 - test("strings", `strings.SliceRunes("✓ Hello", 0, 3)`), 406 - `"✓ H"`, 407 - }, { 408 - test("strings", `strings.Runes("Café")`), 409 - strings.Replace(fmt.Sprint([]rune{'C', 'a', 'f', 'é'}), " ", ",", -1), 410 - }, { 411 - test("math/bits", `bits.Or(0x8, 0x1)`), 412 - `9`, 413 - }, { 414 - testExpr(`len({})`), 415 - `0`, 416 - }, { 417 - testExpr(`len({a: 1, b: 2, {[foo=_]: int}, _c: 3})`), 418 - `2`, 419 - }, { 420 82 testExpr(`len([1, 2, 3])`), 421 83 `3`, 422 84 }, { 423 85 testExpr(`len("foo")`), 424 86 `3`, 425 87 }, { 426 - testExpr(`len('f\x20\x20')`), 427 - `3`, 428 - }, { 429 - testExpr(`and([string, "foo"])`), 430 - `"foo"`, 431 - }, { 432 - testExpr(`and([string, =~"fo"]) & "foo"`), 433 - `"foo"`, 434 - }, { 435 - testExpr(`and([])`), 436 - `{}`, // _ & top scope 437 - }, { 438 - testExpr(`or([1, 2, 3]) & 2`), 439 - `2`, 440 - }, { 441 - testExpr(`or([])`), 442 - `_|_(empty list in call to or (and 1 more errors))`, 443 - }, { 444 - test("encoding/csv", `csv.Encode([[1,2,3],[4,5],[7,8,9]])`), 445 - `"1,2,3\n4,5\n7,8,9\n"`, 446 - }, { 447 - test("encoding/csv", `csv.Encode([["a", "b"], ["c"]])`), 448 - `"a,b\nc\n"`, 449 - }, { 450 - test("encoding/json", `json.Valid("1")`), 451 - `true`, 452 - }, { 453 - test("encoding/json", `json.Compact("[1, 2]")`), 454 - `"[1,2]"`, 455 - }, { 456 - test("encoding/json", `json.Indent(#"{"a": 1, "b": 2}"#, "", " ")`), 457 - `"{\n \"a\": 1,\n \"b\": 2\n}"`, 458 - }, { 459 - test("encoding/json", `json.Unmarshal("1")`), 460 - `1`, 461 - }, { 462 88 test("encoding/json", `json.MarshalStream([{a: 1}, {b: 2}])`), 463 89 `"{\"a\":1}\n{\"b\":2}\n"`, 464 90 }, { ··· 471 97 test("encoding/yaml", `yaml.MarshalStream([{a: 1}, {b: 2}])`), 472 98 `"a: 1\n---\nb: 2\n"`, 473 99 }, { 474 - test("net", `net.FQDN & "foo.bar."`), 475 - `"foo.bar."`, 476 - }, { 477 - test("net", `net.FQDN("foo.bararararararararararararararararararararararararararararararararara")`), 478 - `false`, 479 - }, { 480 - test("net", `net.SplitHostPort("[::%lo0]:80")`), 481 - `["::%lo0","80"]`, 482 - }, { 483 - test("net", `net.JoinHostPort("example.com", "80")`), 484 - `"example.com:80"`, 485 - }, { 486 - test("net", `net.JoinHostPort("2001:db8::1", 80)`), 487 - `"[2001:db8::1]:80"`, 488 - }, { 489 - test("net", `net.JoinHostPort([192,30,4,2], 80)`), 490 - `"192.30.4.2:80"`, 491 - }, { 492 - // TODO: why is this not printing compactly? 493 - test("net", `net.JoinHostPort([192, 30, 4], 80)`), 494 - `_|_(error in call to net.JoinHostPort: invalid host [192, 30, 4] (and 1 more errors))`, 495 - }, { 496 - test("net", `net.IP("23.23.23.23")`), 497 - `true`, 498 - }, { 499 - test("net", `net.IPv4 & "23.23.23.2333"`), 500 - `_|_(invalid value "23.23.23.2333" (does not satisfy net.IPv4))`, 501 - }, { 502 - test("net", `net.IP("23.23.23.23")`), 503 - `true`, 504 - }, { 505 - test("net", `net.IP("2001:db8::1")`), 506 - `true`, 507 - }, { 508 - test("net", `net.IPv4("2001:db8::1")`), 509 - `false`, 510 - }, { 511 - test("net", `net.IPv4() & "ff02::1:3"`), 512 - `_|_(invalid value "ff02::1:3" (does not satisfy net.IPv4))`, 513 - }, { 514 - test("net", `net.LoopbackIP([127, 0, 0, 1])`), 515 - `true`, 516 - }, { 517 - test("net", `net.LoopbackIP("127.0.0.1")`), 518 - `true`, 519 - }, { 520 - test("net", `net.ToIP4("127.0.0.1")`), 521 - `[127,0,0,1]`, 522 - }, { 523 - test("net", `net.ToIP16("127.0.0.1")`), 524 - `[0,0,0,0,0,0,0,0,0,0,255,255,127,0,0,1]`, 525 - }, { 526 - test("strings", `strings.ToCamel("AlphaBeta")`), 527 - `"alphaBeta"`, 528 - }, { 529 - test("strings", `strings.ToTitle("alpha")`), 530 - `"Alpha"`, 531 - }, { 532 - test("strings", `strings.MaxRunes(3) & "foo"`), 533 - `"foo"`, 534 - }, { 535 - test("strings", `strings.MaxRunes(3) & "quux"`), 536 - `_|_(invalid value "quux" (does not satisfy strings.MaxRunes(3)))`, 537 - }, { 538 - test("strings", `strings.MinRunes(1) & "e"`), 539 - `"e"`, 540 - }, { 541 - test("strings", `strings.MaxRunes(0) & "e"`), 542 - `_|_(invalid value "e" (does not satisfy strings.MaxRunes(0)))`, 543 - }, { 544 - test("strings", `strings.MaxRunes(0) & ""`), 545 - `""`, 546 - }, { 547 - test("strings", `strings.MinRunes(3) & "hello"`), 548 - `"hello"`, 549 - }, { 550 - test("strings", `strings.MaxRunes(10) & "hello"`), 551 - `"hello"`, 552 - }, { 553 - test("strings", `strings.MaxRunes(3) & "hello"`), 554 - `_|_(invalid value "hello" (does not satisfy strings.MaxRunes(3)))`, 555 - }, { 556 - test("strings", `strings.MinRunes(10) & "hello"`), 557 - `_|_(invalid value "hello" (does not satisfy strings.MinRunes(10)))`, 558 - }, { 559 100 test("struct", `struct.MinFields(0) & ""`), 560 101 `_|_(conflicting values struct.MinFields(0) and "" (mismatched types struct and string))`, 561 102 }, { ··· 564 105 }, { 565 106 test("struct", `struct.MinFields(2) & {a: 1}`), 566 107 `_|_(invalid value {a:1} (does not satisfy struct.MinFields(2)))`, 567 - }, { 568 - test("struct", `struct.MaxFields(0) & {a: 1}`), 569 - `_|_(invalid value {a:1} (does not satisfy struct.MaxFields(0)))`, 570 - }, { 571 - test("struct", `struct.MaxFields(2) & {a: 1}`), 572 - `{a:1}`, 573 - }, { 574 - test("math", `math.Pow(8, 4)`), `4096`, 575 - }, { 576 - test("math", `math.Pow10(4)`), `1E+4`, 577 - }, { 578 - test("math", `math.Signbit(-4)`), `true`, 579 - }, { 580 - test("math", `math.Round(2.5)`), `3`, 581 - }, { 582 - test("math", `math.Round(-2.5)`), `-3`, 583 - }, { 584 - test("math", `math.RoundToEven(2.5)`), `2`, 585 - }, { 586 - test("math", `math.RoundToEven(-2.5)`), `-2`, 587 - }, { 588 - test("math", `math.Abs(2.5)`), `2.5`, 589 - }, { 590 - test("math", `math.Abs(-2.2)`), `2.2`, 591 - }, { 592 - test("math", `math.Cbrt(2)`), `1.25992104989487316476721`, 593 - }, { 594 - test("math", `math.Copysign(5, -2.2)`), `-5`, 595 - }, { 596 - test("math", `math.Exp(3)`), `20.0855369231876677409285`, 597 - }, { 598 - test("math", `math.Exp2(3.5)`), `11.3137084989847603904135`, 599 - }, { 600 - test("math", `math.Log(4)`), `1.38629436111989061883446`, 601 - }, { 602 - test("math", `math.Log10(4)`), `0.602059991327962390427478`, 603 - }, { 604 - test("math", `math.Log2(5)`), 605 - `2.32192809488736234787032`, 606 - }, { 607 - test("math", `math.Dim(3, 2.5)`), `0.5`, 608 - }, { 609 - test("math", `math.Dim(5, 7.2)`), `0`, 610 - }, { 611 - test("math", `math.Ceil(2.5)`), `3`, 612 - }, { 613 - test("math", `math.Ceil(-2.2)`), `-2`, 614 - }, { 615 - test("math", `math.Floor(2.9)`), `2`, 616 - }, { 617 - test("math", `math.Floor(-2.2)`), `-3`, 618 - }, { 619 - test("math", `math.Trunc(2.5)`), `2`, 620 - }, { 621 - test("math", `math.Trunc(-2.9)`), `-2`, 622 - }, { 623 - test("math/bits", `bits.Lsh(0x8, 4)`), `128`, 624 - }, { 625 - test("math/bits", `bits.Rsh(0x100, 4)`), `16`, 626 - }, { 627 - test("math/bits", `bits.At(0x100, 8)`), `1`, 628 - }, { 629 - test("math/bits", `bits.At(0x100, 9)`), `0`, 630 - }, { 631 - test("math/bits", `bits.Set(0x100, 7, 1)`), `384`, 632 - }, { 633 - test("math/bits", `bits.Set(0x100, 8, 0)`), `0`, 634 - }, { 635 - test("math/bits", `bits.And(0x10000000000000F0E, 0xF0F7)`), `6`, 636 - }, { 637 - test("math/bits", `bits.Or(0x100000000000000F0, 0x0F)`), 638 - hexToDec("100000000000000FF"), 639 - }, { 640 - test("math/bits", `bits.Xor(0x10000000000000F0F, 0xFF0)`), 641 - hexToDec("100000000000000FF"), 642 - }, { 643 - test("math/bits", `bits.Xor(0xFF0, 0x10000000000000F0F)`), 644 - hexToDec("100000000000000FF"), 645 - }, { 646 - test("math/bits", `bits.Clear(0xF, 0x100000000000008)`), `7`, 647 - }, { 648 - test("math/bits", `bits.Clear(0x1000000000000000008, 0xF)`), 649 - hexToDec("1000000000000000000"), 650 - }, { 651 - test("text/tabwriter", `tabwriter.Write(""" 652 - a\tb\tc 653 - aaa\tbb\tvv 654 - """)`), 655 - `"a b c\naaa bb vv"`, 656 - }, { 657 - test("text/tabwriter", `tabwriter.Write([ 658 - "a\tb\tc", 659 - "aaa\tbb\tvv"])`), 660 - `"a b c\naaa bb vv\n"`, 661 - }, { 662 - test("text/template", `template.Execute("{{.}}-{{.}}", "foo")`), 663 - `"foo-foo"`, 664 108 }, { 665 109 test("time", `time.Time & "1937-01-01T12:00:27.87+00:20"`), 666 110 `"1937-01-01T12:00:27.87+00:20"`,
+82
genpkgtests.go
··· 1 + // +build ignore 2 + 3 + package main 4 + 5 + import ( 6 + "fmt" 7 + "go/ast" 8 + "go/parser" 9 + "go/token" 10 + "io/ioutil" 11 + "os" 12 + 13 + "strconv" 14 + 15 + "github.com/rogpeppe/go-internal/txtar" 16 + ) 17 + 18 + func main() { 19 + fset := token.NewFileSet() 20 + f, err := parser.ParseFile(fset, "./cue/builtin_test.go", nil, 0) 21 + if err != nil { 22 + fmt.Println(err) 23 + return 24 + } 25 + 26 + m := map[string]*txtar.Archive{} 27 + count := map[string]int{} 28 + 29 + ast.Inspect(f, func(n ast.Node) bool { 30 + call, ok := n.(*ast.CallExpr) 31 + if !ok { 32 + return true 33 + } 34 + ident, ok := call.Fun.(*ast.Ident) 35 + if !ok || ident.Name != "test" { 36 + return true 37 + } 38 + 39 + str := call.Args[0].(*ast.BasicLit) 40 + pkg, _ := strconv.Unquote(str.Value) 41 + a := &txtar.Archive{ 42 + Comment: []byte( 43 + "# generated from the original tests.\n# Henceforth it may be nicer to group tests into separate files."), 44 + Files: []txtar.File{{Name: "in.cue"}}, 45 + } 46 + m[pkg] = a 47 + return false 48 + }) 49 + 50 + ast.Inspect(f, func(n ast.Node) bool { 51 + call, ok := n.(*ast.CallExpr) 52 + if !ok { 53 + return true 54 + } 55 + ident, ok := call.Fun.(*ast.Ident) 56 + if !ok || ident.Name != "test" { 57 + return true 58 + } 59 + 60 + str := call.Args[0].(*ast.BasicLit) 61 + pkg, _ := strconv.Unquote(str.Value) 62 + str = call.Args[1].(*ast.BasicLit) 63 + expr, err := strconv.Unquote(str.Value) 64 + if err != nil { 65 + panic(err) 66 + } 67 + 68 + a := m[pkg] 69 + count[pkg]++ 70 + 71 + a.Files[0].Data = append(a.Files[0].Data, 72 + fmt.Sprintf("t%d: %s\n", count[pkg], expr)...) 73 + 74 + return false 75 + }) 76 + 77 + for key, a := range m { 78 + os.Mkdir(fmt.Sprintf("pkg/%s/testdata", key), 0755) 79 + p := fmt.Sprintf("pkg/%s/testdata/gen.txtar", key) 80 + ioutil.WriteFile(p, txtar.Format(a), 0644) 81 + } 82 + }
+25
pkg/crypto/md5/md5_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package md5_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("md5", t) 25 + }
+10
pkg/crypto/md5/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "crypto/md5" 5 + 6 + t1: len(md5.Sum("hash me")) 7 + -- out/md5 -- 8 + (struct){ 9 + t1: (int){ 16 } 10 + }
+25
pkg/crypto/sha1/sha1_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package sha1_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("sha1", t) 25 + }
+10
pkg/crypto/sha1/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "crypto/sha1" 5 + 6 + t1: len(sha1.Sum("hash me")) 7 + -- out/sha1 -- 8 + (struct){ 9 + t1: (int){ 20 } 10 + }
+25
pkg/crypto/sha256/sha256_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package sha256_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("sha256", t) 25 + }
+14
pkg/crypto/sha256/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "crypto/sha256" 5 + 6 + t1: sha256.Sum256("hash me") 7 + t2: len(sha256.Sum256("hash me")) 8 + t3: len(sha256.Sum224("hash me")) 9 + -- out/sha256 -- 10 + (struct){ 11 + t1: (bytes){ '\xeb \x1a\xf5\xaa\xf0\xd6\x06)\xd3Ҧ\x1eFl\xfc\x0f\xed\xb5\x17\xad\xd81\xec\xacR5\xe1کc\xd6' } 12 + t2: (int){ 32 } 13 + t3: (int){ 28 } 14 + }
+25
pkg/crypto/sha512/sha512_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package sha512_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("sha512", t) 25 + }
+16
pkg/crypto/sha512/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "crypto/sha512" 5 + 6 + t1: len(sha512.Sum512("hash me")) 7 + t2: len(sha512.Sum384("hash me")) 8 + t3: len(sha512.Sum512_224("hash me")) 9 + t4: len(sha512.Sum512_256("hash me")) 10 + -- out/sha512 -- 11 + (struct){ 12 + t1: (int){ 64 } 13 + t2: (int){ 48 } 14 + t3: (int){ 28 } 15 + t4: (int){ 32 } 16 + }
+25
pkg/encoding/base64/base64_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package base64_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("base64", t) 25 + }
+26
pkg/encoding/base64/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "encoding/base64" 5 + 6 + t1: base64.Encode(null, "foo") 7 + t2: base64.Decode(null, base64.Encode(null, "foo")) 8 + t3: base64.Decode(null, "foo") 9 + t4: base64.Decode({}, "foo") 10 + -- out/base64 -- 11 + Errors: 12 + error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null 13 + error in call to encoding/base64.Decode: illegal base64 data at input byte 0 14 + 15 + Result: 16 + (_|_){ 17 + // [eval] 18 + t1: (string){ "Zm9v" } 19 + t2: (bytes){ 'foo' } 20 + t3: (_|_){ 21 + // [eval] error in call to encoding/base64.Decode: illegal base64 data at input byte 0 22 + } 23 + t4: (_|_){ 24 + // [eval] error in call to encoding/base64.Decode: base64: unsupported encoding: cannot use value {} (type struct) as null 25 + } 26 + }
+25
pkg/encoding/csv/csv_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package csv_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("csv", t) 25 + }
+25
pkg/encoding/csv/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "encoding/csv" 5 + 6 + t1: csv.Decode("1,2,3\n4,5,6") 7 + t2: csv.Encode([[1,2,3],[4,5],[7,8,9]]) 8 + t3: csv.Encode([["a", "b"], ["c"]]) 9 + -- out/csv -- 10 + (struct){ 11 + t1: (#list){ 12 + 0: (#list){ 13 + 0: (string){ "1" } 14 + 1: (string){ "2" } 15 + 2: (string){ "3" } 16 + } 17 + 1: (#list){ 18 + 0: (string){ "4" } 19 + 1: (string){ "5" } 20 + 2: (string){ "6" } 21 + } 22 + } 23 + t2: (string){ "1,2,3\n4,5\n7,8,9\n" } 24 + t3: (string){ "a,b\nc\n" } 25 + }
+25
pkg/encoding/hex/hex_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package hex_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("hex", t) 25 + }
+23
pkg/encoding/hex/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "encoding/hex" 5 + 6 + t1: hex.Encode("foo") 7 + t2: hex.Decode(hex.Encode("foo")) 8 + t3: hex.Decode("foo") 9 + t4: hex.Dump('foo') 10 + -- out/hex -- 11 + Errors: 12 + error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o' 13 + 14 + Result: 15 + (_|_){ 16 + // [eval] 17 + t1: (string){ "666f6f" } 18 + t2: (bytes){ 'foo' } 19 + t3: (_|_){ 20 + // [eval] error in call to encoding/hex.Decode: encoding/hex: invalid byte: U+006F 'o' 21 + } 22 + t4: (string){ "00000000 66 6f 6f |foo|\n" } 23 + }
+25
pkg/encoding/json/json_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package json_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("json", t) 25 + }
+39
pkg/encoding/json/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "encoding/json" 5 + 6 + t1: json.Validate("{\"a\":10}", {b:string}) 7 + t2: json.Validate("{\"a\":10}", {a:<3}) 8 + t3: json.Valid("1") 9 + t4: json.Compact("[1, 2]") 10 + t5: json.Indent(#"{"a": 1, "b": 2}"#, "", " ") 11 + t6: json.Unmarshal("1") 12 + t7: json.MarshalStream([{a: 1}, {b: 2}]) 13 + t8: { 14 + x: int 15 + y: json.Marshal({a: x}) 16 + } 17 + -- out/json -- 18 + Errors: 19 + a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3) 20 + 21 + Result: 22 + (_|_){ 23 + // [eval] 24 + t1: (bool){ true } 25 + t2: (_|_){ 26 + // [eval] a: error in call to encoding/json.Validate: invalid value 10 (out of bound <3) 27 + } 28 + t3: (bool){ true } 29 + t4: (string){ "[1,2]" } 30 + t5: (string){ "{\n \"a\": 1,\n \"b\": 2\n}" } 31 + t6: (int){ 1 } 32 + t7: (string){ "{\"a\":1}\n{\"b\":2}\n" } 33 + t8: (struct){ 34 + x: (int){ int } 35 + y: (_|_){ 36 + // [incomplete] cannot convert incomplete value "int" to JSON 37 + } 38 + } 39 + }
+35
pkg/encoding/yaml/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "encoding/yaml" 5 + 6 + t1: yaml.Validate("a: 2\n---\na: 4", {a:<3}) 7 + t2: yaml.Validate("a: 2\n---\na: 4", {a:<5}) 8 + t3: yaml.Validate("a: 2\n", {a:<5, b:int}) 9 + t4: yaml.ValidatePartial("a: 2\n---\na: 4", {a:<3}) 10 + t5: yaml.ValidatePartial("a: 2\n---\na: 4", {a:<5}) 11 + t6: yaml.ValidatePartial("a: 2\n", {a:<5, b:int}) 12 + t7: yaml.MarshalStream([{a: 1}, {b: 2}]) 13 + -- out/yaml -- 14 + Errors: 15 + a: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3) 16 + a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3) 17 + b: error in call to encoding/yaml.Validate: incomplete value int 18 + 19 + Result: 20 + (_|_){ 21 + // [eval] 22 + t1: (_|_){ 23 + // [eval] a: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3) 24 + } 25 + t2: (bool){ true } 26 + t3: (_|_){ 27 + // [eval] b: error in call to encoding/yaml.Validate: incomplete value int 28 + } 29 + t4: (_|_){ 30 + // [eval] a: error in call to encoding/yaml.ValidatePartial: invalid value 4 (out of bound <3) 31 + } 32 + t5: (bool){ true } 33 + t6: (bool){ true } 34 + t7: (string){ "a: 1\n---\nb: 2\n" } 35 + }
+25
pkg/encoding/yaml/yaml_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package yaml_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("yaml", t) 25 + }
+60
pkg/internal/builtintest/testing.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package builtintest 16 + 17 + import ( 18 + "fmt" 19 + "testing" 20 + 21 + "cuelang.org/go/cue" 22 + "cuelang.org/go/internal/core/debug" 23 + "cuelang.org/go/internal/core/eval" 24 + "cuelang.org/go/internal/core/validate" 25 + "cuelang.org/go/internal/cuetxtar" 26 + ) 27 + 28 + func Run(name string, t *testing.T) { 29 + test := cuetxtar.TxTarTest{ 30 + Root: "./testdata", 31 + Name: name, 32 + } 33 + 34 + r := cue.NewRuntime() 35 + 36 + test.Run(t, func(t *cuetxtar.Test) { 37 + a := t.ValidInstances() 38 + 39 + v, err := r.Build(a[0]) 40 + if err != nil { 41 + t.Fatal(err) 42 + } 43 + 44 + e := eval.New(r) 45 + ctx := e.NewContext(v) 46 + v.Finalize(ctx) 47 + 48 + if b := validate.Validate(ctx, v, &validate.Config{ 49 + AllErrors: true, 50 + }); b != nil { 51 + fmt.Fprintln(t, "Errors:") 52 + t.WriteErrors(b.Err) 53 + fmt.Fprintln(t, "") 54 + fmt.Fprintln(t, "Result:") 55 + } 56 + 57 + debug.WriteNode(t, r, v, &debug.Config{Cwd: t.Dir}) 58 + fmt.Fprintln(t) 59 + }) 60 + }
+25
pkg/list/list_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package list_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("list", t) 25 + }
+305
pkg/list/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "list" 5 + 6 + t1: list.Avg([1, 2, 3, 4]) 7 + t2: list.Avg([]) 8 + t3: list.Avg("foo") 9 + t4: list.Drop([1, 2, 3, 4], 0) 10 + t5: list.Drop([1, 2, 3, 4], 2) 11 + t6: list.Drop([1, 2, 3, 4], 10) 12 + t7: list.Drop([1, 2, 3, 4], -1) 13 + t8: list.FlattenN([1, [[2, 3], []], [4]], -1) 14 + t9: list.FlattenN([1, [[2, 3], []], [4]], 0) 15 + t10: list.FlattenN([1, [[2, 3], []], [4]], 1) 16 + t11: list.FlattenN([1, [[2, 3], []], [4]], 2) 17 + t12: list.FlattenN([[1, 2] | *[]], -1) 18 + t13: list.FlattenN("foo", 1) 19 + t14: list.FlattenN([], "foo") 20 + t15: list.Max([1, 2, 3, 4]) 21 + t16: list.Max([]) 22 + t17: list.Max("foo") 23 + t18: list.Min([1, 2, 3, 4]) 24 + t19: list.Min([]) 25 + t20: list.Min("foo") 26 + t21: list.Product([1, 2, 3, 4]) 27 + t22: list.Product([]) 28 + t23: list.Product("foo") 29 + t24: list.Range(0, 5, 0) 30 + t25: list.Range(5, 0, 1) 31 + t26: list.Range(0, 5, -1) 32 + t27: list.Range(0, 5, 1) 33 + t28: list.Range(0, 1, 1) 34 + t29: list.Range(0, 5, 2) 35 + t30: list.Range(5, 0, -1) 36 + t31: list.Range(0, 5, 0.5) 37 + t32: list.Slice([1, 2, 3, 4], 1, 3) 38 + t33: list.Slice([1, 2, 3, 4], -1, 3) 39 + t34: list.Slice([1, 2, 3, 4], 3, 1) 40 + t35: list.Slice([1, 2, 3, 4], 5, 5) 41 + t36: list.Slice([1, 2, 3, 4], 1, 5) 42 + t37: list.Sort([], list.Ascending) 43 + t38: list.Sort([2, 3, 1, 4], {x:_, y:_, less: x<y}) 44 + t39: list.SortStable([{a:2,v:1}, {a:1,v:2}, {a:1,v:3}], { 45 + x:_, 46 + y:_, 47 + less: (x.a < y.a) 48 + }) 49 + t40: list.Sort([{a:1}, {b:2}], list.Ascending) 50 + t41: list.SortStrings(["b", "a"]) 51 + t42: list.SortStrings([1, 2]) 52 + t43: list.Sum([1, 2, 3, 4]) 53 + t44: list.Sum([]) 54 + t45: list.Sum("foo") 55 + t46: list.Take([1, 2, 3, 4], 0) 56 + t47: list.Take([1, 2, 3, 4], 2) 57 + t48: list.Take([1, 2, 3, 4], 10) 58 + t49: list.Take([1, 2, 3, 4], -1) 59 + t50: list.MinItems([1, 2, 3, 4], 2) 60 + t51: list.MinItems([1, 2, 3, 4], 5) 61 + t52: list.MaxItems([1, 2, 3, 4], 5) 62 + t53: list.MaxItems([1, 2, 3, 4], 2) 63 + t54: list.Sort([{a:1}, {b:2}], list.Ascending) 64 + -- out/list -- 65 + Errors: 66 + error in call to list.Avg: empty list 67 + error in call to list.Drop: negative index 68 + error in call to list.FlattenN: cannot use value "foo" (type string) as list 69 + error in call to list.Max: empty list 70 + error in call to list.Min: empty list 71 + error in call to list.Range: end must be greater than start when step is positive 72 + error in call to list.Range: end must be less than start when step is negative 73 + error in call to list.Range: step must be non zero 74 + error in call to list.Slice: invalid index: 3 > 1 75 + error in call to list.Slice: negative index 76 + error in call to list.Slice: slice bounds out of range 77 + error in call to list.Take: negative index 78 + 0: error in call to list.SortStrings: element 0 of list argument 0: cannot use value 1 (type int) as string 79 + x: error in call to list.Sort: x: conflicting values string and {b:2} (mismatched types string and struct) (and 1 more errors) 80 + t3: cannot use "foo" (type string) as list in argument 1 to list.Avg: 81 + ./in.cue:5:14 82 + t14: cannot use "foo" (type string) as int in argument 2 to list.FlattenN: 83 + ./in.cue:16:24 84 + t17: cannot use "foo" (type string) as list in argument 1 to list.Max: 85 + ./in.cue:19:15 86 + t20: cannot use "foo" (type string) as list in argument 1 to list.Min: 87 + ./in.cue:22:15 88 + t23: cannot use "foo" (type string) as list in argument 1 to list.Product: 89 + ./in.cue:25:19 90 + t45: cannot use "foo" (type string) as list in argument 1 to list.Sum: 91 + ./in.cue:51:15 92 + 93 + Result: 94 + (_|_){ 95 + // [eval] 96 + t1: (number){ 2.5 } 97 + t2: (_|_){ 98 + // [eval] error in call to list.Avg: empty list 99 + } 100 + t3: (_|_){ 101 + // [eval] t3: cannot use "foo" (type string) as list in argument 1 to list.Avg: 102 + // ./in.cue:5:14 103 + } 104 + t4: (#list){ 105 + 0: (int){ 1 } 106 + 1: (int){ 2 } 107 + 2: (int){ 3 } 108 + 3: (int){ 4 } 109 + } 110 + t5: (#list){ 111 + 0: (int){ 3 } 112 + 1: (int){ 4 } 113 + } 114 + t6: (#list){ 115 + } 116 + t7: (_|_){ 117 + // [eval] error in call to list.Drop: negative index 118 + } 119 + t8: (#list){ 120 + 0: (int){ 1 } 121 + 1: (int){ 2 } 122 + 2: (int){ 3 } 123 + 3: (int){ 4 } 124 + } 125 + t9: (#list){ 126 + 0: (int){ 1 } 127 + 1: (#list){ 128 + 0: (#list){ 129 + 0: (int){ 2 } 130 + 1: (int){ 3 } 131 + } 132 + 1: (#list){ 133 + } 134 + } 135 + 2: (#list){ 136 + 0: (int){ 4 } 137 + } 138 + } 139 + t10: (#list){ 140 + 0: (int){ 1 } 141 + 1: (#list){ 142 + 0: (int){ 2 } 143 + 1: (int){ 3 } 144 + } 145 + 2: (#list){ 146 + } 147 + 3: (int){ 4 } 148 + } 149 + t11: (#list){ 150 + 0: (int){ 1 } 151 + 1: (int){ 2 } 152 + 2: (int){ 3 } 153 + 3: (int){ 4 } 154 + } 155 + t12: (#list){ 156 + } 157 + t13: (_|_){ 158 + // [eval] error in call to list.FlattenN: cannot use value "foo" (type string) as list 159 + } 160 + t14: (_|_){ 161 + // [eval] t14: cannot use "foo" (type string) as int in argument 2 to list.FlattenN: 162 + // ./in.cue:16:24 163 + } 164 + t15: (number){ 4 } 165 + t16: (_|_){ 166 + // [eval] error in call to list.Max: empty list 167 + } 168 + t17: (_|_){ 169 + // [eval] t17: cannot use "foo" (type string) as list in argument 1 to list.Max: 170 + // ./in.cue:19:15 171 + } 172 + t18: (number){ 1 } 173 + t19: (_|_){ 174 + // [eval] error in call to list.Min: empty list 175 + } 176 + t20: (_|_){ 177 + // [eval] t20: cannot use "foo" (type string) as list in argument 1 to list.Min: 178 + // ./in.cue:22:15 179 + } 180 + t21: (number){ 24 } 181 + t22: (number){ 1 } 182 + t23: (_|_){ 183 + // [eval] t23: cannot use "foo" (type string) as list in argument 1 to list.Product: 184 + // ./in.cue:25:19 185 + } 186 + t24: (_|_){ 187 + // [eval] error in call to list.Range: step must be non zero 188 + } 189 + t25: (_|_){ 190 + // [eval] error in call to list.Range: end must be greater than start when step is positive 191 + } 192 + t26: (_|_){ 193 + // [eval] error in call to list.Range: end must be less than start when step is negative 194 + } 195 + t27: (#list){ 196 + 0: (number){ 0 } 197 + 1: (number){ 1 } 198 + 2: (number){ 2 } 199 + 3: (number){ 3 } 200 + 4: (number){ 4 } 201 + } 202 + t28: (#list){ 203 + 0: (number){ 0 } 204 + } 205 + t29: (#list){ 206 + 0: (number){ 0 } 207 + 1: (number){ 2 } 208 + 2: (number){ 4 } 209 + } 210 + t30: (#list){ 211 + 0: (number){ 5 } 212 + 1: (number){ 4 } 213 + 2: (number){ 3 } 214 + 3: (number){ 2 } 215 + 4: (number){ 1 } 216 + } 217 + t31: (#list){ 218 + 0: (number){ 0 } 219 + 1: (number){ 0.5 } 220 + 2: (number){ 1.0 } 221 + 3: (number){ 1.5 } 222 + 4: (number){ 2.0 } 223 + 5: (number){ 2.5 } 224 + 6: (number){ 3.0 } 225 + 7: (number){ 3.5 } 226 + 8: (number){ 4.0 } 227 + 9: (number){ 4.5 } 228 + } 229 + t32: (#list){ 230 + 0: (int){ 2 } 231 + 1: (int){ 3 } 232 + } 233 + t33: (_|_){ 234 + // [eval] error in call to list.Slice: negative index 235 + } 236 + t34: (_|_){ 237 + // [eval] error in call to list.Slice: invalid index: 3 > 1 238 + } 239 + t35: (_|_){ 240 + // [eval] error in call to list.Slice: slice bounds out of range 241 + } 242 + t36: (_|_){ 243 + // [eval] error in call to list.Slice: slice bounds out of range 244 + } 245 + t37: (#list){ 246 + } 247 + t38: (#list){ 248 + 0: (int){ 1 } 249 + 1: (int){ 2 } 250 + 2: (int){ 3 } 251 + 3: (int){ 4 } 252 + } 253 + t39: (#list){ 254 + 0: (struct){ 255 + a: (int){ 1 } 256 + v: (int){ 2 } 257 + } 258 + 1: (struct){ 259 + a: (int){ 1 } 260 + v: (int){ 3 } 261 + } 262 + 2: (struct){ 263 + a: (int){ 2 } 264 + v: (int){ 1 } 265 + } 266 + } 267 + t40: (_|_){ 268 + // [eval] x: error in call to list.Sort: x: conflicting values string and {b:2} (mismatched types string and struct) (and 1 more errors) 269 + } 270 + t41: (#list){ 271 + 0: (string){ "a" } 272 + 1: (string){ "b" } 273 + } 274 + t42: (_|_){ 275 + // [eval] 0: error in call to list.SortStrings: element 0 of list argument 0: cannot use value 1 (type int) as string 276 + } 277 + t43: (number){ 10 } 278 + t44: (number){ 0 } 279 + t45: (_|_){ 280 + // [eval] t45: cannot use "foo" (type string) as list in argument 1 to list.Sum: 281 + // ./in.cue:51:15 282 + } 283 + t46: (#list){ 284 + } 285 + t47: (#list){ 286 + 0: (int){ 1 } 287 + 1: (int){ 2 } 288 + } 289 + t48: (#list){ 290 + 0: (int){ 1 } 291 + 1: (int){ 2 } 292 + 2: (int){ 3 } 293 + 3: (int){ 4 } 294 + } 295 + t49: (_|_){ 296 + // [eval] error in call to list.Take: negative index 297 + } 298 + t50: (bool){ true } 299 + t51: (bool){ false } 300 + t52: (bool){ true } 301 + t53: (bool){ false } 302 + t54: (_|_){ 303 + // [eval] x: error in call to list.Sort: x: conflicting values string and {b:2} (mismatched types string and struct) (and 1 more errors) 304 + } 305 + }
+25
pkg/math/bits/bits_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package bits_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("bits", t) 25 + }
+34
pkg/math/bits/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "math/bits" 5 + 6 + t1: bits.Or(0x8, 0x1) 7 + t2: bits.Lsh(0x8, 4) 8 + t3: bits.Rsh(0x100, 4) 9 + t4: bits.At(0x100, 8) 10 + t5: bits.At(0x100, 9) 11 + t6: bits.Set(0x100, 7, 1) 12 + t7: bits.Set(0x100, 8, 0) 13 + t8: bits.And(0x10000000000000F0E, 0xF0F7) 14 + t9: bits.Or(0x100000000000000F0, 0x0F) 15 + t10: bits.Xor(0x10000000000000F0F, 0xFF0) 16 + t11: bits.Xor(0xFF0, 0x10000000000000F0F) 17 + t12: bits.Clear(0xF, 0x100000000000008) 18 + t13: bits.Clear(0x1000000000000000008, 0xF) 19 + -- out/bits -- 20 + (struct){ 21 + t1: (int){ 9 } 22 + t2: (int){ 128 } 23 + t3: (int){ 16 } 24 + t4: (int){ 1 } 25 + t5: (int){ 0 } 26 + t6: (int){ 384 } 27 + t7: (int){ 0 } 28 + t8: (int){ 6 } 29 + t9: (int){ 18446744073709551871 } 30 + t10: (int){ 18446744073709551871 } 31 + t11: (int){ 18446744073709551871 } 32 + t12: (int){ 7 } 33 + t13: (int){ 4722366482869645213696 } 34 + }
+25
pkg/math/math_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package math_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("math", t) 25 + }
+116
pkg/math/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "math" 5 + 6 + t1: math.Pi 7 + t2: math.Floor(math.Pi) 8 + t3: math.Pi(3) 9 + t4: math.Floor(3, 5) 10 + t5: math.Floor("foo") 11 + t6: math.Jacobi(1000, 2000) 12 + t7: math.Jacobi(1000, 201) 13 + t8: math.Asin(2.0e400) 14 + t9: math.MultipleOf(4, 2) 15 + t10: math.MultipleOf(5, 2) 16 + t11: math.MultipleOf(5, 0) 17 + t12: math.MultipleOf(100, 1.00001) 18 + t13: math.MultipleOf(1, 1) 19 + t14: math.MultipleOf(5, 2.5) 20 + t15: math.MultipleOf(100e100, 10) 21 + t16: math.Pow(8, 4) 22 + t17: math.Pow10(4) 23 + t18: math.Signbit(-4) 24 + t19: math.Round(2.5) 25 + t20: math.Round(-2.5) 26 + t21: math.RoundToEven(2.5) 27 + t22: math.RoundToEven(-2.5) 28 + t23: math.Abs(2.5) 29 + t24: math.Abs(-2.2) 30 + t25: math.Cbrt(2) 31 + t26: math.Copysign(5, -2.2) 32 + t27: math.Exp(3) 33 + t28: math.Exp2(3.5) 34 + t29: math.Log(4) 35 + t30: math.Log10(4) 36 + t31: math.Log2(5) 37 + t32: math.Dim(3, 2.5) 38 + t33: math.Dim(5, 7.2) 39 + t34: math.Ceil(2.5) 40 + t35: math.Ceil(-2.2) 41 + t36: math.Floor(2.9) 42 + t37: math.Floor(-2.2) 43 + t38: math.Trunc(2.5) 44 + t39: math.Trunc(-2.9) 45 + -- out/math -- 46 + Errors: 47 + error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000 48 + error in call to math.MultipleOf: division by zero 49 + t3: cannot call non-function math.Pi (type float): 50 + ./in.cue:5:5 51 + t4: too many arguments in call to math.Floor (have 2, want 1): 52 + ./in.cue:6:20 53 + t5: cannot use "foo" (type string) as number in argument 1 to math.Floor: 54 + ./in.cue:7:16 55 + cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up: 56 + ./in.cue:10:5 57 + 58 + Result: 59 + (_|_){ 60 + // [eval] 61 + t1: (float){ 3.14159265358979323846264338327950288419716939937510582097494459 } 62 + t2: (number){ 3 } 63 + t3: (_|_){ 64 + // [eval] t3: cannot call non-function math.Pi (type float): 65 + // ./in.cue:5:5 66 + } 67 + t4: (_|_){ 68 + // [eval] t4: too many arguments in call to math.Floor (have 2, want 1): 69 + // ./in.cue:6:20 70 + } 71 + t5: (_|_){ 72 + // [eval] t5: cannot use "foo" (type string) as number in argument 1 to math.Floor: 73 + // ./in.cue:7:16 74 + } 75 + t6: (_|_){ 76 + // [eval] error in call to math.Jacobi: big: invalid 2nd argument to Int.Jacobi: need odd integer but got 2000 77 + } 78 + t7: (int){ 1 } 79 + t8: (_|_){ 80 + // [eval] cannot use 2.0E+400 (type float) as float64 in argument 0 to math.Asin: value was rounded up: 81 + // ./in.cue:10:5 82 + } 83 + t9: (bool){ true } 84 + t10: (bool){ false } 85 + t11: (_|_){ 86 + // [eval] error in call to math.MultipleOf: division by zero 87 + } 88 + t12: (bool){ false } 89 + t13: (bool){ true } 90 + t14: (bool){ true } 91 + t15: (bool){ true } 92 + t16: (number){ 4096 } 93 + t17: (number){ 1E+4 } 94 + t18: (bool){ true } 95 + t19: (number){ 3 } 96 + t20: (number){ -3 } 97 + t21: (number){ 2 } 98 + t22: (number){ -2 } 99 + t23: (number){ 2.5 } 100 + t24: (number){ 2.2 } 101 + t25: (number){ 1.25992104989487316476721 } 102 + t26: (number){ -5 } 103 + t27: (number){ 20.0855369231876677409285 } 104 + t28: (number){ 11.3137084989847603904135 } 105 + t29: (number){ 1.38629436111989061883446 } 106 + t30: (number){ 0.602059991327962390427478 } 107 + t31: (number){ 2.32192809488736234787032 } 108 + t32: (number){ 0.5 } 109 + t33: (number){ 0 } 110 + t34: (number){ 3 } 111 + t35: (number){ -2 } 112 + t36: (number){ 2 } 113 + t37: (number){ -3 } 114 + t38: (number){ 2 } 115 + t39: (number){ -2 } 116 + }
+25
pkg/net/net_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package net_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("net", t) 25 + }
+82
pkg/net/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "net" 5 + 6 + t1: net.FQDN & "foo.bar." 7 + t2: net.FQDN("foo.bararararararararararararararararararararararararararararararararara") 8 + t3: net.SplitHostPort("[::%lo0]:80") 9 + t4: net.JoinHostPort("example.com", "80") 10 + t5: net.JoinHostPort("2001:db8::1", 80) 11 + t6: net.JoinHostPort([192,30,4,2], 80) 12 + t7: net.JoinHostPort([192, 30, 4], 80) 13 + t8: net.IP("23.23.23.23") 14 + t9: net.IPv4 & "23.23.23.2333" 15 + t10: net.IP("23.23.23.23") 16 + t11: net.IP("2001:db8::1") 17 + t12: net.IPv4("2001:db8::1") 18 + t13: net.IPv4() & "ff02::1:3" 19 + t14: net.LoopbackIP([127, 0, 0, 1]) 20 + t15: net.LoopbackIP("127.0.0.1") 21 + t16: net.ToIP4("127.0.0.1") 22 + t17: net.ToIP16("127.0.0.1") 23 + -- out/net -- 24 + Errors: 25 + error in call to net.JoinHostPort: invalid host [192, 30, 4] 26 + t9: invalid value "23.23.23.2333" (does not satisfy net.IPv4) 27 + t13: invalid value "ff02::1:3" (does not satisfy net.IPv4): 28 + ./in.cue:15:6 29 + 30 + Result: 31 + (_|_){ 32 + // [eval] 33 + t1: (string){ "foo.bar." } 34 + t2: (bool){ false } 35 + t3: (#list){ 36 + 0: (string){ "::%lo0" } 37 + 1: (string){ "80" } 38 + } 39 + t4: (string){ "example.com:80" } 40 + t5: (string){ "[2001:db8::1]:80" } 41 + t6: (string){ "192.30.4.2:80" } 42 + t7: (_|_){ 43 + // [eval] error in call to net.JoinHostPort: invalid host [192, 30, 4] 44 + } 45 + t8: (bool){ true } 46 + t9: (_|_){ 47 + // [eval] t9: invalid value "23.23.23.2333" (does not satisfy net.IPv4) 48 + } 49 + t10: (bool){ true } 50 + t11: (bool){ true } 51 + t12: (bool){ false } 52 + t13: (_|_){ 53 + // [eval] t13: invalid value "ff02::1:3" (does not satisfy net.IPv4): 54 + // ./in.cue:15:6 55 + } 56 + t14: (bool){ true } 57 + t15: (bool){ true } 58 + t16: (#list){ 59 + 0: (int){ 127 } 60 + 1: (int){ 0 } 61 + 2: (int){ 0 } 62 + 3: (int){ 1 } 63 + } 64 + t17: (#list){ 65 + 0: (int){ 0 } 66 + 1: (int){ 0 } 67 + 2: (int){ 0 } 68 + 3: (int){ 0 } 69 + 4: (int){ 0 } 70 + 5: (int){ 0 } 71 + 6: (int){ 0 } 72 + 7: (int){ 0 } 73 + 8: (int){ 0 } 74 + 9: (int){ 0 } 75 + 10: (int){ 255 } 76 + 11: (int){ 255 } 77 + 12: (int){ 127 } 78 + 13: (int){ 0 } 79 + 14: (int){ 0 } 80 + 15: (int){ 1 } 81 + } 82 + }
+25
pkg/regexp/regexp_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package regexp_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("regexp", t) 25 + }
+101
pkg/regexp/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "regexp" 5 + 6 + t1: regexp.Find(#"f\w\w"#, "afoot") 7 + t2: regexp.Find(#"f\w\w"#, "bar") 8 + t3: regexp.FindAll(#"f\w\w"#, "afoot afloat from", 2) 9 + t4: regexp.FindAll(#"f\w\w"#, "afoot afloat from", 2) 10 + t5: regexp.FindAll(#"f\w\w"#, "bla bla", -1) 11 + t6: regexp.FindSubmatch(#"f(\w)(\w)"#, "afloat afoot from") 12 + t7: regexp.FindAllSubmatch(#"f(\w)(\w)"#, "afloat afoot from", -1) 13 + t8: regexp.FindAllSubmatch(#"f(\w)(\w)"#, "aglom", -1) 14 + t9: regexp.FindNamedSubmatch(#"f(?P<A>\w)(?P<B>\w)"#, "afloat afoot from") 15 + t10: regexp.FindAllNamedSubmatch(#"f(?P<A>\w)(?P<B>\w)"#, "afloat afoot from", -1) 16 + t11: regexp.FindAllNamedSubmatch(#"f(?P<A>optional)?"#, "fbla", -1) 17 + t12: regexp.FindAllNamedSubmatch(#"f(?P<A>\w)(?P<B>\w)"#, "aglom", -1) 18 + t13: regexp.Valid & "valid" 19 + t14: regexp.Valid & "invalid)" 20 + -- out/regexp -- 21 + Errors: 22 + error in call to regexp.Find: no match 23 + error in call to regexp.FindAll: no match 24 + error in call to regexp.FindAllNamedSubmatch: no match 25 + error in call to regexp.FindAllSubmatch: no match 26 + error in call to regexp.Valid: error parsing regexp: unexpected ): `invalid)` 27 + 28 + Result: 29 + (_|_){ 30 + // [eval] 31 + t1: (string){ "foo" } 32 + t2: (_|_){ 33 + // [eval] error in call to regexp.Find: no match 34 + } 35 + t3: (#list){ 36 + 0: (string){ "foo" } 37 + 1: (string){ "flo" } 38 + } 39 + t4: (#list){ 40 + 0: (string){ "foo" } 41 + 1: (string){ "flo" } 42 + } 43 + t5: (_|_){ 44 + // [eval] error in call to regexp.FindAll: no match 45 + } 46 + t6: (#list){ 47 + 0: (string){ "flo" } 48 + 1: (string){ "l" } 49 + 2: (string){ "o" } 50 + } 51 + t7: (#list){ 52 + 0: (#list){ 53 + 0: (string){ "flo" } 54 + 1: (string){ "l" } 55 + 2: (string){ "o" } 56 + } 57 + 1: (#list){ 58 + 0: (string){ "foo" } 59 + 1: (string){ "o" } 60 + 2: (string){ "o" } 61 + } 62 + 2: (#list){ 63 + 0: (string){ "fro" } 64 + 1: (string){ "r" } 65 + 2: (string){ "o" } 66 + } 67 + } 68 + t8: (_|_){ 69 + // [eval] error in call to regexp.FindAllSubmatch: no match 70 + } 71 + t9: (struct){ 72 + A: (string){ "l" } 73 + B: (string){ "o" } 74 + } 75 + t10: (#list){ 76 + 0: (struct){ 77 + A: (string){ "l" } 78 + B: (string){ "o" } 79 + } 80 + 1: (struct){ 81 + A: (string){ "o" } 82 + B: (string){ "o" } 83 + } 84 + 2: (struct){ 85 + A: (string){ "r" } 86 + B: (string){ "o" } 87 + } 88 + } 89 + t11: (#list){ 90 + 0: (struct){ 91 + A: (string){ "" } 92 + } 93 + } 94 + t12: (_|_){ 95 + // [eval] error in call to regexp.FindAllNamedSubmatch: no match 96 + } 97 + t13: (string){ "valid" } 98 + t14: (_|_){ 99 + // [eval] error in call to regexp.Valid: error parsing regexp: unexpected ): `invalid)` 100 + } 101 + }
+25
pkg/strconv/strconv_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package strconv_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("strconv", t) 25 + }
+37
pkg/strconv/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "strconv" 5 + 6 + t1: strconv.FormatUint(64, 16) 7 + t2: strconv.FormatFloat(3.02, 300, 4, 64) 8 + t3: strconv.FormatFloat(3.02, -1, 4, 64) 9 + t4: strconv.FormatFloat(3.02, 1.0, 4, 64) 10 + t5: strconv.FormatBool(true) 11 + -- out/strconv -- 12 + Errors: 13 + int 300 overflows byte in argument 1 in call to strconv.FormatFloat: 14 + ./in.cue:4:5 15 + cannot use -1 (type int) as byte in argument 1 to strconv.FormatFloat: 16 + ./in.cue:5:5 17 + t4: cannot use 1.0 (type float) as int in argument 2 to strconv.FormatFloat: 18 + ./in.cue:6:31 19 + 20 + Result: 21 + (_|_){ 22 + // [eval] 23 + t1: (string){ "40" } 24 + t2: (_|_){ 25 + // [eval] int 300 overflows byte in argument 1 in call to strconv.FormatFloat: 26 + // ./in.cue:4:5 27 + } 28 + t3: (_|_){ 29 + // [eval] cannot use -1 (type int) as byte in argument 1 to strconv.FormatFloat: 30 + // ./in.cue:5:5 31 + } 32 + t4: (_|_){ 33 + // [eval] t4: cannot use 1.0 (type float) as int in argument 2 to strconv.FormatFloat: 34 + // ./in.cue:6:31 35 + } 36 + t5: (string){ "true" } 37 + }
+25
pkg/strings/strings_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package strings_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("strings", t) 25 + }
+74
pkg/strings/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "strings" 5 + 6 + t1: strings.Join(["Hello", "World!"], " ") 7 + t2: strings.Join([1, 2], " ") 8 + t3: strings.ByteAt("a", 0) 9 + t4: strings.ByteSlice("Hello", 2, 5) 10 + t5: strings.SliceRunes("✓ Hello", 0, 3) 11 + t6: strings.Runes("Café") 12 + t7: strings.ToCamel("AlphaBeta") 13 + t8: strings.ToTitle("alpha") 14 + t9: strings.MaxRunes(3) & "foo" 15 + t10: strings.MaxRunes(3) & "quux" 16 + t11: strings.MinRunes(1) & "e" 17 + t12: strings.MaxRunes(0) & "e" 18 + t13: strings.MaxRunes(0) & "" 19 + t14: strings.MinRunes(3) & "hello" 20 + t15: strings.MaxRunes(10) & "hello" 21 + t16: strings.MaxRunes(3) & "hello" 22 + t17: strings.MinRunes(10) & "hello" 23 + -- out/strings -- 24 + Errors: 25 + 0: error in call to strings.Join: element 0 of list argument 0: cannot use value 1 (type int) as string 26 + t10: invalid value "quux" (does not satisfy strings.MaxRunes(3)): 27 + ./in.cue:12:6 28 + t12: invalid value "e" (does not satisfy strings.MaxRunes(0)): 29 + ./in.cue:14:6 30 + t16: invalid value "hello" (does not satisfy strings.MaxRunes(3)): 31 + ./in.cue:18:6 32 + t17: invalid value "hello" (does not satisfy strings.MinRunes(10)): 33 + ./in.cue:19:6 34 + 35 + Result: 36 + (_|_){ 37 + // [eval] 38 + t1: (string){ "Hello World!" } 39 + t2: (_|_){ 40 + // [eval] 0: error in call to strings.Join: element 0 of list argument 0: cannot use value 1 (type int) as string 41 + } 42 + t3: (int){ 97 } 43 + t4: (bytes){ 'llo' } 44 + t5: (string){ "✓ H" } 45 + t6: (#list){ 46 + 0: (int){ 67 } 47 + 1: (int){ 97 } 48 + 2: (int){ 102 } 49 + 3: (int){ 233 } 50 + } 51 + t7: (string){ "alphaBeta" } 52 + t8: (string){ "Alpha" } 53 + t9: (string){ "foo" } 54 + t10: (_|_){ 55 + // [eval] t10: invalid value "quux" (does not satisfy strings.MaxRunes(3)): 56 + // ./in.cue:12:6 57 + } 58 + t11: (string){ "e" } 59 + t12: (_|_){ 60 + // [eval] t12: invalid value "e" (does not satisfy strings.MaxRunes(0)): 61 + // ./in.cue:14:6 62 + } 63 + t13: (string){ "" } 64 + t14: (string){ "hello" } 65 + t15: (string){ "hello" } 66 + t16: (_|_){ 67 + // [eval] t16: invalid value "hello" (does not satisfy strings.MaxRunes(3)): 68 + // ./in.cue:18:6 69 + } 70 + t17: (_|_){ 71 + // [eval] t17: invalid value "hello" (does not satisfy strings.MinRunes(10)): 72 + // ./in.cue:19:6 73 + } 74 + }
+25
pkg/struct/structs_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package structs_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("structs", t) 25 + }
+41
pkg/struct/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "struct" 5 + 6 + t1: struct.MinFields(0) & "" 7 + t2: struct.MinFields(0) & {a: 1} 8 + t3: struct.MinFields(2) & {a: 1} 9 + t4: struct.MaxFields(0) & {a: 1} 10 + t5: struct.MaxFields(2) & {a: 1} 11 + -- out/structs -- 12 + Errors: 13 + t1: conflicting values struct.MinFields(0) and "" (mismatched types struct and string) 14 + t3: invalid value {a:1} (does not satisfy struct.MinFields(2)): 15 + ./in.cue:5:5 16 + t4: invalid value {a:1} (does not satisfy struct.MaxFields(0)): 17 + ./in.cue:6:5 18 + 19 + Result: 20 + (_|_){ 21 + // [eval] 22 + t1: (_|_){ 23 + // [eval] t1: conflicting values struct.MinFields(0) and "" (mismatched types struct and string) 24 + } 25 + t2: (struct){ 26 + a: (int){ 1 } 27 + } 28 + t3: (_|_){ 29 + // [eval] t3: invalid value {a:1} (does not satisfy struct.MinFields(2)): 30 + // ./in.cue:5:5 31 + a: (int){ 1 } 32 + } 33 + t4: (_|_){ 34 + // [eval] t4: invalid value {a:1} (does not satisfy struct.MaxFields(0)): 35 + // ./in.cue:6:5 36 + a: (int){ 1 } 37 + } 38 + t5: (struct){ 39 + a: (int){ 1 } 40 + } 41 + }
+25
pkg/text/tabwriter/tabwriter_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package tabwriter_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("tabwriter", t) 25 + }
+17
pkg/text/tabwriter/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "text/tabwriter" 5 + 6 + t1: tabwriter.Write(""" 7 + a\tb\tc 8 + aaa\tbb\tvv 9 + """) 10 + t2: tabwriter.Write([ 11 + "a\tb\tc", 12 + "aaa\tbb\tvv"]) 13 + -- out/tabwriter -- 14 + (struct){ 15 + t1: (string){ "a b c\naaa bb vv" } 16 + t2: (string){ "a b c\naaa bb vv\n" } 17 + }
+25
pkg/text/template/template_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package template_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("template", t) 25 + }
+10
pkg/text/template/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "text/template" 5 + 6 + t1: template.Execute("{{.}}-{{.}}", "foo") 7 + -- out/template -- 8 + (struct){ 9 + t1: (string){ "foo-foo" } 10 + }
+25
pkg/time/builtin_test.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package time_test 16 + 17 + import ( 18 + "testing" 19 + 20 + "cuelang.org/go/pkg/internal/builtintest" 21 + ) 22 + 23 + func TestBuiltin(t *testing.T) { 24 + builtintest.Run("time", t) 25 + }
+21
pkg/time/testdata/gen.txtar
··· 1 + # generated from the original tests. 2 + # Henceforth it may be nicer to group tests into separate files. 3 + -- in.cue -- 4 + import "time" 5 + 6 + t1: time.Time & "1937-01-01T12:00:27.87+00:20" 7 + t2: time.Time & "no time" 8 + t3: time.Unix(1500000000, 123456) 9 + -- out/time -- 10 + Errors: 11 + error in call to time.Time: invalid time "no time" 12 + 13 + Result: 14 + (_|_){ 15 + // [eval] 16 + t1: (string){ "1937-01-01T12:00:27.87+00:20" } 17 + t2: (_|_){ 18 + // [eval] error in call to time.Time: invalid time "no time" 19 + } 20 + t3: (string){ "2017-07-14T02:40:00.000123456Z" } 21 + }