From e26195c2508823afc5269a43c6f3928588a0fa2f Mon Sep 17 00:00:00 2001 From: Luc Genetier <69138830+LucGenetier@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:07:05 +0100 Subject: [PATCH] Fix pretty print for tables (#2232) --- .../Microsoft.PowerFx.Core/Syntax/TexlPretty.cs | 10 +++++----- .../Microsoft.PowerFx.Core.Tests/TexlTests.cs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs b/src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs index b66d8ff9d7..1249da7f0a 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs @@ -67,8 +67,8 @@ public override LazyList Visit(NumLitNode node, Precedence parentPrecede Contracts.AssertValue(node); var nlt = node.Value; - - // $$$ can't use current culture + + // $$$ can't use current culture return LazyList.Of(nlt != null ? nlt.ToString() : node.NumValue.ToString("R", CultureInfo.CurrentCulture)); } @@ -77,7 +77,7 @@ public override LazyList Visit(DecLitNode node, Precedence parentPrecede Contracts.AssertValue(node); var nlt = node.Value; - + // $$$ can't use current culture return LazyList.Of(nlt != null ? nlt.ToString() : node.DecValue.ToString("G29", CultureInfo.CurrentCulture)); } @@ -399,8 +399,8 @@ public override LazyList Visit(TableNode node, Precedence parentPreceden result = LazyList.Of(TexlLexer.PunctuatorBracketOpen, " ") .With(result) .With(" ", TexlLexer.PunctuatorBracketClose); - - return ApplyPrecedence(parentPrecedence, Precedence.SingleExpr, result); + + return result; } public virtual string GetRightToken(TexlNode leftNode, Identifier right) diff --git a/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs b/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs index 41dd902850..a93f1230b7 100644 --- a/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs +++ b/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs @@ -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;