MCPcopy
hub / github.com/hashicorp/hcl / TestTemplateExprIsStringLiteral

Function TestTemplateExprIsStringLiteral

hclsyntax/expression_template_test.go:463–502  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

461}
462
463func 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}

Callers

nothing calls this directly

Calls 4

ParseTemplateFunction · 0.85
RunMethod · 0.80
IsStringLiteralMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected