Skip to content

Commit

Permalink
Fix pretty print for tables (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucGenetier authored Feb 23, 2024
1 parent aae6765 commit e26195c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public override LazyList<string> Visit(NumLitNode node, Precedence parentPrecede
Contracts.AssertValue(node);

var nlt = node.Value;
// $$$ can't use current culture

// $$$ can't use current culture
return LazyList<string>.Of(nlt != null ? nlt.ToString() : node.NumValue.ToString("R", CultureInfo.CurrentCulture));
}

Expand All @@ -77,7 +77,7 @@ public override LazyList<string> Visit(DecLitNode node, Precedence parentPrecede
Contracts.AssertValue(node);

var nlt = node.Value;

// $$$ can't use current culture
return LazyList<string>.Of(nlt != null ? nlt.ToString() : node.DecValue.ToString("G29", CultureInfo.CurrentCulture));
}
Expand Down Expand Up @@ -399,8 +399,8 @@ public override LazyList<string> Visit(TableNode node, Precedence parentPreceden
result = LazyList<string>.Of(TexlLexer.PunctuatorBracketOpen, " ")
.With(result)
.With(" ", TexlLexer.PunctuatorBracketClose);

return ApplyPrecedence(parentPrecedence, Precedence.SingleExpr, result);

return result;
}

public virtual string GetRightToken(TexlNode leftNode, Identifier right)
Expand Down
15 changes: 15 additions & 0 deletions src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,21 @@ public void TexlFunctionTypeSemanticColumn_Negative(string expression)
Assert.False(result.IsSuccess);
}

[Theory]
[InlineData("in")]
[InlineData("exactin")]
public void PrettyPrintTest(string op)
{
string expr = $"1 {op} [0]";

CheckResult check = new CheckResult(new Engine()).SetText(expr);
ParseResult parse = check.ApplyParse();

string str = parse.Root.ToString();

Assert.Equal($"1 {op} [ 0 ]", str);
}

internal class BlobFunc : TexlFunction
{
public override bool IsSelfContained => false;
Expand Down

0 comments on commit e26195c

Please sign in to comment.