(t *testing.T)
| 461 | } |
| 462 | |
| 463 | func TestTemplateExprIsStringLiteral(t *testing.T) { |
| 464 | tests := map[string]bool{ |
| 465 | // A simple string value is a string literal |
| 466 | "a": true, |
| 467 | |
| 468 | // Strings containing escape characters or escape sequences are |
| 469 | // tokenized into multiple string literals, but this should be |
| 470 | // corrected by the parser |
| 471 | "a$b": true, |
| 472 | "a%%b": true, |
| 473 | "a\nb": true, |
| 474 | "a$${\"b\"}": true, |
| 475 | |
| 476 | // Wrapped values (HIL-like) are not treated as string literals for |
| 477 | // legacy reasons |
| 478 | "${1}": false, |
| 479 | "${\"b\"}": false, |
| 480 | |
| 481 | // Even template expressions containing only literal values do not |
| 482 | // count as string literals |
| 483 | "a${1}": false, |
| 484 | "a${\"b\"}": false, |
| 485 | } |
| 486 | for input, want := range tests { |
| 487 | t.Run(input, func(t *testing.T) { |
| 488 | expr, diags := ParseTemplate([]byte(input), "", hcl.InitialPos) |
| 489 | if len(diags) != 0 { |
| 490 | t.Fatalf("unexpected diags: %s", diags.Error()) |
| 491 | } |
| 492 | |
| 493 | if tmplExpr, ok := expr.(*TemplateExpr); ok { |
| 494 | got := tmplExpr.IsStringLiteral() |
| 495 | |
| 496 | if got != want { |
| 497 | t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, want) |
| 498 | } |
| 499 | } |
| 500 | }) |
| 501 | } |
| 502 | } |
nothing calls this directly
no test coverage detected