| 1 | package lexer_test |
| 2 | |
| 3 | import ( |
| 4 | "sort" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/goccy/go-yaml/lexer" |
| 8 | "github.com/goccy/go-yaml/token" |
| 9 | ) |
| 10 | |
| 11 | func TestTokenize(t *testing.T) { |
| 12 | tests := []struct { |
| 13 | YAML string |
| 14 | Tokens token.Tokens |
| 15 | }{ |
| 16 | { |
| 17 | YAML: `null |
| 18 | `, |
| 19 | Tokens: token.Tokens{ |
| 20 | { |
| 21 | Type: token.NullType, |
| 22 | CharacterType: token.CharacterTypeMiscellaneous, |
| 23 | Indicator: token.NotIndicator, |
| 24 | Value: "null", |
| 25 | Origin: "null\n ", |
| 26 | }, |
| 27 | }, |
| 28 | }, |
| 29 | { |
| 30 | YAML: `0_`, |
| 31 | Tokens: token.Tokens{ |
| 32 | { |
| 33 | Type: token.IntegerType, |
| 34 | CharacterType: token.CharacterTypeMiscellaneous, |
| 35 | Indicator: token.NotIndicator, |
| 36 | Value: "0_", |
| 37 | Origin: "0_", |
| 38 | }, |
| 39 | }, |
| 40 | }, |
| 41 | { |
| 42 | YAML: `"hello\tworld"`, |
| 43 | Tokens: token.Tokens{ |
| 44 | { |
| 45 | Type: token.DoubleQuoteType, |
| 46 | CharacterType: token.CharacterTypeIndicator, |
| 47 | Indicator: token.QuotedScalarIndicator, |
| 48 | Value: "hello\tworld", |
| 49 | Origin: `"hello\tworld"`, |
| 50 | }, |
| 51 | }, |
| 52 | }, |
| 53 | { |
| 54 | YAML: `0x_1A_2B_3C`, |
| 55 | Tokens: token.Tokens{ |
| 56 | { |
| 57 | Type: token.HexIntegerType, |
| 58 | CharacterType: token.CharacterTypeMiscellaneous, |
| 59 | Indicator: token.NotIndicator, |
| 60 | Value: "0x_1A_2B_3C", |
| 61 | Origin: "0x_1A_2B_3C", |
| 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | { |
| 66 | YAML: `+0b1010`, |
| 67 | Tokens: token.Tokens{ |
| 68 | { |
| 69 | Type: token.BinaryIntegerType, |
| 70 | CharacterType: token.CharacterTypeMiscellaneous, |
| 71 | Indicator: token.NotIndicator, |
| 72 | Value: "+0b1010", |
| 73 | Origin: "+0b1010", |
| 74 | }, |
| 75 | }, |
| 76 | }, |
| 77 | { |
| 78 | YAML: `0100`, |
| 79 | Tokens: token.Tokens{ |
| 80 | { |
| 81 | Type: token.OctetIntegerType, |
| 82 | CharacterType: token.CharacterTypeMiscellaneous, |
| 83 | Indicator: token.NotIndicator, |
| 84 | Value: "0100", |
| 85 | Origin: "0100", |
| 86 | }, |
| 87 | }, |
| 88 | }, |
| 89 | { |
| 90 | YAML: `0o10`, |
| 91 | Tokens: token.Tokens{ |
| 92 | { |
| 93 | Type: token.OctetIntegerType, |
| 94 | CharacterType: token.CharacterTypeMiscellaneous, |
| 95 | Indicator: token.NotIndicator, |
| 96 | Value: "0o10", |
| 97 | Origin: "0o10", |
| 98 | }, |
| 99 | }, |
| 100 | }, |
| 101 | { |
| 102 | YAML: `0.123e+123`, |
| 103 | Tokens: token.Tokens{ |
| 104 | { |
| 105 | Type: token.FloatType, |
| 106 | CharacterType: token.CharacterTypeMiscellaneous, |
| 107 | Indicator: token.NotIndicator, |
| 108 | Value: "0.123e+123", |
| 109 | Origin: "0.123e+123", |
| 110 | }, |
| 111 | }, |
| 112 | }, |
| 113 | { |
| 114 | YAML: `{} |
| 115 | `, |
| 116 | Tokens: token.Tokens{ |
| 117 | { |
| 118 | Type: token.MappingStartType, |
| 119 | CharacterType: token.CharacterTypeIndicator, |
| 120 | Indicator: token.FlowCollectionIndicator, |
| 121 | Value: "{", |
| 122 | Origin: "{", |
| 123 | }, |
| 124 | { |
| 125 | Type: token.MappingEndType, |
| 126 | CharacterType: token.CharacterTypeIndicator, |
| 127 | Indicator: token.FlowCollectionIndicator, |
| 128 | Value: "}", |
| 129 | Origin: "}", |
| 130 | }, |
| 131 | }, |
| 132 | }, |
| 133 | { |
| 134 | YAML: `v: hi`, |
| 135 | Tokens: token.Tokens{ |
| 136 | { |
| 137 | Type: token.StringType, |
| 138 | CharacterType: token.CharacterTypeMiscellaneous, |
| 139 | Indicator: token.NotIndicator, |
| 140 | Value: "v", |
| 141 | Origin: "v", |
| 142 | }, |
| 143 | { |
| 144 | Type: token.MappingValueType, |
| 145 | CharacterType: token.CharacterTypeIndicator, |
| 146 | Indicator: token.BlockStructureIndicator, |
| 147 | Value: ":", |
| 148 | Origin: ":", |
| 149 | }, |
| 150 | { |
| 151 | Type: token.StringType, |
| 152 | CharacterType: token.CharacterTypeMiscellaneous, |
| 153 | Indicator: token.NotIndicator, |
| 154 | Value: "hi", |
| 155 | Origin: " hi", |
| 156 | }, |
| 157 | }, |
| 158 | }, |
| 159 | { |
| 160 | YAML: `v: a`, |
| 161 | Tokens: token.Tokens{ |
| 162 | { |
| 163 | Type: token.StringType, |
| 164 | CharacterType: token.CharacterTypeMiscellaneous, |
| 165 | Indicator: token.NotIndicator, |
| 166 | Value: "v", |
| 167 | Origin: "v", |
| 168 | }, |
| 169 | { |
| 170 | Type: token.MappingValueType, |
| 171 | CharacterType: token.CharacterTypeIndicator, |
| 172 | Indicator: token.BlockStructureIndicator, |
| 173 | Value: ":", |
| 174 | Origin: ":", |
| 175 | }, |
| 176 | { |
| 177 | Type: token.StringType, |
| 178 | CharacterType: token.CharacterTypeMiscellaneous, |
| 179 | Indicator: token.NotIndicator, |
| 180 | Value: "a", |
| 181 | // nolint: gci |
| 182 | Origin: " a", |
| 183 | }, |
| 184 | }, |
| 185 | }, |
| 186 | { |
| 187 | YAML: `v: "true"`, |
| 188 | Tokens: token.Tokens{ |
| 189 | { |
| 190 | Type: token.StringType, |
| 191 | CharacterType: token.CharacterTypeMiscellaneous, |
| 192 | Indicator: token.NotIndicator, |
| 193 | Value: "v", |
| 194 | Origin: "v", |
| 195 | }, |
| 196 | { |
| 197 | Type: token.MappingValueType, |
| 198 | CharacterType: token.CharacterTypeIndicator, |
| 199 | Indicator: token.BlockStructureIndicator, |
| 200 | Value: ":", |
| 201 | Origin: ":", |
| 202 | }, |
| 203 | { |
| 204 | Type: token.DoubleQuoteType, |
| 205 | CharacterType: token.CharacterTypeIndicator, |
| 206 | Indicator: token.QuotedScalarIndicator, |
| 207 | Value: "true", |
| 208 | Origin: " \"true\"", |
| 209 | }, |
| 210 | }, |
| 211 | }, |
| 212 | { |
| 213 | YAML: `v: "false"`, |
| 214 | Tokens: token.Tokens{ |
| 215 | { |
| 216 | Type: token.StringType, |
| 217 | CharacterType: token.CharacterTypeMiscellaneous, |
| 218 | Indicator: token.NotIndicator, |
| 219 | Value: "v", |
| 220 | Origin: "v", |
| 221 | }, |
| 222 | { |
| 223 | Type: token.MappingValueType, |
| 224 | CharacterType: token.CharacterTypeIndicator, |
| 225 | Indicator: token.BlockStructureIndicator, |
| 226 | Value: ":", |
| 227 | Origin: ":", |
| 228 | }, |
| 229 | { |
| 230 | Type: token.DoubleQuoteType, |
| 231 | CharacterType: token.CharacterTypeIndicator, |
| 232 | Indicator: token.QuotedScalarIndicator, |
| 233 | Value: "false", |
| 234 | Origin: " \"false\"", |
| 235 | }, |
| 236 | }, |
| 237 | }, |
| 238 | { |
| 239 | YAML: `v: true`, |
| 240 | Tokens: token.Tokens{ |
| 241 | { |
| 242 | Type: token.StringType, |
| 243 | CharacterType: token.CharacterTypeMiscellaneous, |
| 244 | Indicator: token.NotIndicator, |
| 245 | Value: "v", |
| 246 | Origin: "v", |
| 247 | }, |
| 248 | { |
| 249 | Type: token.MappingValueType, |
| 250 | CharacterType: token.CharacterTypeIndicator, |
| 251 | Indicator: token.BlockStructureIndicator, |
| 252 | Value: ":", |
| 253 | Origin: ":", |
| 254 | }, |
| 255 | { |
| 256 | Type: token.BoolType, |
| 257 | CharacterType: token.CharacterTypeMiscellaneous, |
| 258 | Indicator: token.NotIndicator, |
| 259 | Value: "true", |
| 260 | Origin: " true", |
| 261 | }, |
| 262 | }, |
| 263 | }, |
| 264 | { |
| 265 | YAML: `v: false`, |
| 266 | Tokens: token.Tokens{ |
| 267 | { |
| 268 | Type: token.StringType, |
| 269 | CharacterType: token.CharacterTypeMiscellaneous, |
| 270 | Indicator: token.NotIndicator, |
| 271 | Value: "v", |
| 272 | Origin: "v", |
| 273 | }, |
| 274 | { |
| 275 | Type: token.MappingValueType, |
| 276 | CharacterType: token.CharacterTypeIndicator, |
| 277 | Indicator: token.BlockStructureIndicator, |
| 278 | Value: ":", |
| 279 | Origin: ":", |
| 280 | }, |
| 281 | { |
| 282 | Type: token.BoolType, |
| 283 | CharacterType: token.CharacterTypeMiscellaneous, |
| 284 | Indicator: token.NotIndicator, |
| 285 | Value: "false", |
| 286 | Origin: " false", |
| 287 | }, |
| 288 | }, |
| 289 | }, |
| 290 | { |
| 291 | YAML: `v: 10`, |
| 292 | Tokens: token.Tokens{ |
| 293 | { |
| 294 | Type: token.StringType, |
| 295 | CharacterType: token.CharacterTypeMiscellaneous, |
| 296 | Indicator: token.NotIndicator, |
| 297 | Value: "v", |
| 298 | Origin: "v", |
| 299 | }, |
| 300 | { |
| 301 | Type: token.MappingValueType, |
| 302 | CharacterType: token.CharacterTypeIndicator, |
| 303 | Indicator: token.BlockStructureIndicator, |
| 304 | Value: ":", |
| 305 | Origin: ":", |
| 306 | }, |
| 307 | { |
| 308 | Type: token.IntegerType, |
| 309 | CharacterType: token.CharacterTypeMiscellaneous, |
| 310 | Indicator: token.NotIndicator, |
| 311 | Value: "10", |
| 312 | Origin: " 10", |
| 313 | }, |
| 314 | }, |
| 315 | }, |
| 316 | { |
| 317 | YAML: `v: -10`, |
| 318 | Tokens: token.Tokens{ |
| 319 | { |
| 320 | Type: token.StringType, |
| 321 | CharacterType: token.CharacterTypeMiscellaneous, |
| 322 | Indicator: token.NotIndicator, |
| 323 | Value: "v", |
| 324 | Origin: "v", |
| 325 | }, |
| 326 | { |
| 327 | Type: token.MappingValueType, |
| 328 | CharacterType: token.CharacterTypeIndicator, |
| 329 | Indicator: token.BlockStructureIndicator, |
| 330 | Value: ":", |
| 331 | Origin: ":", |
| 332 | }, |
| 333 | { |
| 334 | Type: token.IntegerType, |
| 335 | CharacterType: token.CharacterTypeMiscellaneous, |
| 336 | Indicator: token.NotIndicator, |
| 337 | Value: "-10", |
| 338 | Origin: " -10", |
| 339 | }, |
| 340 | }, |
| 341 | }, |
| 342 | { |
| 343 | YAML: `v: 42`, |
| 344 | Tokens: token.Tokens{ |
| 345 | { |
| 346 | Type: token.StringType, |
| 347 | CharacterType: token.CharacterTypeMiscellaneous, |
| 348 | Indicator: token.NotIndicator, |
| 349 | Value: "v", |
| 350 | Origin: "v", |
| 351 | }, |
| 352 | { |
| 353 | Type: token.MappingValueType, |
| 354 | CharacterType: token.CharacterTypeIndicator, |
| 355 | Indicator: token.BlockStructureIndicator, |
| 356 | Value: ":", |
| 357 | Origin: ":", |
| 358 | }, |
| 359 | { |
| 360 | Type: token.IntegerType, |
| 361 | CharacterType: token.CharacterTypeMiscellaneous, |
| 362 | Indicator: token.NotIndicator, |
| 363 | Value: "42", |
| 364 | Origin: " 42", |
| 365 | }, |
| 366 | }, |
| 367 | }, |
| 368 | { |
| 369 | YAML: `v: 4294967296`, |
| 370 | Tokens: token.Tokens{ |
| 371 | { |
| 372 | Type: token.StringType, |
| 373 | CharacterType: token.CharacterTypeMiscellaneous, |
| 374 | Indicator: token.NotIndicator, |
| 375 | Value: "v", |
| 376 | Origin: "v", |
| 377 | }, |
| 378 | { |
| 379 | Type: token.MappingValueType, |
| 380 | CharacterType: token.CharacterTypeIndicator, |
| 381 | Indicator: token.BlockStructureIndicator, |
| 382 | Value: ":", |
| 383 | Origin: ":", |
| 384 | }, |
| 385 | { |
| 386 | Type: token.IntegerType, |
| 387 | CharacterType: token.CharacterTypeMiscellaneous, |
| 388 | Indicator: token.NotIndicator, |
| 389 | Value: "4294967296", |
| 390 | Origin: " 4294967296", |
| 391 | }, |
| 392 | }, |
| 393 | }, |
| 394 | { |
| 395 | YAML: `v: "10"`, |
| 396 | Tokens: token.Tokens{ |
| 397 | { |
| 398 | Type: token.StringType, |
| 399 | CharacterType: token.CharacterTypeMiscellaneous, |
| 400 | Indicator: token.NotIndicator, |
| 401 | Value: "v", |
| 402 | Origin: "v", |
| 403 | }, |
| 404 | { |
| 405 | Type: token.MappingValueType, |
| 406 | CharacterType: token.CharacterTypeIndicator, |
| 407 | Indicator: token.BlockStructureIndicator, |
| 408 | Value: ":", |
| 409 | Origin: ":", |
| 410 | }, |
| 411 | { |
| 412 | Type: token.DoubleQuoteType, |
| 413 | CharacterType: token.CharacterTypeIndicator, |
| 414 | Indicator: token.QuotedScalarIndicator, |
| 415 | Value: "10", |
| 416 | Origin: " \"10\"", |
| 417 | }, |
| 418 | }, |
| 419 | }, |
| 420 | { |
| 421 | YAML: `v: 0.1`, |
| 422 | Tokens: token.Tokens{ |
| 423 | { |
| 424 | Type: token.StringType, |
| 425 | CharacterType: token.CharacterTypeMiscellaneous, |
| 426 | Indicator: token.NotIndicator, |
| 427 | Value: "v", |
| 428 | Origin: "v", |
| 429 | }, |
| 430 | { |
| 431 | Type: token.MappingValueType, |
| 432 | CharacterType: token.CharacterTypeIndicator, |
| 433 | Indicator: token.BlockStructureIndicator, |
| 434 | Value: ":", |
| 435 | Origin: ":", |
| 436 | }, |
| 437 | { |
| 438 | Type: token.FloatType, |
| 439 | CharacterType: token.CharacterTypeMiscellaneous, |
| 440 | Indicator: token.NotIndicator, |
| 441 | Value: "0.1", |
| 442 | Origin: " 0.1", |
| 443 | }, |
| 444 | }, |
| 445 | }, |
| 446 | { |
| 447 | YAML: `v: 0.99`, |
| 448 | Tokens: token.Tokens{ |
| 449 | { |
| 450 | Type: token.StringType, |
| 451 | CharacterType: token.CharacterTypeMiscellaneous, |
| 452 | Indicator: token.NotIndicator, |
| 453 | Value: "v", |
| 454 | Origin: "v", |
| 455 | }, |
| 456 | { |
| 457 | Type: token.MappingValueType, |
| 458 | CharacterType: token.CharacterTypeIndicator, |
| 459 | Indicator: token.BlockStructureIndicator, |
| 460 | Value: ":", |
| 461 | Origin: ":", |
| 462 | }, |
| 463 | { |
| 464 | Type: token.FloatType, |
| 465 | CharacterType: token.CharacterTypeMiscellaneous, |
| 466 | Indicator: token.NotIndicator, |
| 467 | Value: "0.99", |
| 468 | Origin: " 0.99", |
| 469 | }, |
| 470 | }, |
| 471 | }, |
| 472 | { |
| 473 | YAML: `v: -0.1`, |
| 474 | Tokens: token.Tokens{ |
| 475 | { |
| 476 | Type: token.StringType, |
| 477 | CharacterType: token.CharacterTypeMiscellaneous, |
| 478 | Indicator: token.NotIndicator, |
| 479 | Value: "v", |
| 480 | Origin: "v", |
| 481 | }, |
| 482 | { |
| 483 | Type: token.MappingValueType, |
| 484 | CharacterType: token.CharacterTypeIndicator, |
| 485 | Indicator: token.BlockStructureIndicator, |
| 486 | Value: ":", |
| 487 | Origin: ":", |
| 488 | }, |
| 489 | { |
| 490 | Type: token.FloatType, |
| 491 | CharacterType: token.CharacterTypeMiscellaneous, |
| 492 | Indicator: token.NotIndicator, |
| 493 | Value: "-0.1", |
| 494 | Origin: " -0.1", |
| 495 | }, |
| 496 | }, |
| 497 | }, |
| 498 | { |
| 499 | YAML: `v: .inf`, |
| 500 | Tokens: token.Tokens{ |
| 501 | { |
| 502 | Type: token.StringType, |
| 503 | CharacterType: token.CharacterTypeMiscellaneous, |
| 504 | Indicator: token.NotIndicator, |
| 505 | Value: "v", |
| 506 | Origin: "v", |
| 507 | }, |
| 508 | { |
| 509 | Type: token.MappingValueType, |
| 510 | CharacterType: token.CharacterTypeIndicator, |
| 511 | Indicator: token.BlockStructureIndicator, |
| 512 | Value: ":", |
| 513 | Origin: ":", |
| 514 | }, |
| 515 | { |
| 516 | Type: token.InfinityType, |
| 517 | CharacterType: token.CharacterTypeMiscellaneous, |
| 518 | Indicator: token.NotIndicator, |
| 519 | Value: ".inf", |
| 520 | Origin: " .inf", |
| 521 | }, |
| 522 | }, |
| 523 | }, |
| 524 | { |
| 525 | YAML: `v: -.inf`, |
| 526 | Tokens: token.Tokens{ |
| 527 | { |
| 528 | Type: token.StringType, |
| 529 | CharacterType: token.CharacterTypeMiscellaneous, |
| 530 | Indicator: token.NotIndicator, |
| 531 | Value: "v", |
| 532 | Origin: "v", |
| 533 | }, |
| 534 | { |
| 535 | Type: token.MappingValueType, |
| 536 | CharacterType: token.CharacterTypeIndicator, |
| 537 | Indicator: token.BlockStructureIndicator, |
| 538 | Value: ":", |
| 539 | Origin: ":", |
| 540 | }, |
| 541 | { |
| 542 | Type: token.InfinityType, |
| 543 | CharacterType: token.CharacterTypeMiscellaneous, |
| 544 | Indicator: token.NotIndicator, |
| 545 | Value: "-.inf", |
| 546 | Origin: " -.inf", |
| 547 | }, |
| 548 | }, |
| 549 | }, |
| 550 | { |
| 551 | YAML: `v: .nan`, |
| 552 | Tokens: token.Tokens{ |
| 553 | { |
| 554 | Type: token.StringType, |
| 555 | CharacterType: token.CharacterTypeMiscellaneous, |
| 556 | Indicator: token.NotIndicator, |
| 557 | Value: "v", |
| 558 | Origin: "v", |
| 559 | }, |
| 560 | { |
| 561 | Type: token.MappingValueType, |
| 562 | CharacterType: token.CharacterTypeIndicator, |
| 563 | Indicator: token.BlockStructureIndicator, |
| 564 | Value: ":", |
| 565 | Origin: ":", |
| 566 | }, |
| 567 | { |
| 568 | Type: token.NanType, |
| 569 | CharacterType: token.CharacterTypeMiscellaneous, |
| 570 | Indicator: token.NotIndicator, |
| 571 | Value: ".nan", |
| 572 | Origin: " .nan", |
| 573 | }, |
| 574 | }, |
| 575 | }, |
| 576 | { |
| 577 | YAML: ` |
| 578 | a: |
| 579 | "bbb \ |
| 580 | ccc |
| 581 | |
| 582 | ddd eee\n\ |
| 583 | \ \ fff ggg\nhhh iii\n |
| 584 | jjj kkk |
| 585 | " |
| 586 | `, |
| 587 | Tokens: token.Tokens{ |
| 588 | { |
| 589 | Type: token.StringType, |
| 590 | CharacterType: token.CharacterTypeMiscellaneous, |
| 591 | Indicator: token.NotIndicator, |
| 592 | Value: "a", |
| 593 | Origin: "\na", |
| 594 | }, |
| 595 | { |
| 596 | Type: token.MappingValueType, |
| 597 | CharacterType: token.CharacterTypeIndicator, |
| 598 | Indicator: token.BlockStructureIndicator, |
| 599 | Value: ":", |
| 600 | Origin: ":", |
| 601 | }, |
| 602 | { |
| 603 | Type: token.DoubleQuoteType, |
| 604 | CharacterType: token.CharacterTypeIndicator, |
| 605 | Indicator: token.QuotedScalarIndicator, |
| 606 | Value: "bbb ccc\nddd eee\n fff ggg\nhhh iii\n jjj kkk ", |
| 607 | Origin: "\n \"bbb \\\n ccc\n\n ddd eee\\n\\\n \\ \\ fff ggg\\nhhh iii\\n\n jjj kkk\n \"", |
| 608 | }, |
| 609 | }, |
| 610 | }, |
| 611 | { |
| 612 | YAML: `v: null`, |
| 613 | Tokens: token.Tokens{ |
| 614 | { |
| 615 | Type: token.StringType, |
| 616 | CharacterType: token.CharacterTypeMiscellaneous, |
| 617 | Indicator: token.NotIndicator, |
| 618 | Value: "v", |
| 619 | Origin: "v", |
| 620 | }, |
| 621 | { |
| 622 | Type: token.MappingValueType, |
| 623 | CharacterType: token.CharacterTypeIndicator, |
| 624 | Indicator: token.BlockStructureIndicator, |
| 625 | Value: ":", |
| 626 | Origin: ":", |
| 627 | }, |
| 628 | { |
| 629 | Type: token.NullType, |
| 630 | CharacterType: token.CharacterTypeMiscellaneous, |
| 631 | Indicator: token.NotIndicator, |
| 632 | Value: "null", |
| 633 | Origin: " null", |
| 634 | }, |
| 635 | }, |
| 636 | }, |
| 637 | { |
| 638 | YAML: `v: ""`, |
| 639 | Tokens: token.Tokens{ |
| 640 | { |
| 641 | Type: token.StringType, |
| 642 | CharacterType: token.CharacterTypeMiscellaneous, |
| 643 | Indicator: token.NotIndicator, |
| 644 | Value: "v", |
| 645 | Origin: "v", |
| 646 | }, |
| 647 | { |
| 648 | Type: token.MappingValueType, |
| 649 | CharacterType: token.CharacterTypeIndicator, |
| 650 | Indicator: token.BlockStructureIndicator, |
| 651 | Value: ":", |
| 652 | Origin: ":", |
| 653 | }, |
| 654 | { |
| 655 | Type: token.DoubleQuoteType, |
| 656 | CharacterType: token.CharacterTypeIndicator, |
| 657 | Indicator: token.QuotedScalarIndicator, |
| 658 | Value: "", |
| 659 | Origin: " \"\"", |
| 660 | }, |
| 661 | }, |
| 662 | }, |
| 663 | { |
| 664 | YAML: ` |
| 665 | v: |
| 666 | - A |
| 667 | - B |
| 668 | `, |
| 669 | Tokens: token.Tokens{ |
| 670 | { |
| 671 | Type: token.StringType, |
| 672 | CharacterType: token.CharacterTypeMiscellaneous, |
| 673 | Indicator: token.NotIndicator, |
| 674 | Value: "v", |
| 675 | Origin: "\nv", |
| 676 | }, |
| 677 | { |
| 678 | Type: token.MappingValueType, |
| 679 | CharacterType: token.CharacterTypeIndicator, |
| 680 | Indicator: token.BlockStructureIndicator, |
| 681 | Value: ":", |
| 682 | Origin: ":", |
| 683 | }, |
| 684 | { |
| 685 | Type: token.SequenceEntryType, |
| 686 | CharacterType: token.CharacterTypeIndicator, |
| 687 | Indicator: token.BlockStructureIndicator, |
| 688 | Value: "-", |
| 689 | Origin: "\n-", |
| 690 | }, |
| 691 | { |
| 692 | Type: token.StringType, |
| 693 | CharacterType: token.CharacterTypeMiscellaneous, |
| 694 | Indicator: token.NotIndicator, |
| 695 | Value: "A", |
| 696 | Origin: " A\n", |
| 697 | }, |
| 698 | { |
| 699 | Type: token.SequenceEntryType, |
| 700 | CharacterType: token.CharacterTypeIndicator, |
| 701 | Indicator: token.BlockStructureIndicator, |
| 702 | Value: "-", |
| 703 | Origin: "-", |
| 704 | }, |
| 705 | { |
| 706 | Type: token.StringType, |
| 707 | CharacterType: token.CharacterTypeMiscellaneous, |
| 708 | Indicator: token.NotIndicator, |
| 709 | Value: "B", |
| 710 | Origin: " B", |
| 711 | }, |
| 712 | }, |
| 713 | }, |
| 714 | { |
| 715 | YAML: ` |
| 716 | v: |
| 717 | - A |
| 718 | - |- |
| 719 | B |
| 720 | C |
| 721 | `, |
| 722 | Tokens: token.Tokens{ |
| 723 | { |
| 724 | Type: token.StringType, |
| 725 | CharacterType: token.CharacterTypeMiscellaneous, |
| 726 | Indicator: token.NotIndicator, |
| 727 | Value: "v", |
| 728 | Origin: "\nv", |
| 729 | }, |
| 730 | { |
| 731 | Type: token.MappingValueType, |
| 732 | CharacterType: token.CharacterTypeIndicator, |
| 733 | Indicator: token.BlockStructureIndicator, |
| 734 | Value: ":", |
| 735 | Origin: ":", |
| 736 | }, |
| 737 | { |
| 738 | Type: token.SequenceEntryType, |
| 739 | CharacterType: token.CharacterTypeIndicator, |
| 740 | Indicator: token.BlockStructureIndicator, |
| 741 | Value: "-", |
| 742 | Origin: "\n-", |
| 743 | }, |
| 744 | { |
| 745 | Type: token.StringType, |
| 746 | CharacterType: token.CharacterTypeMiscellaneous, |
| 747 | Indicator: token.NotIndicator, |
| 748 | Value: "A", |
| 749 | Origin: " A\n", |
| 750 | }, |
| 751 | { |
| 752 | Type: token.SequenceEntryType, |
| 753 | CharacterType: token.CharacterTypeIndicator, |
| 754 | Indicator: token.BlockStructureIndicator, |
| 755 | Value: "-", |
| 756 | Origin: "-", |
| 757 | }, |
| 758 | { |
| 759 | Type: token.LiteralType, |
| 760 | CharacterType: token.CharacterTypeIndicator, |
| 761 | Indicator: token.BlockScalarIndicator, |
| 762 | Value: "|-", |
| 763 | Origin: " |-\n", |
| 764 | }, |
| 765 | { |
| 766 | Type: token.StringType, |
| 767 | CharacterType: token.CharacterTypeMiscellaneous, |
| 768 | Indicator: token.NotIndicator, |
| 769 | Value: "B\nC", |
| 770 | Origin: " B\n C\n", |
| 771 | }, |
| 772 | }, |
| 773 | }, |
| 774 | { |
| 775 | YAML: ` |
| 776 | v: |
| 777 | - A |
| 778 | - 1 |
| 779 | - B: |
| 780 | - 2 |
| 781 | - 3 |
| 782 | `, |
| 783 | Tokens: token.Tokens{ |
| 784 | { |
| 785 | Type: token.StringType, |
| 786 | CharacterType: token.CharacterTypeMiscellaneous, |
| 787 | Indicator: token.NotIndicator, |
| 788 | Value: "v", |
| 789 | Origin: "\nv", |
| 790 | }, |
| 791 | { |
| 792 | Type: token.MappingValueType, |
| 793 | CharacterType: token.CharacterTypeIndicator, |
| 794 | Indicator: token.BlockStructureIndicator, |
| 795 | Value: ":", |
| 796 | Origin: ":", |
| 797 | }, |
| 798 | { |
| 799 | Type: token.SequenceEntryType, |
| 800 | CharacterType: token.CharacterTypeIndicator, |
| 801 | Indicator: token.BlockStructureIndicator, |
| 802 | Value: "-", |
| 803 | Origin: "\n-", |
| 804 | }, |
| 805 | { |
| 806 | Type: token.StringType, |
| 807 | CharacterType: token.CharacterTypeMiscellaneous, |
| 808 | Indicator: token.NotIndicator, |
| 809 | Value: "A", |
| 810 | Origin: " A\n", |
| 811 | }, |
| 812 | { |
| 813 | Type: token.SequenceEntryType, |
| 814 | CharacterType: token.CharacterTypeIndicator, |
| 815 | Indicator: token.BlockStructureIndicator, |
| 816 | Value: "-", |
| 817 | Origin: "-", |
| 818 | }, |
| 819 | { |
| 820 | Type: token.IntegerType, |
| 821 | CharacterType: token.CharacterTypeMiscellaneous, |
| 822 | Indicator: token.NotIndicator, |
| 823 | Value: "1", |
| 824 | Origin: " 1\n", |
| 825 | }, |
| 826 | { |
| 827 | Type: token.SequenceEntryType, |
| 828 | CharacterType: token.CharacterTypeIndicator, |
| 829 | Indicator: token.BlockStructureIndicator, |
| 830 | Value: "-", |
| 831 | Origin: "-", |
| 832 | }, |
| 833 | { |
| 834 | Type: token.StringType, |
| 835 | CharacterType: token.CharacterTypeMiscellaneous, |
| 836 | Indicator: token.NotIndicator, |
| 837 | Value: "B", |
| 838 | Origin: " B", |
| 839 | }, |
| 840 | { |
| 841 | Type: token.MappingValueType, |
| 842 | CharacterType: token.CharacterTypeIndicator, |
| 843 | Indicator: token.BlockStructureIndicator, |
| 844 | Value: ":", |
| 845 | Origin: ":", |
| 846 | }, |
| 847 | { |
| 848 | Type: token.SequenceEntryType, |
| 849 | CharacterType: token.CharacterTypeIndicator, |
| 850 | Indicator: token.BlockStructureIndicator, |
| 851 | Value: "-", |
| 852 | Origin: "\n -", |
| 853 | }, |
| 854 | { |
| 855 | Type: token.IntegerType, |
| 856 | CharacterType: token.CharacterTypeMiscellaneous, |
| 857 | Indicator: token.NotIndicator, |
| 858 | Value: "2", |
| 859 | Origin: " 2\n ", |
| 860 | }, |
| 861 | { |
| 862 | Type: token.SequenceEntryType, |
| 863 | CharacterType: token.CharacterTypeIndicator, |
| 864 | Indicator: token.BlockStructureIndicator, |
| 865 | Value: "-", |
| 866 | Origin: "-", |
| 867 | }, |
| 868 | { |
| 869 | Type: token.IntegerType, |
| 870 | CharacterType: token.CharacterTypeMiscellaneous, |
| 871 | Indicator: token.NotIndicator, |
| 872 | Value: "3", |
| 873 | Origin: " 3", |
| 874 | }, |
| 875 | }, |
| 876 | }, |
| 877 | { |
| 878 | YAML: ` |
| 879 | a: |
| 880 | b: c |
| 881 | `, |
| 882 | Tokens: token.Tokens{ |
| 883 | { |
| 884 | Type: token.StringType, |
| 885 | CharacterType: token.CharacterTypeMiscellaneous, |
| 886 | Indicator: token.NotIndicator, |
| 887 | Value: "a", |
| 888 | Origin: "\na", |
| 889 | }, |
| 890 | { |
| 891 | Type: token.MappingValueType, |
| 892 | CharacterType: token.CharacterTypeIndicator, |
| 893 | Indicator: token.BlockStructureIndicator, |
| 894 | Value: ":", |
| 895 | Origin: ":", |
| 896 | }, |
| 897 | { |
| 898 | Type: token.StringType, |
| 899 | CharacterType: token.CharacterTypeMiscellaneous, |
| 900 | Indicator: token.NotIndicator, |
| 901 | Value: "b", |
| 902 | Origin: "\n b", |
| 903 | }, |
| 904 | { |
| 905 | Type: token.MappingValueType, |
| 906 | CharacterType: token.CharacterTypeIndicator, |
| 907 | Indicator: token.BlockStructureIndicator, |
| 908 | Value: ":", |
| 909 | Origin: ":", |
| 910 | }, |
| 911 | { |
| 912 | Type: token.StringType, |
| 913 | CharacterType: token.CharacterTypeMiscellaneous, |
| 914 | Indicator: token.NotIndicator, |
| 915 | Value: "c", |
| 916 | Origin: " c", |
| 917 | }, |
| 918 | }, |
| 919 | }, |
| 920 | { |
| 921 | YAML: `a: '-'`, |
| 922 | Tokens: token.Tokens{ |
| 923 | { |
| 924 | Type: token.StringType, |
| 925 | CharacterType: token.CharacterTypeMiscellaneous, |
| 926 | Indicator: token.NotIndicator, |
| 927 | Value: "a", |
| 928 | Origin: "a", |
| 929 | }, |
| 930 | { |
| 931 | Type: token.MappingValueType, |
| 932 | CharacterType: token.CharacterTypeIndicator, |
| 933 | Indicator: token.BlockStructureIndicator, |
| 934 | Value: ":", |
| 935 | Origin: ":", |
| 936 | }, |
| 937 | { |
| 938 | Type: token.SingleQuoteType, |
| 939 | CharacterType: token.CharacterTypeIndicator, |
| 940 | Indicator: token.QuotedScalarIndicator, |
| 941 | Value: "-", |
| 942 | Origin: " '-'", |
| 943 | }, |
| 944 | }, |
| 945 | }, |
| 946 | { |
| 947 | YAML: `123`, |
| 948 | Tokens: token.Tokens{ |
| 949 | { |
| 950 | Type: token.IntegerType, |
| 951 | CharacterType: token.CharacterTypeMiscellaneous, |
| 952 | Indicator: token.NotIndicator, |
| 953 | Value: "123", |
| 954 | Origin: "123", |
| 955 | }, |
| 956 | }, |
| 957 | }, |
| 958 | { |
| 959 | YAML: `hello: world |
| 960 | `, |
| 961 | Tokens: token.Tokens{ |
| 962 | { |
| 963 | Type: token.StringType, |
| 964 | CharacterType: token.CharacterTypeMiscellaneous, |
| 965 | Indicator: token.NotIndicator, |
| 966 | Value: "hello", |
| 967 | Origin: "hello", |
| 968 | }, |
| 969 | { |
| 970 | Type: token.MappingValueType, |
| 971 | CharacterType: token.CharacterTypeIndicator, |
| 972 | Indicator: token.BlockStructureIndicator, |
| 973 | Value: ":", |
| 974 | Origin: ":", |
| 975 | }, |
| 976 | { |
| 977 | Type: token.StringType, |
| 978 | CharacterType: token.CharacterTypeMiscellaneous, |
| 979 | Indicator: token.NotIndicator, |
| 980 | Value: "world", |
| 981 | Origin: " world", |
| 982 | }, |
| 983 | }, |
| 984 | }, |
| 985 | { |
| 986 | YAML: `a: null`, |
| 987 | Tokens: token.Tokens{ |
| 988 | { |
| 989 | Type: token.StringType, |
| 990 | CharacterType: token.CharacterTypeMiscellaneous, |
| 991 | Indicator: token.NotIndicator, |
| 992 | Value: "a", |
| 993 | Origin: "a", |
| 994 | }, |
| 995 | { |
| 996 | Type: token.MappingValueType, |
| 997 | CharacterType: token.CharacterTypeIndicator, |
| 998 | Indicator: token.BlockStructureIndicator, |
| 999 | Value: ":", |
| 1000 | Origin: ":", |
| 1001 | }, |
| 1002 | { |
| 1003 | Type: token.NullType, |
| 1004 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1005 | Indicator: token.NotIndicator, |
| 1006 | Value: "null", |
| 1007 | Origin: " null", |
| 1008 | }, |
| 1009 | }, |
| 1010 | }, |
| 1011 | { |
| 1012 | YAML: `a: {x: 1}`, |
| 1013 | Tokens: token.Tokens{ |
| 1014 | { |
| 1015 | Type: token.StringType, |
| 1016 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1017 | Indicator: token.NotIndicator, |
| 1018 | Value: "a", |
| 1019 | Origin: "a", |
| 1020 | }, |
| 1021 | { |
| 1022 | Type: token.MappingValueType, |
| 1023 | CharacterType: token.CharacterTypeIndicator, |
| 1024 | Indicator: token.BlockStructureIndicator, |
| 1025 | Value: ":", |
| 1026 | Origin: ":", |
| 1027 | }, |
| 1028 | { |
| 1029 | Type: token.MappingStartType, |
| 1030 | CharacterType: token.CharacterTypeIndicator, |
| 1031 | Indicator: token.FlowCollectionIndicator, |
| 1032 | Value: "{", |
| 1033 | Origin: " {", |
| 1034 | }, |
| 1035 | { |
| 1036 | Type: token.StringType, |
| 1037 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1038 | Indicator: token.NotIndicator, |
| 1039 | Value: "x", |
| 1040 | Origin: "x", |
| 1041 | }, |
| 1042 | { |
| 1043 | Type: token.MappingValueType, |
| 1044 | CharacterType: token.CharacterTypeIndicator, |
| 1045 | Indicator: token.BlockStructureIndicator, |
| 1046 | Value: ":", |
| 1047 | Origin: ":", |
| 1048 | }, |
| 1049 | { |
| 1050 | Type: token.IntegerType, |
| 1051 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1052 | Indicator: token.NotIndicator, |
| 1053 | Value: "1", |
| 1054 | Origin: " 1", |
| 1055 | }, |
| 1056 | { |
| 1057 | Type: token.MappingEndType, |
| 1058 | CharacterType: token.CharacterTypeIndicator, |
| 1059 | Indicator: token.FlowCollectionIndicator, |
| 1060 | Value: "}", |
| 1061 | Origin: "}", |
| 1062 | }, |
| 1063 | }, |
| 1064 | }, |
| 1065 | { |
| 1066 | YAML: `a: [1, 2]`, |
| 1067 | Tokens: token.Tokens{ |
| 1068 | { |
| 1069 | Type: token.StringType, |
| 1070 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1071 | Indicator: token.NotIndicator, |
| 1072 | Value: "a", |
| 1073 | Origin: "a", |
| 1074 | }, |
| 1075 | { |
| 1076 | Type: token.MappingValueType, |
| 1077 | CharacterType: token.CharacterTypeIndicator, |
| 1078 | Indicator: token.BlockStructureIndicator, |
| 1079 | Value: ":", |
| 1080 | Origin: ":", |
| 1081 | }, |
| 1082 | { |
| 1083 | Type: token.SequenceStartType, |
| 1084 | CharacterType: token.CharacterTypeIndicator, |
| 1085 | Indicator: token.FlowCollectionIndicator, |
| 1086 | Value: "[", |
| 1087 | Origin: " [", |
| 1088 | }, |
| 1089 | { |
| 1090 | Type: token.IntegerType, |
| 1091 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1092 | Indicator: token.NotIndicator, |
| 1093 | Value: "1", |
| 1094 | Origin: "1", |
| 1095 | }, |
| 1096 | { |
| 1097 | Type: token.CollectEntryType, |
| 1098 | CharacterType: token.CharacterTypeIndicator, |
| 1099 | Indicator: token.FlowCollectionIndicator, |
| 1100 | Value: ",", |
| 1101 | Origin: ",", |
| 1102 | }, |
| 1103 | { |
| 1104 | Type: token.IntegerType, |
| 1105 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1106 | Indicator: token.NotIndicator, |
| 1107 | Value: "2", |
| 1108 | Origin: " 2", |
| 1109 | }, |
| 1110 | { |
| 1111 | Type: token.SequenceEndType, |
| 1112 | CharacterType: token.CharacterTypeIndicator, |
| 1113 | Indicator: token.FlowCollectionIndicator, |
| 1114 | Value: "]", |
| 1115 | Origin: "]", |
| 1116 | }, |
| 1117 | }, |
| 1118 | }, |
| 1119 | { |
| 1120 | YAML: ` |
| 1121 | t2: 2018-01-09T10:40:47Z |
| 1122 | t4: 2098-01-09T10:40:47Z |
| 1123 | `, |
| 1124 | Tokens: token.Tokens{ |
| 1125 | { |
| 1126 | Type: token.StringType, |
| 1127 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1128 | Indicator: token.NotIndicator, |
| 1129 | Value: "t2", |
| 1130 | Origin: "\nt2", |
| 1131 | }, |
| 1132 | { |
| 1133 | Type: token.MappingValueType, |
| 1134 | CharacterType: token.CharacterTypeIndicator, |
| 1135 | Indicator: token.BlockStructureIndicator, |
| 1136 | Value: ":", |
| 1137 | Origin: ":", |
| 1138 | }, |
| 1139 | { |
| 1140 | Type: token.StringType, |
| 1141 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1142 | Indicator: token.NotIndicator, |
| 1143 | Value: "2018-01-09T10:40:47Z", |
| 1144 | Origin: " 2018-01-09T10:40:47Z\n", |
| 1145 | }, |
| 1146 | { |
| 1147 | Type: token.StringType, |
| 1148 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1149 | Indicator: token.NotIndicator, |
| 1150 | Value: "t4", |
| 1151 | Origin: "t4", |
| 1152 | }, |
| 1153 | { |
| 1154 | Type: token.MappingValueType, |
| 1155 | CharacterType: token.CharacterTypeIndicator, |
| 1156 | Indicator: token.BlockStructureIndicator, |
| 1157 | Value: ":", |
| 1158 | Origin: ":", |
| 1159 | }, |
| 1160 | { |
| 1161 | Type: token.StringType, |
| 1162 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1163 | Indicator: token.NotIndicator, |
| 1164 | Value: "2098-01-09T10:40:47Z", |
| 1165 | Origin: " 2098-01-09T10:40:47Z", |
| 1166 | }, |
| 1167 | }, |
| 1168 | }, |
| 1169 | { |
| 1170 | YAML: `a: {b: c, d: e}`, |
| 1171 | Tokens: token.Tokens{ |
| 1172 | { |
| 1173 | Type: token.StringType, |
| 1174 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1175 | Indicator: token.NotIndicator, |
| 1176 | Value: "a", |
| 1177 | Origin: "a", |
| 1178 | }, |
| 1179 | { |
| 1180 | Type: token.MappingValueType, |
| 1181 | CharacterType: token.CharacterTypeIndicator, |
| 1182 | Indicator: token.BlockStructureIndicator, |
| 1183 | Value: ":", |
| 1184 | Origin: ":", |
| 1185 | }, |
| 1186 | { |
| 1187 | Type: token.MappingStartType, |
| 1188 | CharacterType: token.CharacterTypeIndicator, |
| 1189 | Indicator: token.FlowCollectionIndicator, |
| 1190 | Value: "{", |
| 1191 | Origin: " {", |
| 1192 | }, |
| 1193 | { |
| 1194 | Type: token.StringType, |
| 1195 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1196 | Indicator: token.NotIndicator, |
| 1197 | Value: "b", |
| 1198 | Origin: "b", |
| 1199 | }, |
| 1200 | { |
| 1201 | Type: token.MappingValueType, |
| 1202 | CharacterType: token.CharacterTypeIndicator, |
| 1203 | Indicator: token.BlockStructureIndicator, |
| 1204 | Value: ":", |
| 1205 | Origin: ":", |
| 1206 | }, |
| 1207 | { |
| 1208 | Type: token.StringType, |
| 1209 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1210 | Indicator: token.NotIndicator, |
| 1211 | Value: "c", |
| 1212 | Origin: " c", |
| 1213 | }, |
| 1214 | { |
| 1215 | Type: token.CollectEntryType, |
| 1216 | CharacterType: token.CharacterTypeIndicator, |
| 1217 | Indicator: token.FlowCollectionIndicator, |
| 1218 | Value: ",", |
| 1219 | Origin: ",", |
| 1220 | }, |
| 1221 | { |
| 1222 | Type: token.StringType, |
| 1223 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1224 | Indicator: token.NotIndicator, |
| 1225 | Value: "d", |
| 1226 | Origin: " d", |
| 1227 | }, |
| 1228 | { |
| 1229 | Type: token.MappingValueType, |
| 1230 | CharacterType: token.CharacterTypeIndicator, |
| 1231 | Indicator: token.BlockStructureIndicator, |
| 1232 | Value: ":", |
| 1233 | Origin: ":", |
| 1234 | }, |
| 1235 | { |
| 1236 | Type: token.StringType, |
| 1237 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1238 | Indicator: token.NotIndicator, |
| 1239 | Value: "e", |
| 1240 | Origin: " e", |
| 1241 | }, |
| 1242 | { |
| 1243 | Type: token.MappingEndType, |
| 1244 | CharacterType: token.CharacterTypeIndicator, |
| 1245 | Indicator: token.FlowCollectionIndicator, |
| 1246 | Value: "}", |
| 1247 | Origin: "}", |
| 1248 | }, |
| 1249 | }, |
| 1250 | }, |
| 1251 | { |
| 1252 | YAML: `a: 3s`, |
| 1253 | Tokens: token.Tokens{ |
| 1254 | { |
| 1255 | Type: token.StringType, |
| 1256 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1257 | Indicator: token.NotIndicator, |
| 1258 | Value: "a", |
| 1259 | Origin: "a", |
| 1260 | }, |
| 1261 | { |
| 1262 | Type: token.MappingValueType, |
| 1263 | CharacterType: token.CharacterTypeIndicator, |
| 1264 | Indicator: token.BlockStructureIndicator, |
| 1265 | Value: ":", |
| 1266 | Origin: ":", |
| 1267 | }, |
| 1268 | { |
| 1269 | Type: token.StringType, |
| 1270 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1271 | Indicator: token.NotIndicator, |
| 1272 | Value: "3s", |
| 1273 | Origin: " 3s", |
| 1274 | }, |
| 1275 | }, |
| 1276 | }, |
| 1277 | { |
| 1278 | YAML: `a: <foo>`, |
| 1279 | Tokens: token.Tokens{ |
| 1280 | { |
| 1281 | Type: token.StringType, |
| 1282 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1283 | Indicator: token.NotIndicator, |
| 1284 | Value: "a", |
| 1285 | Origin: "a", |
| 1286 | }, |
| 1287 | { |
| 1288 | Type: token.MappingValueType, |
| 1289 | CharacterType: token.CharacterTypeIndicator, |
| 1290 | Indicator: token.BlockStructureIndicator, |
| 1291 | Value: ":", |
| 1292 | Origin: ":", |
| 1293 | }, |
| 1294 | { |
| 1295 | Type: token.StringType, |
| 1296 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1297 | Indicator: token.NotIndicator, |
| 1298 | Value: "<foo>", |
| 1299 | Origin: " <foo>", |
| 1300 | }, |
| 1301 | }, |
| 1302 | }, |
| 1303 | { |
| 1304 | YAML: `a: "1:1"`, |
| 1305 | Tokens: token.Tokens{ |
| 1306 | { |
| 1307 | Type: token.StringType, |
| 1308 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1309 | Indicator: token.NotIndicator, |
| 1310 | Value: "a", |
| 1311 | Origin: "a", |
| 1312 | }, |
| 1313 | { |
| 1314 | Type: token.MappingValueType, |
| 1315 | CharacterType: token.CharacterTypeIndicator, |
| 1316 | Indicator: token.BlockStructureIndicator, |
| 1317 | Value: ":", |
| 1318 | Origin: ":", |
| 1319 | }, |
| 1320 | { |
| 1321 | Type: token.DoubleQuoteType, |
| 1322 | CharacterType: token.CharacterTypeIndicator, |
| 1323 | Indicator: token.QuotedScalarIndicator, |
| 1324 | Value: "1:1", |
| 1325 | Origin: " \"1:1\"", |
| 1326 | }, |
| 1327 | }, |
| 1328 | }, |
| 1329 | { |
| 1330 | YAML: `a: "\0"`, |
| 1331 | Tokens: token.Tokens{ |
| 1332 | { |
| 1333 | Type: token.StringType, |
| 1334 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1335 | Indicator: token.NotIndicator, |
| 1336 | Value: "a", |
| 1337 | Origin: "a", |
| 1338 | }, |
| 1339 | { |
| 1340 | Type: token.MappingValueType, |
| 1341 | CharacterType: token.CharacterTypeIndicator, |
| 1342 | Indicator: token.BlockStructureIndicator, |
| 1343 | Value: ":", |
| 1344 | Origin: ":", |
| 1345 | }, |
| 1346 | { |
| 1347 | Type: token.DoubleQuoteType, |
| 1348 | CharacterType: token.CharacterTypeIndicator, |
| 1349 | Indicator: token.QuotedScalarIndicator, |
| 1350 | Value: "\x00", |
| 1351 | Origin: " \"\\0\"", |
| 1352 | }, |
| 1353 | }, |
| 1354 | }, |
| 1355 | { |
| 1356 | YAML: `a: !!binary gIGC`, |
| 1357 | Tokens: token.Tokens{ |
| 1358 | { |
| 1359 | Type: token.StringType, |
| 1360 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1361 | Indicator: token.NotIndicator, |
| 1362 | Value: "a", |
| 1363 | Origin: "a", |
| 1364 | }, |
| 1365 | { |
| 1366 | Type: token.MappingValueType, |
| 1367 | CharacterType: token.CharacterTypeIndicator, |
| 1368 | Indicator: token.BlockStructureIndicator, |
| 1369 | Value: ":", |
| 1370 | Origin: ":", |
| 1371 | }, |
| 1372 | { |
| 1373 | Type: token.TagType, |
| 1374 | CharacterType: token.CharacterTypeIndicator, |
| 1375 | Indicator: token.NodePropertyIndicator, |
| 1376 | Value: "!!binary", |
| 1377 | Origin: " !!binary ", |
| 1378 | }, |
| 1379 | { |
| 1380 | Type: token.StringType, |
| 1381 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1382 | Indicator: token.NotIndicator, |
| 1383 | Value: "gIGC", |
| 1384 | Origin: "gIGC", |
| 1385 | }, |
| 1386 | }, |
| 1387 | }, |
| 1388 | { |
| 1389 | YAML: ` |
| 1390 | a: !!binary | |
| 1391 | kJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJ |
| 1392 | CQ |
| 1393 | `, |
| 1394 | Tokens: token.Tokens{ |
| 1395 | { |
| 1396 | Type: token.StringType, |
| 1397 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1398 | Indicator: token.NotIndicator, |
| 1399 | Value: "a", |
| 1400 | Origin: "\na", |
| 1401 | }, |
| 1402 | { |
| 1403 | Type: token.MappingValueType, |
| 1404 | CharacterType: token.CharacterTypeIndicator, |
| 1405 | Indicator: token.BlockStructureIndicator, |
| 1406 | Value: ":", |
| 1407 | Origin: ":", |
| 1408 | }, |
| 1409 | { |
| 1410 | Type: token.TagType, |
| 1411 | CharacterType: token.CharacterTypeIndicator, |
| 1412 | Indicator: token.NodePropertyIndicator, |
| 1413 | Value: "!!binary", |
| 1414 | Origin: " !!binary ", |
| 1415 | }, |
| 1416 | { |
| 1417 | Type: token.LiteralType, |
| 1418 | CharacterType: token.CharacterTypeIndicator, |
| 1419 | Indicator: token.BlockScalarIndicator, |
| 1420 | Value: "|", |
| 1421 | Origin: "|\n", |
| 1422 | }, |
| 1423 | { |
| 1424 | Type: token.StringType, |
| 1425 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1426 | Indicator: token.NotIndicator, |
| 1427 | Value: "kJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJ\nCQ\n", |
| 1428 | Origin: " kJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJ\n CQ\n", |
| 1429 | }, |
| 1430 | }, |
| 1431 | }, |
| 1432 | { |
| 1433 | YAML: ` |
| 1434 | b: 2 |
| 1435 | a: 1 |
| 1436 | d: 4 |
| 1437 | c: 3 |
| 1438 | sub: |
| 1439 | e: 5 |
| 1440 | `, |
| 1441 | Tokens: token.Tokens{ |
| 1442 | { |
| 1443 | Type: token.StringType, |
| 1444 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1445 | Indicator: token.NotIndicator, |
| 1446 | Value: "b", |
| 1447 | Origin: "\nb", |
| 1448 | }, |
| 1449 | { |
| 1450 | Type: token.MappingValueType, |
| 1451 | CharacterType: token.CharacterTypeIndicator, |
| 1452 | Indicator: token.BlockStructureIndicator, |
| 1453 | Value: ":", |
| 1454 | Origin: ":", |
| 1455 | }, |
| 1456 | { |
| 1457 | Type: token.IntegerType, |
| 1458 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1459 | Indicator: token.NotIndicator, |
| 1460 | Value: "2", |
| 1461 | Origin: " 2\n", |
| 1462 | }, |
| 1463 | { |
| 1464 | Type: token.StringType, |
| 1465 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1466 | Indicator: token.NotIndicator, |
| 1467 | Value: "a", |
| 1468 | Origin: "a", |
| 1469 | }, |
| 1470 | { |
| 1471 | Type: token.MappingValueType, |
| 1472 | CharacterType: token.CharacterTypeIndicator, |
| 1473 | Indicator: token.BlockStructureIndicator, |
| 1474 | Value: ":", |
| 1475 | Origin: ":", |
| 1476 | }, |
| 1477 | { |
| 1478 | Type: token.IntegerType, |
| 1479 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1480 | Indicator: token.NotIndicator, |
| 1481 | Value: "1", |
| 1482 | Origin: " 1\n", |
| 1483 | }, |
| 1484 | { |
| 1485 | Type: token.StringType, |
| 1486 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1487 | Indicator: token.NotIndicator, |
| 1488 | Value: "d", |
| 1489 | Origin: "d", |
| 1490 | }, |
| 1491 | { |
| 1492 | Type: token.MappingValueType, |
| 1493 | CharacterType: token.CharacterTypeIndicator, |
| 1494 | Indicator: token.BlockStructureIndicator, |
| 1495 | Value: ":", |
| 1496 | Origin: ":", |
| 1497 | }, |
| 1498 | { |
| 1499 | Type: token.IntegerType, |
| 1500 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1501 | Indicator: token.NotIndicator, |
| 1502 | Value: "4", |
| 1503 | Origin: " 4\n", |
| 1504 | }, |
| 1505 | { |
| 1506 | Type: token.StringType, |
| 1507 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1508 | Indicator: token.NotIndicator, |
| 1509 | Value: "c", |
| 1510 | Origin: "c", |
| 1511 | }, |
| 1512 | { |
| 1513 | Type: token.MappingValueType, |
| 1514 | CharacterType: token.CharacterTypeIndicator, |
| 1515 | Indicator: token.BlockStructureIndicator, |
| 1516 | Value: ":", |
| 1517 | Origin: ":", |
| 1518 | }, |
| 1519 | { |
| 1520 | Type: token.IntegerType, |
| 1521 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1522 | Indicator: token.NotIndicator, |
| 1523 | Value: "3", |
| 1524 | Origin: " 3\n", |
| 1525 | }, |
| 1526 | { |
| 1527 | Type: token.StringType, |
| 1528 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1529 | Indicator: token.NotIndicator, |
| 1530 | Value: "sub", |
| 1531 | Origin: "sub", |
| 1532 | }, |
| 1533 | { |
| 1534 | Type: token.MappingValueType, |
| 1535 | CharacterType: token.CharacterTypeIndicator, |
| 1536 | Indicator: token.BlockStructureIndicator, |
| 1537 | Value: ":", |
| 1538 | Origin: ":", |
| 1539 | }, |
| 1540 | { |
| 1541 | Type: token.StringType, |
| 1542 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1543 | Indicator: token.NotIndicator, |
| 1544 | Value: "e", |
| 1545 | Origin: "\n e", |
| 1546 | }, |
| 1547 | { |
| 1548 | Type: token.MappingValueType, |
| 1549 | CharacterType: token.CharacterTypeIndicator, |
| 1550 | Indicator: token.BlockStructureIndicator, |
| 1551 | Value: ":", |
| 1552 | Origin: ":", |
| 1553 | }, |
| 1554 | { |
| 1555 | Type: token.IntegerType, |
| 1556 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1557 | Indicator: token.NotIndicator, |
| 1558 | Value: "5", |
| 1559 | Origin: " 5", |
| 1560 | }, |
| 1561 | }, |
| 1562 | }, |
| 1563 | { |
| 1564 | YAML: `a: 1.2.3.4`, |
| 1565 | Tokens: token.Tokens{ |
| 1566 | { |
| 1567 | Type: token.StringType, |
| 1568 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1569 | Indicator: token.NotIndicator, |
| 1570 | Value: "a", |
| 1571 | Origin: "a", |
| 1572 | }, |
| 1573 | { |
| 1574 | Type: token.MappingValueType, |
| 1575 | CharacterType: token.CharacterTypeIndicator, |
| 1576 | Indicator: token.BlockStructureIndicator, |
| 1577 | Value: ":", |
| 1578 | Origin: ":", |
| 1579 | }, |
| 1580 | { |
| 1581 | Type: token.StringType, |
| 1582 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1583 | Indicator: token.NotIndicator, |
| 1584 | Value: "1.2.3.4", |
| 1585 | Origin: " 1.2.3.4", |
| 1586 | }, |
| 1587 | }, |
| 1588 | }, |
| 1589 | { |
| 1590 | YAML: `a: "2015-02-24T18:19:39Z"`, |
| 1591 | Tokens: token.Tokens{ |
| 1592 | { |
| 1593 | Type: token.StringType, |
| 1594 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1595 | Indicator: token.NotIndicator, |
| 1596 | Value: "a", |
| 1597 | Origin: "a", |
| 1598 | }, |
| 1599 | { |
| 1600 | Type: token.MappingValueType, |
| 1601 | CharacterType: token.CharacterTypeIndicator, |
| 1602 | Indicator: token.BlockStructureIndicator, |
| 1603 | Value: ":", |
| 1604 | Origin: ":", |
| 1605 | }, |
| 1606 | { |
| 1607 | Type: token.DoubleQuoteType, |
| 1608 | CharacterType: token.CharacterTypeIndicator, |
| 1609 | Indicator: token.QuotedScalarIndicator, |
| 1610 | Value: "2015-02-24T18:19:39Z", |
| 1611 | Origin: " \"2015-02-24T18:19:39Z\"", |
| 1612 | }, |
| 1613 | }, |
| 1614 | }, |
| 1615 | { |
| 1616 | YAML: `a: 'b: c'`, |
| 1617 | Tokens: token.Tokens{ |
| 1618 | { |
| 1619 | Type: token.StringType, |
| 1620 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1621 | Indicator: token.NotIndicator, |
| 1622 | Value: "a", |
| 1623 | Origin: "a", |
| 1624 | }, |
| 1625 | { |
| 1626 | Type: token.MappingValueType, |
| 1627 | CharacterType: token.CharacterTypeIndicator, |
| 1628 | Indicator: token.BlockStructureIndicator, |
| 1629 | Value: ":", |
| 1630 | Origin: ":", |
| 1631 | }, |
| 1632 | { |
| 1633 | Type: token.SingleQuoteType, |
| 1634 | CharacterType: token.CharacterTypeIndicator, |
| 1635 | Indicator: token.QuotedScalarIndicator, |
| 1636 | Value: "b: c", |
| 1637 | Origin: " 'b: c'", |
| 1638 | }, |
| 1639 | }, |
| 1640 | }, |
| 1641 | { |
| 1642 | YAML: `a: 'Hello #comment'`, |
| 1643 | Tokens: token.Tokens{ |
| 1644 | { |
| 1645 | Type: token.StringType, |
| 1646 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1647 | Indicator: token.NotIndicator, |
| 1648 | Value: "a", |
| 1649 | Origin: "a", |
| 1650 | }, |
| 1651 | { |
| 1652 | Type: token.MappingValueType, |
| 1653 | CharacterType: token.CharacterTypeIndicator, |
| 1654 | Indicator: token.BlockStructureIndicator, |
| 1655 | Value: ":", |
| 1656 | Origin: ":", |
| 1657 | }, |
| 1658 | { |
| 1659 | Type: token.SingleQuoteType, |
| 1660 | CharacterType: token.CharacterTypeIndicator, |
| 1661 | Indicator: token.QuotedScalarIndicator, |
| 1662 | Value: "Hello #comment", |
| 1663 | Origin: " 'Hello #comment'", |
| 1664 | }, |
| 1665 | }, |
| 1666 | }, |
| 1667 | { |
| 1668 | YAML: `a: 100.5`, |
| 1669 | Tokens: token.Tokens{ |
| 1670 | { |
| 1671 | Type: token.StringType, |
| 1672 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1673 | Indicator: token.NotIndicator, |
| 1674 | Value: "a", |
| 1675 | Origin: "a", |
| 1676 | }, |
| 1677 | { |
| 1678 | Type: token.MappingValueType, |
| 1679 | CharacterType: token.CharacterTypeIndicator, |
| 1680 | Indicator: token.BlockStructureIndicator, |
| 1681 | Value: ":", |
| 1682 | Origin: ":", |
| 1683 | }, |
| 1684 | { |
| 1685 | Type: token.FloatType, |
| 1686 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1687 | Indicator: token.NotIndicator, |
| 1688 | Value: "100.5", |
| 1689 | Origin: " 100.5", |
| 1690 | }, |
| 1691 | }, |
| 1692 | }, |
| 1693 | { |
| 1694 | YAML: `a: bogus`, |
| 1695 | Tokens: token.Tokens{ |
| 1696 | { |
| 1697 | Type: token.StringType, |
| 1698 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1699 | Indicator: token.NotIndicator, |
| 1700 | Value: "a", |
| 1701 | Origin: "a", |
| 1702 | }, |
| 1703 | { |
| 1704 | Type: token.MappingValueType, |
| 1705 | CharacterType: token.CharacterTypeIndicator, |
| 1706 | Indicator: token.BlockStructureIndicator, |
| 1707 | Value: ":", |
| 1708 | Origin: ":", |
| 1709 | }, |
| 1710 | { |
| 1711 | Type: token.StringType, |
| 1712 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1713 | Indicator: token.NotIndicator, |
| 1714 | Value: "bogus", |
| 1715 | Origin: " bogus", |
| 1716 | }, |
| 1717 | }, |
| 1718 | }, |
| 1719 | { |
| 1720 | YAML: `"a": double quoted map key`, |
| 1721 | Tokens: token.Tokens{ |
| 1722 | { |
| 1723 | Type: token.DoubleQuoteType, |
| 1724 | CharacterType: token.CharacterTypeIndicator, |
| 1725 | Indicator: token.QuotedScalarIndicator, |
| 1726 | Value: "a", |
| 1727 | Origin: "\"a\"", |
| 1728 | }, |
| 1729 | { |
| 1730 | Type: token.MappingValueType, |
| 1731 | CharacterType: token.CharacterTypeIndicator, |
| 1732 | Indicator: token.BlockStructureIndicator, |
| 1733 | Value: ":", |
| 1734 | Origin: ":", |
| 1735 | }, |
| 1736 | { |
| 1737 | Type: token.StringType, |
| 1738 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1739 | Indicator: token.NotIndicator, |
| 1740 | Value: "double quoted map key", |
| 1741 | Origin: " double quoted map key", |
| 1742 | }, |
| 1743 | }, |
| 1744 | }, |
| 1745 | { |
| 1746 | YAML: `'a': single quoted map key`, |
| 1747 | Tokens: token.Tokens{ |
| 1748 | { |
| 1749 | Type: token.SingleQuoteType, |
| 1750 | CharacterType: token.CharacterTypeIndicator, |
| 1751 | Indicator: token.QuotedScalarIndicator, |
| 1752 | Value: "a", |
| 1753 | Origin: "'a'", |
| 1754 | }, |
| 1755 | { |
| 1756 | Type: token.MappingValueType, |
| 1757 | CharacterType: token.CharacterTypeIndicator, |
| 1758 | Indicator: token.BlockStructureIndicator, |
| 1759 | Value: ":", |
| 1760 | Origin: ":", |
| 1761 | }, |
| 1762 | { |
| 1763 | Type: token.StringType, |
| 1764 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1765 | Indicator: token.NotIndicator, |
| 1766 | Value: "single quoted map key", |
| 1767 | Origin: " single quoted map key", |
| 1768 | }, |
| 1769 | }, |
| 1770 | }, |
| 1771 | { |
| 1772 | YAML: ` |
| 1773 | a: "double quoted" |
| 1774 | b: "value map"`, |
| 1775 | Tokens: token.Tokens{ |
| 1776 | { |
| 1777 | Type: token.StringType, |
| 1778 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1779 | Indicator: token.NotIndicator, |
| 1780 | Value: "a", |
| 1781 | Origin: "\na", |
| 1782 | }, |
| 1783 | { |
| 1784 | Type: token.MappingValueType, |
| 1785 | CharacterType: token.CharacterTypeIndicator, |
| 1786 | Indicator: token.BlockStructureIndicator, |
| 1787 | Value: ":", |
| 1788 | Origin: ":", |
| 1789 | }, |
| 1790 | { |
| 1791 | Type: token.DoubleQuoteType, |
| 1792 | CharacterType: token.CharacterTypeIndicator, |
| 1793 | Indicator: token.QuotedScalarIndicator, |
| 1794 | Value: "double quoted", |
| 1795 | Origin: " \"double quoted\"", |
| 1796 | }, |
| 1797 | { |
| 1798 | Type: token.StringType, |
| 1799 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1800 | Indicator: token.NotIndicator, |
| 1801 | Value: "b", |
| 1802 | Origin: "\nb", |
| 1803 | }, |
| 1804 | { |
| 1805 | Type: token.MappingValueType, |
| 1806 | CharacterType: token.CharacterTypeIndicator, |
| 1807 | Indicator: token.BlockStructureIndicator, |
| 1808 | Value: ":", |
| 1809 | Origin: ":", |
| 1810 | }, |
| 1811 | { |
| 1812 | Type: token.DoubleQuoteType, |
| 1813 | CharacterType: token.CharacterTypeIndicator, |
| 1814 | Indicator: token.QuotedScalarIndicator, |
| 1815 | Value: "value map", |
| 1816 | Origin: " \"value map\"", |
| 1817 | }, |
| 1818 | }, |
| 1819 | }, |
| 1820 | { |
| 1821 | YAML: ` |
| 1822 | a: 'single quoted' |
| 1823 | b: 'value map'`, |
| 1824 | Tokens: token.Tokens{ |
| 1825 | { |
| 1826 | Type: token.StringType, |
| 1827 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1828 | Indicator: token.NotIndicator, |
| 1829 | Value: "a", |
| 1830 | Origin: "\na", |
| 1831 | }, |
| 1832 | { |
| 1833 | Type: token.MappingValueType, |
| 1834 | CharacterType: token.CharacterTypeIndicator, |
| 1835 | Indicator: token.BlockStructureIndicator, |
| 1836 | Value: ":", |
| 1837 | Origin: ":", |
| 1838 | }, |
| 1839 | { |
| 1840 | Type: token.SingleQuoteType, |
| 1841 | CharacterType: token.CharacterTypeIndicator, |
| 1842 | Indicator: token.QuotedScalarIndicator, |
| 1843 | Value: "single quoted", |
| 1844 | Origin: " 'single quoted'", |
| 1845 | }, |
| 1846 | { |
| 1847 | Type: token.StringType, |
| 1848 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1849 | Indicator: token.NotIndicator, |
| 1850 | Value: "b", |
| 1851 | Origin: "\nb", |
| 1852 | }, |
| 1853 | { |
| 1854 | Type: token.MappingValueType, |
| 1855 | CharacterType: token.CharacterTypeIndicator, |
| 1856 | Indicator: token.BlockStructureIndicator, |
| 1857 | Value: ":", |
| 1858 | Origin: ":", |
| 1859 | }, |
| 1860 | { |
| 1861 | Type: token.SingleQuoteType, |
| 1862 | CharacterType: token.CharacterTypeIndicator, |
| 1863 | Indicator: token.QuotedScalarIndicator, |
| 1864 | Value: "value map", |
| 1865 | Origin: " 'value map'", |
| 1866 | }, |
| 1867 | }, |
| 1868 | }, |
| 1869 | { |
| 1870 | YAML: `json: '\"expression\": \"thi:\"'`, |
| 1871 | Tokens: token.Tokens{ |
| 1872 | { |
| 1873 | Type: token.StringType, |
| 1874 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1875 | Indicator: token.NotIndicator, |
| 1876 | Value: "json", |
| 1877 | Origin: "json", |
| 1878 | }, |
| 1879 | { |
| 1880 | Type: token.MappingValueType, |
| 1881 | CharacterType: token.CharacterTypeIndicator, |
| 1882 | Indicator: token.BlockStructureIndicator, |
| 1883 | Value: ":", |
| 1884 | Origin: ":", |
| 1885 | }, |
| 1886 | { |
| 1887 | Type: token.SingleQuoteType, |
| 1888 | CharacterType: token.CharacterTypeIndicator, |
| 1889 | Indicator: token.QuotedScalarIndicator, |
| 1890 | Value: "\\\"expression\\\": \\\"thi:\\\"", |
| 1891 | Origin: " '\\\"expression\\\": \\\"thi:\\\"'", |
| 1892 | }, |
| 1893 | }, |
| 1894 | }, |
| 1895 | { |
| 1896 | YAML: `json: "\"expression\": \"thi:\""`, |
| 1897 | Tokens: token.Tokens{ |
| 1898 | { |
| 1899 | Type: token.StringType, |
| 1900 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1901 | Indicator: token.NotIndicator, |
| 1902 | Value: "json", |
| 1903 | Origin: "json", |
| 1904 | }, |
| 1905 | { |
| 1906 | Type: token.MappingValueType, |
| 1907 | CharacterType: token.CharacterTypeIndicator, |
| 1908 | Indicator: token.BlockStructureIndicator, |
| 1909 | Value: ":", |
| 1910 | Origin: ":", |
| 1911 | }, |
| 1912 | { |
| 1913 | Type: token.DoubleQuoteType, |
| 1914 | CharacterType: token.CharacterTypeIndicator, |
| 1915 | Indicator: token.QuotedScalarIndicator, |
| 1916 | Value: "\"expression\": \"thi:\"", |
| 1917 | Origin: " \"\\\"expression\\\": \\\"thi:\\\"\"", |
| 1918 | }, |
| 1919 | }, |
| 1920 | }, |
| 1921 | { |
| 1922 | YAML: ` |
| 1923 | a: |
| 1924 | b |
| 1925 | |
| 1926 | c |
| 1927 | `, |
| 1928 | Tokens: token.Tokens{ |
| 1929 | { |
| 1930 | Type: token.StringType, |
| 1931 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1932 | Indicator: token.NotIndicator, |
| 1933 | Value: "a", |
| 1934 | Origin: "\na", |
| 1935 | }, |
| 1936 | { |
| 1937 | Type: token.MappingValueType, |
| 1938 | CharacterType: token.CharacterTypeIndicator, |
| 1939 | Indicator: token.BlockStructureIndicator, |
| 1940 | Value: ":", |
| 1941 | Origin: ":", |
| 1942 | }, |
| 1943 | { |
| 1944 | Type: token.StringType, |
| 1945 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1946 | Indicator: token.NotIndicator, |
| 1947 | Value: "b\nc", |
| 1948 | Origin: "\n b\n\n c", |
| 1949 | }, |
| 1950 | }, |
| 1951 | }, |
| 1952 | { |
| 1953 | YAML: ` |
| 1954 | a: |
| 1955 | b |
| 1956 | |
| 1957 | |
| 1958 | c |
| 1959 | d |
| 1960 | e: f |
| 1961 | `, |
| 1962 | Tokens: token.Tokens{ |
| 1963 | { |
| 1964 | Type: token.StringType, |
| 1965 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1966 | Indicator: token.NotIndicator, |
| 1967 | Value: "a", |
| 1968 | Origin: "\na", |
| 1969 | }, |
| 1970 | { |
| 1971 | Type: token.MappingValueType, |
| 1972 | CharacterType: token.CharacterTypeIndicator, |
| 1973 | Indicator: token.BlockStructureIndicator, |
| 1974 | Value: ":", |
| 1975 | Origin: ":", |
| 1976 | }, |
| 1977 | { |
| 1978 | Type: token.StringType, |
| 1979 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1980 | Indicator: token.NotIndicator, |
| 1981 | Value: "b\nc d", |
| 1982 | Origin: "\n b\n\n\n c\n d\n", |
| 1983 | }, |
| 1984 | { |
| 1985 | Type: token.StringType, |
| 1986 | CharacterType: token.CharacterTypeMiscellaneous, |
| 1987 | Indicator: token.NotIndicator, |
| 1988 | Value: "e", |
| 1989 | Origin: "e", |
| 1990 | }, |
| 1991 | { |
| 1992 | Type: token.MappingValueType, |
| 1993 | CharacterType: token.CharacterTypeIndicator, |
| 1994 | Indicator: token.BlockStructureIndicator, |
| 1995 | Value: ":", |
| 1996 | Origin: ":", |
| 1997 | }, |
| 1998 | { |
| 1999 | Type: token.StringType, |
| 2000 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2001 | Indicator: token.NotIndicator, |
| 2002 | Value: "f", |
| 2003 | Origin: " f", |
| 2004 | }, |
| 2005 | }, |
| 2006 | }, |
| 2007 | { |
| 2008 | YAML: ` |
| 2009 | a: | |
| 2010 | b |
| 2011 | |
| 2012 | |
| 2013 | c |
| 2014 | d |
| 2015 | e: f |
| 2016 | `, |
| 2017 | Tokens: token.Tokens{ |
| 2018 | { |
| 2019 | Type: token.StringType, |
| 2020 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2021 | Indicator: token.NotIndicator, |
| 2022 | Value: "a", |
| 2023 | Origin: "\na", |
| 2024 | }, |
| 2025 | { |
| 2026 | Type: token.MappingValueType, |
| 2027 | CharacterType: token.CharacterTypeIndicator, |
| 2028 | Indicator: token.BlockStructureIndicator, |
| 2029 | Value: ":", |
| 2030 | Origin: ":", |
| 2031 | }, |
| 2032 | { |
| 2033 | Type: token.LiteralType, |
| 2034 | CharacterType: token.CharacterTypeIndicator, |
| 2035 | Indicator: token.BlockScalarIndicator, |
| 2036 | Value: "|", |
| 2037 | Origin: " |\n", |
| 2038 | }, |
| 2039 | { |
| 2040 | Type: token.StringType, |
| 2041 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2042 | Indicator: token.NotIndicator, |
| 2043 | Value: "b \n\n \nc\nd \n", |
| 2044 | Origin: " b \n\n \n c\n d \n", |
| 2045 | }, |
| 2046 | { |
| 2047 | Type: token.StringType, |
| 2048 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2049 | Indicator: token.NotIndicator, |
| 2050 | Value: "e", |
| 2051 | Origin: "e", |
| 2052 | }, |
| 2053 | { |
| 2054 | Type: token.MappingValueType, |
| 2055 | CharacterType: token.CharacterTypeIndicator, |
| 2056 | Indicator: token.BlockStructureIndicator, |
| 2057 | Value: ":", |
| 2058 | Origin: ":", |
| 2059 | }, |
| 2060 | { |
| 2061 | Type: token.StringType, |
| 2062 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2063 | Indicator: token.NotIndicator, |
| 2064 | Value: "f", |
| 2065 | Origin: " f", |
| 2066 | }, |
| 2067 | }, |
| 2068 | }, |
| 2069 | { |
| 2070 | YAML: ` |
| 2071 | a: > |
| 2072 | b |
| 2073 | |
| 2074 | |
| 2075 | c |
| 2076 | d |
| 2077 | e: f |
| 2078 | `, |
| 2079 | Tokens: token.Tokens{ |
| 2080 | { |
| 2081 | Type: token.StringType, |
| 2082 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2083 | Indicator: token.NotIndicator, |
| 2084 | Value: "a", |
| 2085 | Origin: "\na", |
| 2086 | }, |
| 2087 | { |
| 2088 | Type: token.MappingValueType, |
| 2089 | CharacterType: token.CharacterTypeIndicator, |
| 2090 | Indicator: token.BlockStructureIndicator, |
| 2091 | Value: ":", |
| 2092 | Origin: ":", |
| 2093 | }, |
| 2094 | { |
| 2095 | Type: token.FoldedType, |
| 2096 | CharacterType: token.CharacterTypeIndicator, |
| 2097 | Indicator: token.BlockScalarIndicator, |
| 2098 | Value: ">", |
| 2099 | Origin: " >\n", |
| 2100 | }, |
| 2101 | { |
| 2102 | Type: token.StringType, |
| 2103 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2104 | Indicator: token.NotIndicator, |
| 2105 | Value: "b \n\n \nc d \n", |
| 2106 | Origin: " b \n\n \n c\n d \n", |
| 2107 | }, |
| 2108 | { |
| 2109 | Type: token.StringType, |
| 2110 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2111 | Indicator: token.NotIndicator, |
| 2112 | Value: "e", |
| 2113 | Origin: "e", |
| 2114 | }, |
| 2115 | { |
| 2116 | Type: token.MappingValueType, |
| 2117 | CharacterType: token.CharacterTypeIndicator, |
| 2118 | Indicator: token.BlockStructureIndicator, |
| 2119 | Value: ":", |
| 2120 | Origin: ":", |
| 2121 | }, |
| 2122 | { |
| 2123 | Type: token.StringType, |
| 2124 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2125 | Indicator: token.NotIndicator, |
| 2126 | Value: "f", |
| 2127 | Origin: " f", |
| 2128 | }, |
| 2129 | }, |
| 2130 | }, |
| 2131 | { |
| 2132 | YAML: ` |
| 2133 | a: > |
| 2134 | Text`, |
| 2135 | Tokens: token.Tokens{ |
| 2136 | { |
| 2137 | Type: token.StringType, |
| 2138 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2139 | Indicator: token.NotIndicator, |
| 2140 | Value: "a", |
| 2141 | Origin: "\na", |
| 2142 | }, |
| 2143 | { |
| 2144 | Type: token.MappingValueType, |
| 2145 | CharacterType: token.CharacterTypeIndicator, |
| 2146 | Indicator: token.BlockStructureIndicator, |
| 2147 | Value: ":", |
| 2148 | Origin: ":", |
| 2149 | }, |
| 2150 | { |
| 2151 | Type: token.FoldedType, |
| 2152 | CharacterType: token.CharacterTypeIndicator, |
| 2153 | Indicator: token.BlockScalarIndicator, |
| 2154 | Value: ">", |
| 2155 | Origin: " >\n", |
| 2156 | }, |
| 2157 | { |
| 2158 | Type: token.StringType, |
| 2159 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2160 | Indicator: token.NotIndicator, |
| 2161 | Value: "Text", |
| 2162 | Origin: " Text", |
| 2163 | }, |
| 2164 | }, |
| 2165 | }, |
| 2166 | { |
| 2167 | YAML: ` |
| 2168 | s: > |
| 2169 | 1s |
| 2170 | `, |
| 2171 | Tokens: token.Tokens{ |
| 2172 | { |
| 2173 | Type: token.StringType, |
| 2174 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2175 | Indicator: token.NotIndicator, |
| 2176 | Value: "s", |
| 2177 | Origin: "\ns", |
| 2178 | }, |
| 2179 | { |
| 2180 | Type: token.MappingValueType, |
| 2181 | CharacterType: token.CharacterTypeIndicator, |
| 2182 | Indicator: token.BlockStructureIndicator, |
| 2183 | Value: ":", |
| 2184 | Origin: ":", |
| 2185 | }, |
| 2186 | { |
| 2187 | Type: token.FoldedType, |
| 2188 | CharacterType: token.CharacterTypeIndicator, |
| 2189 | Indicator: token.BlockScalarIndicator, |
| 2190 | Value: ">", |
| 2191 | Origin: " >\n", |
| 2192 | }, |
| 2193 | { |
| 2194 | Type: token.StringType, |
| 2195 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2196 | Indicator: token.NotIndicator, |
| 2197 | Value: "1s\n", |
| 2198 | Origin: " 1s\n", |
| 2199 | }, |
| 2200 | }, |
| 2201 | }, |
| 2202 | { |
| 2203 | YAML: ` |
| 2204 | s: >1 # comment |
| 2205 | 1s |
| 2206 | `, |
| 2207 | Tokens: token.Tokens{ |
| 2208 | { |
| 2209 | Type: token.StringType, |
| 2210 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2211 | Indicator: token.NotIndicator, |
| 2212 | Value: "s", |
| 2213 | Origin: "\ns", |
| 2214 | }, |
| 2215 | { |
| 2216 | Type: token.MappingValueType, |
| 2217 | CharacterType: token.CharacterTypeIndicator, |
| 2218 | Indicator: token.BlockStructureIndicator, |
| 2219 | Value: ":", |
| 2220 | Origin: ":", |
| 2221 | }, |
| 2222 | { |
| 2223 | Type: token.FoldedType, |
| 2224 | CharacterType: token.CharacterTypeIndicator, |
| 2225 | Indicator: token.BlockScalarIndicator, |
| 2226 | Value: ">1", |
| 2227 | Origin: " >1 ", |
| 2228 | }, |
| 2229 | { |
| 2230 | Type: token.CommentType, |
| 2231 | CharacterType: token.CharacterTypeIndicator, |
| 2232 | Indicator: token.CommentIndicator, |
| 2233 | Value: " comment", |
| 2234 | Origin: "# comment\n", |
| 2235 | }, |
| 2236 | { |
| 2237 | Type: token.StringType, |
| 2238 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2239 | Indicator: token.NotIndicator, |
| 2240 | Value: " 1s\n", |
| 2241 | Origin: " 1s\n", |
| 2242 | }, |
| 2243 | }, |
| 2244 | }, |
| 2245 | { |
| 2246 | YAML: ` |
| 2247 | s: >+2 |
| 2248 | 1s |
| 2249 | `, |
| 2250 | Tokens: token.Tokens{ |
| 2251 | { |
| 2252 | Type: token.StringType, |
| 2253 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2254 | Indicator: token.NotIndicator, |
| 2255 | Value: "s", |
| 2256 | Origin: "\ns", |
| 2257 | }, |
| 2258 | { |
| 2259 | Type: token.MappingValueType, |
| 2260 | CharacterType: token.CharacterTypeIndicator, |
| 2261 | Indicator: token.BlockStructureIndicator, |
| 2262 | Value: ":", |
| 2263 | Origin: ":", |
| 2264 | }, |
| 2265 | { |
| 2266 | Type: token.FoldedType, |
| 2267 | CharacterType: token.CharacterTypeIndicator, |
| 2268 | Indicator: token.BlockScalarIndicator, |
| 2269 | Value: ">+2", |
| 2270 | Origin: " >+2\n", |
| 2271 | }, |
| 2272 | { |
| 2273 | Type: token.StringType, |
| 2274 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2275 | Indicator: token.NotIndicator, |
| 2276 | Value: " 1s\n", |
| 2277 | Origin: " 1s\n", |
| 2278 | }, |
| 2279 | }, |
| 2280 | }, |
| 2281 | { |
| 2282 | YAML: ` |
| 2283 | s: >-3 |
| 2284 | 1s |
| 2285 | `, |
| 2286 | Tokens: token.Tokens{ |
| 2287 | { |
| 2288 | Type: token.StringType, |
| 2289 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2290 | Indicator: token.NotIndicator, |
| 2291 | Value: "s", |
| 2292 | Origin: "\ns", |
| 2293 | }, |
| 2294 | { |
| 2295 | Type: token.MappingValueType, |
| 2296 | CharacterType: token.CharacterTypeIndicator, |
| 2297 | Indicator: token.BlockStructureIndicator, |
| 2298 | Value: ":", |
| 2299 | Origin: ":", |
| 2300 | }, |
| 2301 | { |
| 2302 | Type: token.FoldedType, |
| 2303 | CharacterType: token.CharacterTypeIndicator, |
| 2304 | Indicator: token.BlockScalarIndicator, |
| 2305 | Value: ">-3", |
| 2306 | Origin: " >-3\n", |
| 2307 | }, |
| 2308 | { |
| 2309 | Type: token.StringType, |
| 2310 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2311 | Indicator: token.NotIndicator, |
| 2312 | Value: " 1s", |
| 2313 | Origin: " 1s\n", |
| 2314 | }, |
| 2315 | }, |
| 2316 | }, |
| 2317 | { |
| 2318 | YAML: ` |
| 2319 | s: > |
| 2320 | 1s |
| 2321 | 2s |
| 2322 | `, |
| 2323 | Tokens: token.Tokens{ |
| 2324 | { |
| 2325 | Type: token.StringType, |
| 2326 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2327 | Indicator: token.NotIndicator, |
| 2328 | Value: "s", |
| 2329 | Origin: "\ns", |
| 2330 | }, |
| 2331 | { |
| 2332 | Type: token.MappingValueType, |
| 2333 | CharacterType: token.CharacterTypeIndicator, |
| 2334 | Indicator: token.BlockStructureIndicator, |
| 2335 | Value: ":", |
| 2336 | Origin: ":", |
| 2337 | }, |
| 2338 | { |
| 2339 | Type: token.FoldedType, |
| 2340 | CharacterType: token.CharacterTypeIndicator, |
| 2341 | Indicator: token.BlockScalarIndicator, |
| 2342 | Value: ">", |
| 2343 | Origin: " >\n", |
| 2344 | }, |
| 2345 | { |
| 2346 | Type: token.StringType, |
| 2347 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2348 | Indicator: token.NotIndicator, |
| 2349 | Value: "1s 2s\n", |
| 2350 | Origin: " 1s\n 2s\n", |
| 2351 | }, |
| 2352 | }, |
| 2353 | }, |
| 2354 | { |
| 2355 | YAML: ` |
| 2356 | s: > |
| 2357 | 1s |
| 2358 | 2s |
| 2359 | 3s |
| 2360 | `, |
| 2361 | Tokens: token.Tokens{ |
| 2362 | { |
| 2363 | Type: token.StringType, |
| 2364 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2365 | Indicator: token.NotIndicator, |
| 2366 | Value: "s", |
| 2367 | Origin: "\ns", |
| 2368 | }, |
| 2369 | { |
| 2370 | Type: token.MappingValueType, |
| 2371 | CharacterType: token.CharacterTypeIndicator, |
| 2372 | Indicator: token.BlockStructureIndicator, |
| 2373 | Value: ":", |
| 2374 | Origin: ":", |
| 2375 | }, |
| 2376 | { |
| 2377 | Type: token.FoldedType, |
| 2378 | CharacterType: token.CharacterTypeIndicator, |
| 2379 | Indicator: token.BlockScalarIndicator, |
| 2380 | Value: ">", |
| 2381 | Origin: " >\n", |
| 2382 | }, |
| 2383 | { |
| 2384 | Type: token.StringType, |
| 2385 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2386 | Indicator: token.NotIndicator, |
| 2387 | Value: "1s\n 2s\n3s\n", |
| 2388 | Origin: " 1s\n 2s\n 3s\n", |
| 2389 | }, |
| 2390 | }, |
| 2391 | }, |
| 2392 | { |
| 2393 | YAML: ` |
| 2394 | s: > |
| 2395 | 1s |
| 2396 | 2s |
| 2397 | 3s |
| 2398 | 4s |
| 2399 | 5s |
| 2400 | `, |
| 2401 | Tokens: token.Tokens{ |
| 2402 | { |
| 2403 | Type: token.StringType, |
| 2404 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2405 | Indicator: token.NotIndicator, |
| 2406 | Value: "s", |
| 2407 | Origin: "\ns", |
| 2408 | }, |
| 2409 | { |
| 2410 | Type: token.MappingValueType, |
| 2411 | CharacterType: token.CharacterTypeIndicator, |
| 2412 | Indicator: token.BlockStructureIndicator, |
| 2413 | Value: ":", |
| 2414 | Origin: ":", |
| 2415 | }, |
| 2416 | { |
| 2417 | Type: token.FoldedType, |
| 2418 | CharacterType: token.CharacterTypeIndicator, |
| 2419 | Indicator: token.BlockScalarIndicator, |
| 2420 | Value: ">", |
| 2421 | Origin: " >\n", |
| 2422 | }, |
| 2423 | { |
| 2424 | Type: token.StringType, |
| 2425 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2426 | Indicator: token.NotIndicator, |
| 2427 | Value: "1s\n 2s\n 3s\n4s 5s\n", |
| 2428 | Origin: " 1s\n 2s\n 3s\n 4s\n 5s\n", |
| 2429 | }, |
| 2430 | }, |
| 2431 | }, |
| 2432 | { |
| 2433 | YAML: ` |
| 2434 | s: >-3 |
| 2435 | 1s |
| 2436 | 2s |
| 2437 | 3s |
| 2438 | 4s |
| 2439 | 5s |
| 2440 | `, |
| 2441 | Tokens: token.Tokens{ |
| 2442 | { |
| 2443 | Type: token.StringType, |
| 2444 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2445 | Indicator: token.NotIndicator, |
| 2446 | Value: "s", |
| 2447 | Origin: "\ns", |
| 2448 | }, |
| 2449 | { |
| 2450 | Type: token.MappingValueType, |
| 2451 | CharacterType: token.CharacterTypeIndicator, |
| 2452 | Indicator: token.BlockStructureIndicator, |
| 2453 | Value: ":", |
| 2454 | Origin: ":", |
| 2455 | }, |
| 2456 | { |
| 2457 | Type: token.FoldedType, |
| 2458 | CharacterType: token.CharacterTypeIndicator, |
| 2459 | Indicator: token.BlockScalarIndicator, |
| 2460 | Value: ">-3", |
| 2461 | Origin: " >-3\n", |
| 2462 | }, |
| 2463 | { |
| 2464 | Type: token.StringType, |
| 2465 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2466 | Indicator: token.NotIndicator, |
| 2467 | Value: " 1s\n 2s\n 3s\n 4s\n 5s", |
| 2468 | Origin: " 1s\n 2s\n 3s\n 4s\n 5s\n", |
| 2469 | }, |
| 2470 | }, |
| 2471 | }, |
| 2472 | { |
| 2473 | YAML: ` |
| 2474 | |2- |
| 2475 | |
| 2476 | text |
| 2477 | `, |
| 2478 | Tokens: token.Tokens{ |
| 2479 | { |
| 2480 | Type: token.LiteralType, |
| 2481 | CharacterType: token.CharacterTypeIndicator, |
| 2482 | Indicator: token.BlockScalarIndicator, |
| 2483 | Value: "|2-", |
| 2484 | Origin: "\n|2-\n", |
| 2485 | }, |
| 2486 | { |
| 2487 | Type: token.StringType, |
| 2488 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2489 | Indicator: token.NotIndicator, |
| 2490 | Value: "\n text", |
| 2491 | Origin: "\n text\n", |
| 2492 | }, |
| 2493 | }, |
| 2494 | }, |
| 2495 | { |
| 2496 | YAML: ` |
| 2497 | | |
| 2498 | a |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | `, |
| 2503 | Tokens: token.Tokens{ |
| 2504 | { |
| 2505 | Type: token.LiteralType, |
| 2506 | CharacterType: token.CharacterTypeIndicator, |
| 2507 | Indicator: token.BlockScalarIndicator, |
| 2508 | Value: "|", |
| 2509 | Origin: "\n|\n", |
| 2510 | }, |
| 2511 | { |
| 2512 | Type: token.StringType, |
| 2513 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2514 | Indicator: token.NotIndicator, |
| 2515 | Value: "a\n", |
| 2516 | Origin: " a\n\n\n\n", |
| 2517 | }, |
| 2518 | }, |
| 2519 | }, |
| 2520 | { |
| 2521 | YAML: ` |
| 2522 | | # comment |
| 2523 | foo |
| 2524 | `, |
| 2525 | Tokens: token.Tokens{ |
| 2526 | { |
| 2527 | Type: token.LiteralType, |
| 2528 | CharacterType: token.CharacterTypeIndicator, |
| 2529 | Indicator: token.BlockScalarIndicator, |
| 2530 | Value: "|", |
| 2531 | Origin: "\n| ", |
| 2532 | }, |
| 2533 | { |
| 2534 | Type: token.CommentType, |
| 2535 | CharacterType: token.CharacterTypeIndicator, |
| 2536 | Indicator: token.CommentIndicator, |
| 2537 | Value: " comment", |
| 2538 | Origin: "# comment\n", |
| 2539 | }, |
| 2540 | { |
| 2541 | Type: token.StringType, |
| 2542 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2543 | Indicator: token.NotIndicator, |
| 2544 | Value: "foo\n", |
| 2545 | Origin: " foo\n", |
| 2546 | }, |
| 2547 | }, |
| 2548 | }, |
| 2549 | { |
| 2550 | YAML: `1x0`, |
| 2551 | Tokens: token.Tokens{ |
| 2552 | { |
| 2553 | Type: token.StringType, |
| 2554 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2555 | Indicator: token.NotIndicator, |
| 2556 | Value: "1x0", |
| 2557 | Origin: "1x0", |
| 2558 | }, |
| 2559 | }, |
| 2560 | }, |
| 2561 | { |
| 2562 | YAML: `0b98765`, |
| 2563 | Tokens: token.Tokens{ |
| 2564 | { |
| 2565 | Type: token.StringType, |
| 2566 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2567 | Indicator: token.NotIndicator, |
| 2568 | Value: "0b98765", |
| 2569 | Origin: "0b98765", |
| 2570 | }, |
| 2571 | }, |
| 2572 | }, |
| 2573 | { |
| 2574 | YAML: `098765`, |
| 2575 | Tokens: token.Tokens{ |
| 2576 | { |
| 2577 | Type: token.StringType, |
| 2578 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2579 | Indicator: token.NotIndicator, |
| 2580 | Value: "098765", |
| 2581 | Origin: "098765", |
| 2582 | }, |
| 2583 | }, |
| 2584 | }, |
| 2585 | { |
| 2586 | YAML: `0o98765`, |
| 2587 | Tokens: token.Tokens{ |
| 2588 | { |
| 2589 | Type: token.StringType, |
| 2590 | CharacterType: token.CharacterTypeMiscellaneous, |
| 2591 | Indicator: token.NotIndicator, |
| 2592 | Value: "0o98765", |
| 2593 | Origin: "0o98765", |
| 2594 | }, |
| 2595 | }, |
| 2596 | }, |
| 2597 | } |
| 2598 | for _, test := range tests { |
| 2599 | t.Run(test.YAML, func(t *testing.T) { |
| 2600 | tokens := lexer.Tokenize(test.YAML) |
| 2601 | if len(tokens) != len(test.Tokens) { |
| 2602 | t.Fatalf("Tokenize(%q) token count mismatch, expected: %d got: %d", test.YAML, len(test.Tokens), len(tokens)) |
| 2603 | } |
| 2604 | for i := range test.Tokens { |
| 2605 | if tokens[i].Type != test.Tokens[i].Type { |
| 2606 | t.Errorf("Tokenize(%q)[%d] token.Type mismatch, expected: %s got: %s", test.YAML, i, test.Tokens[i].Type, tokens[i].Type) |
| 2607 | } |
| 2608 | if tokens[i].CharacterType != test.Tokens[i].CharacterType { |
| 2609 | t.Errorf("Tokenize(%q)[%d] token.CharacterType mismatch, expected: %s got: %s", test.YAML, i, test.Tokens[i].CharacterType, tokens[i].CharacterType) |
| 2610 | } |
| 2611 | if tokens[i].Indicator != test.Tokens[i].Indicator { |
| 2612 | t.Errorf("Tokenize(%q)[%d] token.Indicator mismatch, expected: %s got: %s", test.YAML, i, test.Tokens[i].Indicator, tokens[i].Indicator) |
| 2613 | } |
| 2614 | if tokens[i].Value != test.Tokens[i].Value { |
| 2615 | t.Errorf("Tokenize(%q)[%d] token.Value mismatch, expected: %q got: %q", test.YAML, i, test.Tokens[i].Value, tokens[i].Value) |
| 2616 | } |
| 2617 | if tokens[i].Origin != test.Tokens[i].Origin { |
| 2618 | t.Errorf("Tokenize(%q)[%d] token.Origin mismatch, expected: %q got: %q", test.YAML, i, test.Tokens[i].Origin, tokens[i].Origin) |
| 2619 | } |
| 2620 | } |
| 2621 | }) |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | type testToken struct { |
| 2626 | line int |
| 2627 | column int |
| 2628 | value string |
| 2629 | } |
| 2630 | |
| 2631 | func TestSingleLineToken_ValueLineColumnPosition(t *testing.T) { |
| 2632 | tests := []struct { |
| 2633 | name string |
| 2634 | src string |
| 2635 | expect map[int]string // Column -> Value map. |
| 2636 | }{ |
| 2637 | { |
| 2638 | name: "single quote, single value array", |
| 2639 | src: "test: ['test']", |
| 2640 | expect: map[int]string{ |
| 2641 | 1: "test", |
| 2642 | 5: ":", |
| 2643 | 7: "[", |
| 2644 | 8: "test", |
| 2645 | 14: "]", |
| 2646 | }, |
| 2647 | }, |
| 2648 | { |
| 2649 | name: "double quote, single value array", |
| 2650 | src: `test: ["test"]`, |
| 2651 | expect: map[int]string{ |
| 2652 | 1: "test", |
| 2653 | 5: ":", |
| 2654 | 7: "[", |
| 2655 | 8: "test", |
| 2656 | 14: "]", |
| 2657 | }, |
| 2658 | }, |
| 2659 | { |
| 2660 | name: "no quotes, single value array", |
| 2661 | src: "test: [somevalue]", |
| 2662 | expect: map[int]string{ |
| 2663 | 1: "test", |
| 2664 | 5: ":", |
| 2665 | 7: "[", |
| 2666 | 8: "somevalue", |
| 2667 | 17: "]", |
| 2668 | }, |
| 2669 | }, |
| 2670 | { |
| 2671 | name: "single quote, multi value array", |
| 2672 | src: "myarr: ['1','2','3', '444' , '55','66' , '77' ]", |
| 2673 | expect: map[int]string{ |
| 2674 | 1: "myarr", |
| 2675 | 6: ":", |
| 2676 | 8: "[", |
| 2677 | 9: "1", |
| 2678 | 12: ",", |
| 2679 | 13: "2", |
| 2680 | 16: ",", |
| 2681 | 17: "3", |
| 2682 | 20: ",", |
| 2683 | 22: "444", |
| 2684 | 28: ",", |
| 2685 | 30: "55", |
| 2686 | 34: ",", |
| 2687 | 35: "66", |
| 2688 | 40: ",", |
| 2689 | 43: "77", |
| 2690 | 49: "]", |
| 2691 | }, |
| 2692 | }, |
| 2693 | { |
| 2694 | name: "double quote, multi value array", |
| 2695 | src: `myarr: ["1","2","3", "444" , "55","66" , "77" ]`, |
| 2696 | expect: map[int]string{ |
| 2697 | 1: "myarr", |
| 2698 | 6: ":", |
| 2699 | 8: "[", |
| 2700 | 9: "1", |
| 2701 | 12: ",", |
| 2702 | 13: "2", |
| 2703 | 16: ",", |
| 2704 | 17: "3", |
| 2705 | 20: ",", |
| 2706 | 22: "444", |
| 2707 | 28: ",", |
| 2708 | 30: "55", |
| 2709 | 34: ",", |
| 2710 | 35: "66", |
| 2711 | 40: ",", |
| 2712 | 43: "77", |
| 2713 | 49: "]", |
| 2714 | }, |
| 2715 | }, |
| 2716 | { |
| 2717 | name: "no quote, multi value array", |
| 2718 | src: "numbers: [1, 5, 99,100, 3, 7 ]", |
| 2719 | expect: map[int]string{ |
| 2720 | 1: "numbers", |
| 2721 | 8: ":", |
| 2722 | 10: "[", |
| 2723 | 11: "1", |
| 2724 | 12: ",", |
| 2725 | 14: "5", |
| 2726 | 15: ",", |
| 2727 | 17: "99", |
| 2728 | 19: ",", |
| 2729 | 20: "100", |
| 2730 | 23: ",", |
| 2731 | 25: "3", |
| 2732 | 26: ",", |
| 2733 | 28: "7", |
| 2734 | 30: "]", |
| 2735 | }, |
| 2736 | }, |
| 2737 | { |
| 2738 | name: "double quotes, nested arrays", |
| 2739 | src: `Strings: ["1",["2",["3"]]]`, |
| 2740 | expect: map[int]string{ |
| 2741 | 1: "Strings", |
| 2742 | 8: ":", |
| 2743 | 10: "[", |
| 2744 | 11: "1", |
| 2745 | 14: ",", |
| 2746 | 15: "[", |
| 2747 | 16: "2", |
| 2748 | 19: ",", |
| 2749 | 20: "[", |
| 2750 | 21: "3", |
| 2751 | 24: "]", |
| 2752 | 25: "]", |
| 2753 | 26: "]", |
| 2754 | }, |
| 2755 | }, |
| 2756 | { |
| 2757 | name: "mixed quotes, nested arrays", |
| 2758 | src: `Values: [1,['2',"3",4,["5",6]]]`, |
| 2759 | expect: map[int]string{ |
| 2760 | 1: "Values", |
| 2761 | 7: ":", |
| 2762 | 9: "[", |
| 2763 | 10: "1", |
| 2764 | 11: ",", |
| 2765 | 12: "[", |
| 2766 | 13: "2", |
| 2767 | 16: ",", |
| 2768 | 17: "3", |
| 2769 | 20: ",", |
| 2770 | 21: "4", |
| 2771 | 22: ",", |
| 2772 | 23: "[", |
| 2773 | 24: "5", |
| 2774 | 27: ",", |
| 2775 | 28: "6", |
| 2776 | 29: "]", |
| 2777 | 30: "]", |
| 2778 | 31: "]", |
| 2779 | }, |
| 2780 | }, |
| 2781 | { |
| 2782 | name: "double quote, empty array", |
| 2783 | src: `Empty: ["", ""]`, |
| 2784 | expect: map[int]string{ |
| 2785 | 1: "Empty", |
| 2786 | 6: ":", |
| 2787 | 8: "[", |
| 2788 | 9: "", |
| 2789 | 11: ",", |
| 2790 | 13: "", |
| 2791 | 15: "]", |
| 2792 | }, |
| 2793 | }, |
| 2794 | { |
| 2795 | name: "double quote key", |
| 2796 | src: `"a": b`, |
| 2797 | expect: map[int]string{ |
| 2798 | 1: "a", |
| 2799 | 4: ":", |
| 2800 | 6: "b", |
| 2801 | }, |
| 2802 | }, |
| 2803 | { |
| 2804 | name: "single quote key", |
| 2805 | src: `'a': b`, |
| 2806 | expect: map[int]string{ |
| 2807 | 1: "a", |
| 2808 | 4: ":", |
| 2809 | 6: "b", |
| 2810 | }, |
| 2811 | }, |
| 2812 | { |
| 2813 | name: "double quote key and value", |
| 2814 | src: `"a": "b"`, |
| 2815 | expect: map[int]string{ |
| 2816 | 1: "a", |
| 2817 | 4: ":", |
| 2818 | 6: "b", |
| 2819 | }, |
| 2820 | }, |
| 2821 | { |
| 2822 | name: "single quote key and value", |
| 2823 | src: `'a': 'b'`, |
| 2824 | expect: map[int]string{ |
| 2825 | 1: "a", |
| 2826 | 4: ":", |
| 2827 | 6: "b", |
| 2828 | }, |
| 2829 | }, |
| 2830 | { |
| 2831 | name: "double quote key, single quote value", |
| 2832 | src: `"a": 'b'`, |
| 2833 | expect: map[int]string{ |
| 2834 | 1: "a", |
| 2835 | 4: ":", |
| 2836 | 6: "b", |
| 2837 | }, |
| 2838 | }, |
| 2839 | { |
| 2840 | name: "single quote key, double quote value", |
| 2841 | src: `'a': "b"`, |
| 2842 | expect: map[int]string{ |
| 2843 | 1: "a", |
| 2844 | 4: ":", |
| 2845 | 6: "b", |
| 2846 | }, |
| 2847 | }, |
| 2848 | } |
| 2849 | |
| 2850 | for _, tc := range tests { |
| 2851 | t.Run(tc.name, func(t *testing.T) { |
| 2852 | got := lexer.Tokenize(tc.src) |
| 2853 | sort.Slice(got, func(i, j int) bool { |
| 2854 | return got[i].Position.Column < got[j].Position.Column |
| 2855 | }) |
| 2856 | var expected []testToken |
| 2857 | for k, v := range tc.expect { |
| 2858 | tt := testToken{ |
| 2859 | line: 1, |
| 2860 | column: k, |
| 2861 | value: v, |
| 2862 | } |
| 2863 | expected = append(expected, tt) |
| 2864 | } |
| 2865 | sort.Slice(expected, func(i, j int) bool { |
| 2866 | return expected[i].column < expected[j].column |
| 2867 | }) |
| 2868 | if len(got) != len(expected) { |
| 2869 | t.Errorf("Tokenize(%s) token count mismatch, expected:%d got:%d", tc.src, len(expected), len(got)) |
| 2870 | } |
| 2871 | for i, tok := range got { |
| 2872 | if !tokenMatches(tok, expected[i]) { |
| 2873 | t.Errorf("Tokenize(%s) expected:%+v got line:%d column:%d value:%s", tc.src, expected[i], tok.Position.Line, tok.Position.Column, tok.Value) |
| 2874 | } |
| 2875 | } |
| 2876 | }) |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | func tokenMatches(t *token.Token, e testToken) bool { |
| 2881 | return t != nil && t.Position != nil && |
| 2882 | t.Value == e.value && |
| 2883 | t.Position.Line == e.line && |
| 2884 | t.Position.Column == e.column |
| 2885 | } |
| 2886 | |
| 2887 | func TestMultiLineToken_ValueLineColumnPosition(t *testing.T) { |
| 2888 | tests := []struct { |
| 2889 | name string |
| 2890 | src string |
| 2891 | expect []testToken |
| 2892 | }{ |
| 2893 | { |
| 2894 | name: "double quote", |
| 2895 | src: `one: "1 2 3 4 5" |
| 2896 | two: "1 2 |
| 2897 | 3 4 |
| 2898 | 5" |
| 2899 | three: "1 2 3 4 |
| 2900 | 5"`, |
| 2901 | expect: []testToken{ |
| 2902 | { |
| 2903 | line: 1, |
| 2904 | column: 1, |
| 2905 | value: "one", |
| 2906 | }, |
| 2907 | { |
| 2908 | line: 1, |
| 2909 | column: 4, |
| 2910 | value: ":", |
| 2911 | }, |
| 2912 | { |
| 2913 | line: 1, |
| 2914 | column: 6, |
| 2915 | value: "1 2 3 4 5", |
| 2916 | }, |
| 2917 | { |
| 2918 | line: 2, |
| 2919 | column: 1, |
| 2920 | value: "two", |
| 2921 | }, |
| 2922 | { |
| 2923 | line: 2, |
| 2924 | column: 4, |
| 2925 | value: ":", |
| 2926 | }, |
| 2927 | { |
| 2928 | line: 2, |
| 2929 | column: 6, |
| 2930 | value: "1 2 3 4 5", |
| 2931 | }, |
| 2932 | { |
| 2933 | line: 5, |
| 2934 | column: 1, |
| 2935 | value: "three", |
| 2936 | }, |
| 2937 | { |
| 2938 | line: 5, |
| 2939 | column: 6, |
| 2940 | value: ":", |
| 2941 | }, |
| 2942 | { |
| 2943 | line: 5, |
| 2944 | column: 8, |
| 2945 | value: "1 2 3 4 5", |
| 2946 | }, |
| 2947 | }, |
| 2948 | }, |
| 2949 | { |
| 2950 | name: "single quote in an array", |
| 2951 | src: `arr: ['1', 'and |
| 2952 | two'] |
| 2953 | last: 'hello'`, |
| 2954 | expect: []testToken{ |
| 2955 | { |
| 2956 | line: 1, |
| 2957 | column: 1, |
| 2958 | value: "arr", |
| 2959 | }, |
| 2960 | { |
| 2961 | line: 1, |
| 2962 | column: 4, |
| 2963 | value: ":", |
| 2964 | }, |
| 2965 | { |
| 2966 | line: 1, |
| 2967 | column: 6, |
| 2968 | value: "[", |
| 2969 | }, |
| 2970 | { |
| 2971 | line: 1, |
| 2972 | column: 7, |
| 2973 | value: "1", |
| 2974 | }, |
| 2975 | { |
| 2976 | line: 1, |
| 2977 | column: 10, |
| 2978 | value: ",", |
| 2979 | }, |
| 2980 | { |
| 2981 | line: 1, |
| 2982 | column: 12, |
| 2983 | value: "and two", |
| 2984 | }, |
| 2985 | { |
| 2986 | line: 2, |
| 2987 | column: 5, |
| 2988 | value: "]", |
| 2989 | }, |
| 2990 | { |
| 2991 | line: 3, |
| 2992 | column: 1, |
| 2993 | value: "last", |
| 2994 | }, |
| 2995 | { |
| 2996 | line: 3, |
| 2997 | column: 5, |
| 2998 | value: ":", |
| 2999 | }, |
| 3000 | { |
| 3001 | line: 3, |
| 3002 | column: 7, |
| 3003 | value: "hello", |
| 3004 | }, |
| 3005 | }, |
| 3006 | }, |
| 3007 | { |
| 3008 | name: "single quote and double quote", |
| 3009 | src: `foo: "test |
| 3010 | |
| 3011 | |
| 3012 | |
| 3013 | |
| 3014 | bar" |
| 3015 | foo2: 'bar2'`, |
| 3016 | expect: []testToken{ |
| 3017 | { |
| 3018 | line: 1, |
| 3019 | column: 1, |
| 3020 | value: "foo", |
| 3021 | }, |
| 3022 | { |
| 3023 | line: 1, |
| 3024 | column: 4, |
| 3025 | value: ":", |
| 3026 | }, |
| 3027 | { |
| 3028 | line: 1, |
| 3029 | column: 6, |
| 3030 | value: "test\n\n\n\nbar", |
| 3031 | }, |
| 3032 | { |
| 3033 | line: 7, |
| 3034 | column: 1, |
| 3035 | value: "foo2", |
| 3036 | }, |
| 3037 | { |
| 3038 | line: 7, |
| 3039 | column: 5, |
| 3040 | value: ":", |
| 3041 | }, |
| 3042 | { |
| 3043 | line: 7, |
| 3044 | column: 7, |
| 3045 | value: "bar2", |
| 3046 | }, |
| 3047 | }, |
| 3048 | }, |
| 3049 | { |
| 3050 | name: "single and double quote map keys", |
| 3051 | src: `"a": test |
| 3052 | 'b': 1 |
| 3053 | c: true`, |
| 3054 | expect: []testToken{ |
| 3055 | { |
| 3056 | line: 1, |
| 3057 | column: 1, |
| 3058 | value: "a", |
| 3059 | }, |
| 3060 | { |
| 3061 | line: 1, |
| 3062 | column: 4, |
| 3063 | value: ":", |
| 3064 | }, |
| 3065 | { |
| 3066 | line: 1, |
| 3067 | column: 6, |
| 3068 | value: "test", |
| 3069 | }, |
| 3070 | { |
| 3071 | line: 2, |
| 3072 | column: 1, |
| 3073 | value: "b", |
| 3074 | }, |
| 3075 | { |
| 3076 | line: 2, |
| 3077 | column: 4, |
| 3078 | value: ":", |
| 3079 | }, |
| 3080 | { |
| 3081 | line: 2, |
| 3082 | column: 6, |
| 3083 | value: "1", |
| 3084 | }, |
| 3085 | { |
| 3086 | line: 3, |
| 3087 | column: 1, |
| 3088 | value: "c", |
| 3089 | }, |
| 3090 | { |
| 3091 | line: 3, |
| 3092 | column: 2, |
| 3093 | value: ":", |
| 3094 | }, |
| 3095 | { |
| 3096 | line: 3, |
| 3097 | column: 4, |
| 3098 | value: "true", |
| 3099 | }, |
| 3100 | }, |
| 3101 | }, |
| 3102 | { |
| 3103 | name: "issue326", |
| 3104 | src: `a: | |
| 3105 | Text |
| 3106 | b: 1`, |
| 3107 | expect: []testToken{ |
| 3108 | { |
| 3109 | line: 1, |
| 3110 | column: 1, |
| 3111 | value: "a", |
| 3112 | }, |
| 3113 | { |
| 3114 | line: 1, |
| 3115 | column: 2, |
| 3116 | value: ":", |
| 3117 | }, |
| 3118 | { |
| 3119 | line: 1, |
| 3120 | column: 4, |
| 3121 | value: "|", |
| 3122 | }, |
| 3123 | { |
| 3124 | line: 2, |
| 3125 | column: 3, |
| 3126 | value: "Text\n", |
| 3127 | }, |
| 3128 | { |
| 3129 | line: 3, |
| 3130 | column: 1, |
| 3131 | value: "b", |
| 3132 | }, |
| 3133 | { |
| 3134 | line: 3, |
| 3135 | column: 2, |
| 3136 | value: ":", |
| 3137 | }, |
| 3138 | { |
| 3139 | line: 3, |
| 3140 | column: 4, |
| 3141 | value: "1", |
| 3142 | }, |
| 3143 | }, |
| 3144 | }, |
| 3145 | } |
| 3146 | |
| 3147 | for _, tc := range tests { |
| 3148 | t.Run(tc.name, func(t *testing.T) { |
| 3149 | got := lexer.Tokenize(tc.src) |
| 3150 | sort.Slice(got, func(i, j int) bool { |
| 3151 | // sort by line, then column |
| 3152 | if got[i].Position.Line < got[j].Position.Line { |
| 3153 | return true |
| 3154 | } else if got[i].Position.Line == got[j].Position.Line { |
| 3155 | return got[i].Position.Column < got[j].Position.Column |
| 3156 | } |
| 3157 | return false |
| 3158 | }) |
| 3159 | sort.Slice(tc.expect, func(i, j int) bool { |
| 3160 | if tc.expect[i].line < tc.expect[j].line { |
| 3161 | return true |
| 3162 | } else if tc.expect[i].line == tc.expect[j].line { |
| 3163 | return tc.expect[i].column < tc.expect[j].column |
| 3164 | } |
| 3165 | return false |
| 3166 | }) |
| 3167 | if len(got) != len(tc.expect) { |
| 3168 | t.Errorf("Tokenize() token count mismatch, expected:%d got:%d", len(tc.expect), len(got)) |
| 3169 | } |
| 3170 | for i, tok := range got { |
| 3171 | if !tokenMatches(tok, tc.expect[i]) { |
| 3172 | t.Errorf("Tokenize() expected:%+v got line:%d column:%d value:%s", tc.expect[i], tok.Position.Line, tok.Position.Column, tok.Value) |
| 3173 | } |
| 3174 | } |
| 3175 | }) |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | func TestInvalid(t *testing.T) { |
| 3180 | tests := []struct { |
| 3181 | name string |
| 3182 | src string |
| 3183 | }{ |
| 3184 | { |
| 3185 | name: "literal opt with content", |
| 3186 | src: ` |
| 3187 | a: |invalid |
| 3188 | foo`, |
| 3189 | }, |
| 3190 | { |
| 3191 | name: "literal opt", |
| 3192 | src: ` |
| 3193 | a: |invalid`, |
| 3194 | }, |
| 3195 | { |
| 3196 | name: "invalid single-quoted", |
| 3197 | src: `a: 'foobarbaz`, |
| 3198 | }, |
| 3199 | { |
| 3200 | name: "invalid double-quoted", |
| 3201 | src: `a: "\"key\": \"value:\"`, |
| 3202 | }, |
| 3203 | { |
| 3204 | name: "invalid document folded", |
| 3205 | src: ">\n>", |
| 3206 | }, |
| 3207 | { |
| 3208 | name: "invalid document number", |
| 3209 | src: ">\n1", |
| 3210 | }, |
| 3211 | { |
| 3212 | name: "invalid document header option number", |
| 3213 | src: "a: >3\n 1", |
| 3214 | }, |
| 3215 | { |
| 3216 | name: "use reserved character @", |
| 3217 | src: "key: [@val]", |
| 3218 | }, |
| 3219 | { |
| 3220 | name: "use reserved character `", |
| 3221 | src: "key: [`val]", |
| 3222 | }, |
| 3223 | { |
| 3224 | name: "use tab character as indent", |
| 3225 | // nolint: gci |
| 3226 | src: " a: b", |
| 3227 | }, |
| 3228 | { |
| 3229 | name: "use tab character as indent in literal", |
| 3230 | src: ` |
| 3231 | a: | |
| 3232 | b |
| 3233 | c |
| 3234 | `, |
| 3235 | }, |
| 3236 | { |
| 3237 | name: "invalid UTF-16 character", |
| 3238 | src: `"\u00"`, |
| 3239 | }, |
| 3240 | { |
| 3241 | name: "invalid UTF-16 surrogate pair length", |
| 3242 | src: `"\ud800"`, |
| 3243 | }, |
| 3244 | { |
| 3245 | name: "invalid UTF-16 low surrogate prefix", |
| 3246 | src: `"\ud800\v"`, |
| 3247 | }, |
| 3248 | { |
| 3249 | name: "invalid UTF-16 low surrogate", |
| 3250 | src: `"\ud800\u0000"`, |
| 3251 | }, |
| 3252 | { |
| 3253 | name: "invalid UTF-32 character", |
| 3254 | src: `"\U0000"`, |
| 3255 | }, |
| 3256 | } |
| 3257 | for _, test := range tests { |
| 3258 | t.Run(test.name, func(t *testing.T) { |
| 3259 | got := lexer.Tokenize(test.src) |
| 3260 | if got.InvalidToken() == nil { |
| 3261 | t.Fatal("expected contains invalid token") |
| 3262 | } |
| 3263 | }) |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | func TestTokenOffset(t *testing.T) { |
| 3268 | t.Run("crlf", func(t *testing.T) { |
| 3269 | content := "project:\r\n version: 1.2.3\r\n" |
| 3270 | tokens := lexer.Tokenize(content) |
| 3271 | if len(tokens) != 5 { |
| 3272 | t.Fatalf("invalid token num. got %d", len(tokens)) |
| 3273 | } |
| 3274 | if tokens[4].Value != "1.2.3" { |
| 3275 | t.Fatalf("unexpected value. got %q", tokens[4].Value) |
| 3276 | } |
| 3277 | if tokens[4].Position.Offset != 22 { |
| 3278 | t.Fatalf("unexpected offset. got %d", tokens[4].Position.Offset) |
| 3279 | } |
| 3280 | }) |
| 3281 | t.Run("lf", func(t *testing.T) { |
| 3282 | content := "project:\n version: 1.2.3\n" |
| 3283 | tokens := lexer.Tokenize(content) |
| 3284 | if len(tokens) != 5 { |
| 3285 | t.Fatalf("invalid token num. got %d", len(tokens)) |
| 3286 | } |
| 3287 | if tokens[4].Value != "1.2.3" { |
| 3288 | t.Fatalf("unexpected value. got %q", tokens[4].Value) |
| 3289 | } |
| 3290 | if tokens[4].Position.Offset != 21 { |
| 3291 | t.Fatalf("unexpected offset. got %d", tokens[4].Position.Offset) |
| 3292 | } |
| 3293 | }) |
| 3294 | } |