aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorpiegames <git@piegames.de>2024-08-08 18:15:21 +0000
committerGerrit Code Review <gerrit@localhost>2024-08-08 18:15:21 +0000
commite03cd8b3a6f70c60f359fd683c2b25f8eba4da0d (patch)
treeb0c6684b42343e073a9c3cd65db9ddbccceeccd4 /tests/unit
parenta957219df2b7f360695f884f45fe4802240b9755 (diff)
parent28ae24f3f738a50903bd9b9bf8eece84a1075c30 (diff)
Merge "libexpr: Add experimental pipe operator" into main
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/libexpr/trivial.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/unit/libexpr/trivial.cc b/tests/unit/libexpr/trivial.cc
index 19b62aff8..c984657fd 100644
--- a/tests/unit/libexpr/trivial.cc
+++ b/tests/unit/libexpr/trivial.cc
@@ -210,4 +210,40 @@ namespace nix {
TEST_F(TrivialExpressionTest, orCantBeUsed) {
ASSERT_THROW(eval("let or = 1; in or"), Error);
}
+
+ // pipes are gated behind an experimental feature flag
+ TEST_F(TrivialExpressionTest, pipeDisabled) {
+ ASSERT_THROW(eval("let add = l: r: l + r; in ''a'' |> add ''b''"), Error);
+ ASSERT_THROW(eval("let add = l: r: l + r; in ''a'' <| add ''b''"), Error);
+ }
+
+ TEST_F(TrivialExpressionTest, pipeRight) {
+ ExperimentalFeatureSettings mockXpSettings;
+ mockXpSettings.set("experimental-features", "pipe-operator");
+
+ auto v = eval("let add = l: r: l + r; in ''a'' |> add ''b''", true, mockXpSettings);
+ ASSERT_THAT(v, IsStringEq("ba"));
+ v = eval("let add = l: r: l + r; in ''a'' |> add ''b'' |> add ''c''", true, mockXpSettings);
+ ASSERT_THAT(v, IsStringEq("cba"));
+ }
+
+ TEST_F(TrivialExpressionTest, pipeLeft) {
+ ExperimentalFeatureSettings mockXpSettings;
+ mockXpSettings.set("experimental-features", "pipe-operator");
+
+ auto v = eval("let add = l: r: l + r; in add ''a'' <| ''b''", true, mockXpSettings);
+ ASSERT_THAT(v, IsStringEq("ab"));
+ v = eval("let add = l: r: l + r; in add ''a'' <| add ''b'' <| ''c''", true, mockXpSettings);
+ ASSERT_THAT(v, IsStringEq("abc"));
+ }
+
+ TEST_F(TrivialExpressionTest, pipeMixed) {
+ ExperimentalFeatureSettings mockXpSettings;
+ mockXpSettings.set("experimental-features", "pipe-operator");
+
+ auto v = eval("let add = l: r: l + r; in add ''a'' <| ''b'' |> add ''c''", true, mockXpSettings);
+ ASSERT_THAT(v, IsStringEq("acb"));
+ v = eval("let add = l: r: l + r; in ''a'' |> add <| ''c''", true, mockXpSettings);
+ ASSERT_THAT(v, IsStringEq("ac"));
+ }
} /* namespace nix */