Skip to content

Commit

Permalink
Feature: python format strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Sep 21, 2020
1 parent 1516671 commit 171cbd7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
*.user
.vs/
/src/packages/
/src/.vscode
6 changes: 6 additions & 0 deletions src/Core/CodeModel/CSharpExpressionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Pytocs.Tests/Translate/ExpTranslatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

0 comments on commit 171cbd7

Please sign in to comment.