Skip to content

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Sep 16, 2025

Adds a new unit test for the Mustache Set Delimiter feature.

This test is written with inverted logic (EXPECT_NE) so that it
passes with the current implementation, which does not support
the feature. Once the feature is implemented, this test will fail,
signaling that the test logic should be flipped to EXPECT_EQ.

Copy link
Contributor Author

ilovepi commented Sep 16, 2025

@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2025

@llvm/pr-subscribers-llvm-support

Author: Paul Kirth (ilovepi)

Changes

Adds a new unit test for the Mustache Set Delimiter feature.

This test is written with inverted logic (EXPECT_NE) so that it
passes with the current implementation, which does not support
the feature. Once the feature is implemented, this test will fail,
signaling that the test logic should be flipped to EXPECT_EQ.


Full diff: https://github.com/llvm/llvm-project/pull/159186.diff

1 Files Affected:

  • (modified) llvm/unittests/Support/MustacheTest.cpp (+134)
diff --git a/llvm/unittests/Support/MustacheTest.cpp b/llvm/unittests/Support/MustacheTest.cpp
index b80c39fb7c5bc..f613fde072cde 100644
--- a/llvm/unittests/Support/MustacheTest.cpp
+++ b/llvm/unittests/Support/MustacheTest.cpp
@@ -1329,3 +1329,137 @@ TEST(MustacheTripleMustache, WithPadding) {
   EXPECT_EQ("|---|", Out);
 }
 
+TEST(MustacheDelimiters, PairBehavior) {
+  Value D = Object{{"text", "Hey!"}};
+  auto T = Template("{{=<% %>=}}(<%text%>)");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("(Hey!)", Out);
+}
+
+TEST(MustacheDelimiters, SpecialCharacters) {
+  Value D = Object{{"text", "It worked!"}};
+  auto T = Template("({{=[ ]=}}[text])");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("(It worked!)", Out);
+}
+
+TEST(MustacheDelimiters, Sections) {
+  Value D = Object{{"section", true}, {"data", "I got interpolated."}};
+  auto T = Template("[\n{{#section}}\n  {{data}}\n  |data|\n{{/section}}\n\n{{= "
+                    "| | =}}\n|#section|\n  {{data}}\n  |data|\n|/section|\n]\n");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("[\n  I got interpolated.\n  |data|\n\n  {{data}}\n  I got "
+            "interpolated.\n]\n",
+            Out);
+}
+
+TEST(MustacheDelimiters, InvertedSections) {
+  Value D = Object{{"section", false}, {"data", "I got interpolated."}};
+  auto T = Template("[\n{{^section}}\n  {{data}}\n  |data|\n{{/section}}\n\n{{= "
+                    "| | =}}\n|^section|\n  {{data}}\n  |data|\n|/section|\n]\n");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("[\n  I got interpolated.\n  |data|\n\n  {{data}}\n  I got "
+            "interpolated.\n]\n",
+            Out);
+}
+
+TEST(MustacheDelimiters, PartialInheritence) {
+  Value D = Object{{"value", "yes"}};
+  auto T = Template("[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n");
+  T.registerPartial("include", ".{{value}}.");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("[ .yes. ]\n[ .yes. ]\n", Out);
+}
+
+TEST(MustacheDelimiters, PostPartialBehavior) {
+  Value D = Object{{"value", "yes"}};
+  auto T = Template("[ {{>include}} ]\n[ .{{value}}.  .|value|. ]\n");
+  T.registerPartial("include", ".{{value}}. {{= | | =}} .|value|.");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("[ .yes.  .yes. ]\n[ .yes.  .|value|. ]\n", Out);
+}
+
+TEST(MustacheDelimiters, SurroundingWhitespace) {
+  Value D = Object{};
+  auto T = Template("| {{=@ @=}} |");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_EQ("|  |", Out);
+}
+
+TEST(MustacheDelimiters, OutlyingWhitespaceInline) {
+  Value D = Object{};
+  auto T = Template(" | {{=@ @=}}\n");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_EQ(" | \n", Out);
+}
+
+TEST(MustacheDelimiters, StandaloneTag) {
+  Value D = Object{};
+  auto T = Template("Begin.\n{{=@ @=}}\nEnd.\n");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("Begin.\nEnd.\n", Out);
+}
+
+TEST(MustacheDelimiters, IndentedStandaloneTag) {
+  Value D = Object{};
+  auto T = Template("Begin.\n  {{=@ @=}}\nEnd.\n");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("Begin.\nEnd.\n", Out);
+}
+
+TEST(MustacheDelimiters, StandaloneLineEndings) {
+  Value D = Object{};
+  auto T = Template("|\r\n{{= @ @ =}}\r\n|");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("|\r\n|", Out);
+}
+
+TEST(MustacheDelimiters, StandaloneWithoutPreviousLine) {
+  Value D = Object{};
+  auto T = Template("  {{=@ @=}}\n=");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("=", Out);
+}
+
+TEST(MustacheDelimiters, StandaloneWithoutNewline) {
+  Value D = Object{};
+  auto T = Template("=\n  {{=@ @=}}");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_NE("=\n", Out);
+}
+
+TEST(MustacheDelimiters, PairwithPadding) {
+  Value D = Object{};
+  auto T = Template("|{{= @   @ =}}|");
+  std::string Out;
+  raw_string_ostream OS(Out);
+  T.render(D, OS);
+  EXPECT_EQ("||", Out);
+}
+

@github-actions
Copy link

github-actions bot commented Sep 16, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@ilovepi ilovepi force-pushed the users/ilovepi/mustache-indent-impl branch from 8b5ffb2 to f2623ab Compare September 22, 2025 17:07
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-delimiter-test branch 2 times, most recently from 293e89e to c3b7fae Compare September 22, 2025 17:56
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-indent-impl branch 4 times, most recently from 2be3734 to 9c99ef9 Compare September 25, 2025 22:12
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-delimiter-test branch from c3b7fae to 6ba6cd7 Compare September 25, 2025 22:12
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-indent-impl branch from 9c99ef9 to c4b1cba Compare September 26, 2025 01:55
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-delimiter-test branch from 6ba6cd7 to 78a29c3 Compare September 26, 2025 01:55
The current implementation did not correctly handle indentation for
standalone partial tags. It was only applied to lines following a
newline, instead of the first line of a partial's content. This was
fixed by updating the AddIndentation implementation to prepend the
indentation to the first line of the partial.
Adds a new unit test for the Mustache Set Delimiter feature.

This test is written with inverted logic (`EXPECT_NE`) so that it
passes with the current implementation, which does not support
the feature. Once the feature is implemented, this test will fail,
signaling that the test logic should be flipped to `EXPECT_EQ`.
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-delimiter-test branch from 78a29c3 to dc36a30 Compare September 29, 2025 17:39
@ilovepi ilovepi force-pushed the users/ilovepi/mustache-indent-impl branch from c4b1cba to c58ac89 Compare September 29, 2025 17:39
Base automatically changed from users/ilovepi/mustache-indent-impl to main September 29, 2025 18:00
@ilovepi ilovepi enabled auto-merge (squash) September 29, 2025 18:01
@ilovepi ilovepi merged commit 2522a95 into main Sep 29, 2025
12 of 15 checks passed
@ilovepi ilovepi deleted the users/ilovepi/mustache-delimiter-test branch September 29, 2025 18:19
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
Adds a new unit test for the Mustache Set Delimiter feature.

This test is written with inverted logic (`EXPECT_NE`) so that it
passes with the current implementation, which does not support
the feature. Once the feature is implemented, this test will fail,
signaling that the test logic should be flipped to `EXPECT_EQ`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants