From 2e6cf0ec6ca477087ca30bca3e5d0c889a35dbf8 Mon Sep 17 00:00:00 2001 From: James Luck Date: Mon, 29 Aug 2022 13:30:56 +1000 Subject: [PATCH] Fixing bug that meant printing a vector matching expression with matcher labels would incorrectly not include empty parenthesis for group_right/ group_left (#10) Co-authored-by: James Luck --- src/PromQL.Parser/Printer.cs | 2 +- tests/PromQL.Parser.Tests/PrinterTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PromQL.Parser/Printer.cs b/src/PromQL.Parser/Printer.cs index 1e3d4ca..d172c3c 100644 --- a/src/PromQL.Parser/Printer.cs +++ b/src/PromQL.Parser/Printer.cs @@ -173,7 +173,7 @@ public virtual void Visit(VectorMatching vm) _sb.Append(vm.MatchCardinality.ToPromQl()); } - if (vm.Include.Length > 0) + if (vm.Include.Length > 0 || vm.MatchCardinality != VectorMatching.DefaultMatchCardinality) { if (_sb.Length > 0) _sb.Append(" "); diff --git a/tests/PromQL.Parser.Tests/PrinterTests.cs b/tests/PromQL.Parser.Tests/PrinterTests.cs index 8d8927e..72d932a 100644 --- a/tests/PromQL.Parser.Tests/PrinterTests.cs +++ b/tests/PromQL.Parser.Tests/PrinterTests.cs @@ -136,7 +136,7 @@ public void VectorMatching_GroupRight_NoLabels_ToPromQl() false, ImmutableArray.Empty, false - )).Should().Be("group_right"); + )).Should().Be("group_right ()"); } [Test]