vrchat-community / UdonSharp

A compiler for compiling C# to Udon assembly
https://udonsharp.docs.vrchat.com
MIT License
470 stars 50 forks source link

Interpret two braces in the interpolated string #14

Closed ureishi closed 2 years ago

ureishi commented 2 years ago

Interpret two braces ("{{" or "}}") as one brace ("{" or "}") in the interpolated string.

cf. https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting#escaping-braces

github-actions[bot] commented 2 years ago

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

ureishi commented 2 years ago

I have read the CLA Document and I hereby sign the CLA

MerlinVR commented 2 years ago

Okay I was confused for a moment here. The relevant tests for this change are

tester.TestAssertion("String interpolation 1 left brace", $"One left brace \"{{\"" == "One left brace \"{\"");
tester.TestAssertion("String interpolation 1 right brace", $"One right brace \"}}\"" == "One right brace \"}\"");
tester.TestAssertion("String interpolation multi braces", $"{{1}}, {{{{2}}}}, {{{{{{3}}}}}}" == "{1}, {{2}}, {{{3}}}");

where no interpolation takes place and the compiler optimizes them to const strings but did not unescape the string. The rest just provide better coverage for string interpolation testing.

ureishi commented 2 years ago

I will limit it to test cases where parentheses are escaped in the string interpolation, to make the purpose of the test clearer. The two candidates are as follows:

tester.TestAssertion("String interpolation braces escape 1", $"}}, {{}}, {{" == "}, {}, {");

tester.TestAssertion("String interpolation braces escape 2", $"{{{1}}}, {{{{{2}}}}}, {{{{{{{3}}}}}}}" == "{1}, {{2}}, {{{3}}}");

I thought it appropriate to prepare a detailed test on string interpolation as a separate test, if necessary.

MerlinVR commented 2 years ago

It's okay to have the extra tests, I was just clarifying for future reference.

ureishi commented 2 years ago

It's okay to have the extra tests, I was just clarifying for future reference.

Okay, but I pushed before reading the message.... What should I do, leave it as it is, push the previous test case again, or create a new file as a detailed test case about string interpolation?

MerlinVR commented 2 years ago

It'd be good to have the extra tests just in case if you want to re-add them since you already have them written.