aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/libexpr')
-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 */