-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
13249: fix(codegen/go): Use raw string literals for multiline-strings r=abhinav a=abhinav We already have logic in place to generate mutliline strings with backticks if they meet certain conditions in genTemplateExpression. However, the logic came into effect only if the string was complex enough to warrant use of `Sprintf` because the function short circuits to just printing a string literal if the string doesn't need a `Sprintf`. This changes genStringLiteral to be responsible for the decision of whether the string warrants backticks or not, retaining the prior conditions on whether the string would benefit from being split across multiple lines. Resolves #12358 13252: Freeze v3.73.0 r=Zaid-Ajaj a=Zaid-Ajaj Co-authored-by: Abhinav Gupta <abhinav@pulumi.com> Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
- Loading branch information
Showing
9 changed files
with
166 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.73.0 | ||
3.73.1 |
4 changes: 4 additions & 0 deletions
4
...pending/20230622--programgen-go--use-raw-string-literals-for-long-multi-line-strings.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
changes: | ||
- type: fix | ||
scope: programgen/go | ||
description: Use raw string literals for long, multi-line strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
pkg/codegen/testing/test/testdata/multiline-string-pp/dotnet/multiline-string.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Pulumi; | ||
using Random = Pulumi.Random; | ||
|
||
return await Deployment.RunAsync(() => | ||
{ | ||
var foo = new Random.RandomShuffle("foo", new() | ||
{ | ||
Inputs = new[] | ||
{ | ||
@"just one | ||
newline", | ||
@"foo | ||
bar | ||
baz | ||
qux | ||
quux | ||
qux", | ||
@"{ | ||
""a"": 1, | ||
""b"": 2, | ||
""c"": [ | ||
""foo"", | ||
""bar"", | ||
""baz"", | ||
""qux"", | ||
""quux"" | ||
] | ||
} | ||
", | ||
}, | ||
}); | ||
}); | ||
|
33 changes: 33 additions & 0 deletions
33
pkg/codegen/testing/test/testdata/multiline-string-pp/go/multiline-string.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/pulumi/pulumi-random/sdk/v4/go/random" | ||
"github.com/pulumi/pulumi/sdk/v3/go/pulumi" | ||
) | ||
|
||
func main() { | ||
pulumi.Run(func(ctx *pulumi.Context) error { | ||
_, err := random.NewRandomShuffle(ctx, "foo", &random.RandomShuffleArgs{ | ||
Inputs: pulumi.StringArray{ | ||
pulumi.String("just one\nnewline"), | ||
pulumi.String("foo\nbar\nbaz\nqux\nquux\nqux"), | ||
pulumi.String(`{ | ||
"a": 1, | ||
"b": 2, | ||
"c": [ | ||
"foo", | ||
"bar", | ||
"baz", | ||
"qux", | ||
"quux" | ||
] | ||
} | ||
`), | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}) | ||
} |
19 changes: 19 additions & 0 deletions
19
pkg/codegen/testing/test/testdata/multiline-string-pp/multiline-string.pp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
resource foo "random:index/randomShuffle:RandomShuffle" { | ||
inputs = [ | ||
"just one\nnewline", | ||
"foo\nbar\nbaz\nqux\nquux\nqux", | ||
<<-EOT | ||
{ | ||
"a": 1, | ||
"b": 2, | ||
"c": [ | ||
"foo", | ||
"bar", | ||
"baz", | ||
"qux", | ||
"quux" | ||
] | ||
} | ||
EOT | ||
] | ||
} |
25 changes: 25 additions & 0 deletions
25
pkg/codegen/testing/test/testdata/multiline-string-pp/nodejs/multiline-string.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as random from "@pulumi/random"; | ||
|
||
const foo = new random.RandomShuffle("foo", {inputs: [ | ||
`just one | ||
newline`, | ||
`foo | ||
bar | ||
baz | ||
qux | ||
quux | ||
qux`, | ||
`{ | ||
"a": 1, | ||
"b": 2, | ||
"c": [ | ||
"foo", | ||
"bar", | ||
"baz", | ||
"qux", | ||
"quux" | ||
] | ||
} | ||
`, | ||
]}); |
25 changes: 25 additions & 0 deletions
25
pkg/codegen/testing/test/testdata/multiline-string-pp/python/multiline-string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pulumi | ||
import pulumi_random as random | ||
|
||
foo = random.RandomShuffle("foo", inputs=[ | ||
"""just one | ||
newline""", | ||
"""foo | ||
bar | ||
baz | ||
qux | ||
quux | ||
qux""", | ||
"""{ | ||
"a": 1, | ||
"b": 2, | ||
"c": [ | ||
"foo", | ||
"bar", | ||
"baz", | ||
"qux", | ||
"quux" | ||
] | ||
} | ||
""", | ||
]) |