diff --git a/.gitignore b/.gitignore index 2aca60d..eba7fe3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ *.user .vs/ /src/packages/ +/src/.vscode diff --git a/src/Core/CodeModel/CSharpExpressionWriter.cs b/src/Core/CodeModel/CSharpExpressionWriter.cs index cc2ecf9..9632db9 100644 --- a/src/Core/CodeModel/CSharpExpressionWriter.cs +++ b/src/Core/CodeModel/CSharpExpressionWriter.cs @@ -645,8 +645,14 @@ private void WriteStringLiteral(Syntax.Str literal) { writer.Write("@\""); } + else if (literal.Format) + { + writer.Write("$\""); + } else + { writer.Write("\""); + } for (int i = 0; i < literal.s.Length; ++i) { diff --git a/src/Pytocs.Tests/Translate/ExpTranslatorTests.cs b/src/Pytocs.Tests/Translate/ExpTranslatorTests.cs index 700b64d..b57813e 100644 --- a/src/Pytocs.Tests/Translate/ExpTranslatorTests.cs +++ b/src/Pytocs.Tests/Translate/ExpTranslatorTests.cs @@ -785,5 +785,13 @@ public void Ex_tuple_unpacker() })"; Assert.Equal(sExp, Xlat(pySrc)); } + + [Fact(DisplayName = nameof(Ex_FormatString))] + public void Ex_FormatString() + { + var pySrc = "f'Hello {world}'"; + var sExp = "$\"Hello {world}\""; + Assert.Equal(sExp, Xlat(pySrc)); + } } }