| 458 | } |
| 459 | |
| 460 | func TestUnmarshal(t *testing.T) { |
| 461 | type test struct { |
| 462 | target interface{} |
| 463 | expected interface{} |
| 464 | err bool |
| 465 | assert func(t *testing.T, test test) |
| 466 | } |
| 467 | examples := []struct { |
| 468 | skip bool |
| 469 | desc string |
| 470 | input string |
| 471 | gen func() test |
| 472 | }{ |
| 473 | { |
| 474 | desc: "kv string", |
| 475 | input: `A = "foo"`, |
| 476 | gen: func() test { |
| 477 | type doc struct { |
| 478 | A string |
| 479 | } |
| 480 | |
| 481 | return test{ |
| 482 | target: &doc{}, |
| 483 | expected: &doc{A: "foo"}, |
| 484 | } |
| 485 | }, |
| 486 | }, |
| 487 | { |
| 488 | desc: "kv literal string", |
| 489 | input: `A = 'foo 🙂 '`, |
| 490 | gen: func() test { |
| 491 | type doc struct { |
| 492 | A string |
| 493 | } |
| 494 | |
| 495 | return test{ |
| 496 | target: &doc{}, |
| 497 | expected: &doc{A: "foo 🙂 "}, |
| 498 | } |
| 499 | }, |
| 500 | }, |
| 501 | { |
| 502 | desc: "kv text key", |
| 503 | input: `a-1 = "foo"`, |
| 504 | gen: func() test { |
| 505 | type doc = map[unmarshalTextKey]string |
| 506 | |
| 507 | return test{ |
| 508 | target: &doc{}, |
| 509 | expected: &doc{{A: "a", B: "1"}: "foo"}, |
| 510 | } |
| 511 | }, |
| 512 | }, |
| 513 | { |
| 514 | desc: "table text key", |
| 515 | input: `["a-1"] |
| 516 | foo = "bar"`, |
| 517 | gen: func() test { |