diff options
Diffstat (limited to 'tests/unit/libexpr/trivial.cc')
-rw-r--r-- | tests/unit/libexpr/trivial.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/libexpr/trivial.cc b/tests/unit/libexpr/trivial.cc index 171727ac7..c984657fd 100644 --- a/tests/unit/libexpr/trivial.cc +++ b/tests/unit/libexpr/trivial.cc @@ -59,6 +59,11 @@ namespace nix { ASSERT_THAT(v, IsFloatEq(1.234)); } + TEST_F(TrivialExpressionTest, pointfloat) { + auto v = eval(".234"); + ASSERT_THAT(v, IsFloatEq(0.234)); + } + TEST_F(TrivialExpressionTest, updateAttrs) { auto v = eval("{ a = 1; } // { b = 2; a = 3; }"); ASSERT_THAT(v, IsAttrsOfSize(2)); @@ -81,6 +86,18 @@ namespace nix { ASSERT_THAT(v, IsTrue()); } + TEST_F(TrivialExpressionTest, urlLiteral) { + auto v = eval("https://nixos.org"); + ASSERT_THAT(v, IsStringEq("https://nixos.org")); + } + + TEST_F(TrivialExpressionTest, noUrlLiteral) { + ExperimentalFeatureSettings mockXpSettings; + mockXpSettings.set("experimental-features", "no-url-literals"); + + ASSERT_THROW(eval("https://nixos.org", true, mockXpSettings), Error); + } + TEST_F(TrivialExpressionTest, withFound) { auto v = eval("with { a = 23; }; a"); ASSERT_THAT(v, IsIntEq(23)); @@ -193,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 */ |