Skip to content

Commit

Permalink
Closes #44. Do not remove spaces from string in FB_init.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roald87 committed Aug 19, 2020
1 parent 24e5856 commit 7b6e5ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/TcBlack/VariableDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public TcDeclaration Tokenize()

public string RemoveWhiteSpaceIfPossible(string str)
{
string pattern = @"\s+(?=[^[\]]*\])|\s+(?=[^()]*\))";
string pattern = (
"\\s+(?=[^[]*\\])"
+ "|(?<!['\"][^,]*)\\s+(?=[^(]*\\))"
+ "|\\s+(?![^,]*['\"])(?=[^(]*\\))"
);

return Regex.Replace(str, pattern, "").Trim();
}
Expand Down
16 changes: 16 additions & 0 deletions src/TcBlackTests/VariableDeclarationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ private void AssertEquals(TcDeclaration expected, TcDeclaration actual)
"SomeArray : ARRAY[- 10..(2*-14)/SYSTEM.Number] OF INT;",
"SomeArray : ARRAY[-10..(2 * -14) / SYSTEM.Number] OF INT;"
)]
[InlineData(
"fbInst : FB_WithName(Name:='Text with spaces', number := 4);",
"fbInst : FB_WithName(Name:='Text with spaces', number:=4);"
)]
[InlineData(
"fbInst : FB_WithName( Name:= \"Another text with spaces\", num:=3.14) ;",
"fbInst : FB_WithName(Name:=\"Another text with spaces\", num:=3.14);"
)]
[InlineData(
"fbInst : FB_Name( Name:= \"Text with ' quote\" , truth := FALSE);",
"fbInst : FB_Name(Name:=\"Text with ' quote\", truth:=FALSE);"
)]
[InlineData(
"fbInst : FB_Name(Name:='The other \" quote' );",
"fbInst : FB_Name(Name:='The other \" quote');"
)]
public void FormatVariableDeclaration(string unformattedCode, string expected)
{
Global.indentation = " ";
Expand Down

0 comments on commit 7b6e5ac

Please sign in to comment.