Skip to content

Commit 2522a95

Browse files
authored
[llvm][mustache] Precommit test for Set Delimiter (#159186)
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`.
1 parent 8dde784 commit 2522a95

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

llvm/unittests/Support/MustacheTest.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,3 +1328,139 @@ TEST(MustacheTripleMustache, WithPadding) {
13281328
T.render(D, OS);
13291329
EXPECT_EQ("|---|", Out);
13301330
}
1331+
1332+
TEST(MustacheDelimiters, PairBehavior) {
1333+
Value D = Object{{"text", "Hey!"}};
1334+
auto T = Template("{{=<% %>=}}(<%text%>)");
1335+
std::string Out;
1336+
raw_string_ostream OS(Out);
1337+
T.render(D, OS);
1338+
EXPECT_NE("(Hey!)", Out);
1339+
}
1340+
1341+
TEST(MustacheDelimiters, SpecialCharacters) {
1342+
Value D = Object{{"text", "It worked!"}};
1343+
auto T = Template("({{=[ ]=}}[text])");
1344+
std::string Out;
1345+
raw_string_ostream OS(Out);
1346+
T.render(D, OS);
1347+
EXPECT_NE("(It worked!)", Out);
1348+
}
1349+
1350+
TEST(MustacheDelimiters, Sections) {
1351+
Value D = Object{{"section", true}, {"data", "I got interpolated."}};
1352+
auto T =
1353+
Template("[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= "
1354+
"| | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n");
1355+
std::string Out;
1356+
raw_string_ostream OS(Out);
1357+
T.render(D, OS);
1358+
EXPECT_NE("[\n I got interpolated.\n |data|\n\n {{data}}\n I got "
1359+
"interpolated.\n]\n",
1360+
Out);
1361+
}
1362+
1363+
TEST(MustacheDelimiters, InvertedSections) {
1364+
Value D = Object{{"section", false}, {"data", "I got interpolated."}};
1365+
auto T =
1366+
Template("[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= "
1367+
"| | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n");
1368+
std::string Out;
1369+
raw_string_ostream OS(Out);
1370+
T.render(D, OS);
1371+
EXPECT_NE("[\n I got interpolated.\n |data|\n\n {{data}}\n I got "
1372+
"interpolated.\n]\n",
1373+
Out);
1374+
}
1375+
1376+
TEST(MustacheDelimiters, PartialInheritence) {
1377+
Value D = Object{{"value", "yes"}};
1378+
auto T = Template("[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n");
1379+
T.registerPartial("include", ".{{value}}.");
1380+
std::string Out;
1381+
raw_string_ostream OS(Out);
1382+
T.render(D, OS);
1383+
EXPECT_NE("[ .yes. ]\n[ .yes. ]\n", Out);
1384+
}
1385+
1386+
TEST(MustacheDelimiters, PostPartialBehavior) {
1387+
Value D = Object{{"value", "yes"}};
1388+
auto T = Template("[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n");
1389+
T.registerPartial("include", ".{{value}}. {{= | | =}} .|value|.");
1390+
std::string Out;
1391+
raw_string_ostream OS(Out);
1392+
T.render(D, OS);
1393+
EXPECT_NE("[ .yes. .yes. ]\n[ .yes. .|value|. ]\n", Out);
1394+
}
1395+
1396+
TEST(MustacheDelimiters, SurroundingWhitespace) {
1397+
Value D = Object{};
1398+
auto T = Template("| {{=@ @=}} |");
1399+
std::string Out;
1400+
raw_string_ostream OS(Out);
1401+
T.render(D, OS);
1402+
EXPECT_EQ("| |", Out);
1403+
}
1404+
1405+
TEST(MustacheDelimiters, OutlyingWhitespaceInline) {
1406+
Value D = Object{};
1407+
auto T = Template(" | {{=@ @=}}\n");
1408+
std::string Out;
1409+
raw_string_ostream OS(Out);
1410+
T.render(D, OS);
1411+
EXPECT_EQ(" | \n", Out);
1412+
}
1413+
1414+
TEST(MustacheDelimiters, StandaloneTag) {
1415+
Value D = Object{};
1416+
auto T = Template("Begin.\n{{=@ @=}}\nEnd.\n");
1417+
std::string Out;
1418+
raw_string_ostream OS(Out);
1419+
T.render(D, OS);
1420+
EXPECT_NE("Begin.\nEnd.\n", Out);
1421+
}
1422+
1423+
TEST(MustacheDelimiters, IndentedStandaloneTag) {
1424+
Value D = Object{};
1425+
auto T = Template("Begin.\n {{=@ @=}}\nEnd.\n");
1426+
std::string Out;
1427+
raw_string_ostream OS(Out);
1428+
T.render(D, OS);
1429+
EXPECT_NE("Begin.\nEnd.\n", Out);
1430+
}
1431+
1432+
TEST(MustacheDelimiters, StandaloneLineEndings) {
1433+
Value D = Object{};
1434+
auto T = Template("|\r\n{{= @ @ =}}\r\n|");
1435+
std::string Out;
1436+
raw_string_ostream OS(Out);
1437+
T.render(D, OS);
1438+
EXPECT_NE("|\r\n|", Out);
1439+
}
1440+
1441+
TEST(MustacheDelimiters, StandaloneWithoutPreviousLine) {
1442+
Value D = Object{};
1443+
auto T = Template(" {{=@ @=}}\n=");
1444+
std::string Out;
1445+
raw_string_ostream OS(Out);
1446+
T.render(D, OS);
1447+
EXPECT_NE("=", Out);
1448+
}
1449+
1450+
TEST(MustacheDelimiters, StandaloneWithoutNewline) {
1451+
Value D = Object{};
1452+
auto T = Template("=\n {{=@ @=}}");
1453+
std::string Out;
1454+
raw_string_ostream OS(Out);
1455+
T.render(D, OS);
1456+
EXPECT_NE("=\n", Out);
1457+
}
1458+
1459+
TEST(MustacheDelimiters, PairwithPadding) {
1460+
Value D = Object{};
1461+
auto T = Template("|{{= @ @ =}}|");
1462+
std::string Out;
1463+
raw_string_ostream OS(Out);
1464+
T.render(D, OS);
1465+
EXPECT_EQ("||", Out);
1466+
}

0 commit comments

Comments
 (0)