diff options
author | piegames <git@piegames.de> | 2024-07-11 10:49:15 +0200 |
---|---|---|
committer | piegames <git@piegames.de> | 2024-08-08 11:13:53 +0200 |
commit | 28ae24f3f738a50903bd9b9bf8eece84a1075c30 (patch) | |
tree | dae4696680c5acd3ada9f170976c6b7581e9be82 /tests/unit | |
parent | 6fdb47f0b259a9ffbe4bdb349d6aaf03a0144092 (diff) |
libexpr: Add experimental pipe operator
The |> operator is a reverse function operator with low binding strength
to replace lib.pipe. Implements RFC 148, see the RFC text for more
details. Closes #438.
Change-Id: I21df66e8014e0d4dd9753dd038560a2b0b7fd805
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/libexpr/trivial.cc | 36 |
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 */ |