1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00
nix/src/libexpr-tests/search-path.cc
Sergei Zimmerman 0e35cd6f3e
Apply clang-format universally.
* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.

Co-authored-by: Graham Christensen <graham@grahamc.com>
2025-07-18 22:49:40 +03:00

102 lines
2.7 KiB
C++

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include "nix/expr/search-path.hh"
namespace nix {
TEST(LookupPathElem, parse_justPath)
{
ASSERT_EQ(
LookupPath::Elem::parse("foo"),
(LookupPath::Elem{
.prefix = LookupPath::Prefix{.s = ""},
.path = LookupPath::Path{.s = "foo"},
}));
}
TEST(LookupPathElem, parse_emptyPrefix)
{
ASSERT_EQ(
LookupPath::Elem::parse("=foo"),
(LookupPath::Elem{
.prefix = LookupPath::Prefix{.s = ""},
.path = LookupPath::Path{.s = "foo"},
}));
}
TEST(LookupPathElem, parse_oneEq)
{
ASSERT_EQ(
LookupPath::Elem::parse("foo=bar"),
(LookupPath::Elem{
.prefix = LookupPath::Prefix{.s = "foo"},
.path = LookupPath::Path{.s = "bar"},
}));
}
TEST(LookupPathElem, parse_twoEqs)
{
ASSERT_EQ(
LookupPath::Elem::parse("foo=bar=baz"),
(LookupPath::Elem{
.prefix = LookupPath::Prefix{.s = "foo"},
.path = LookupPath::Path{.s = "bar=baz"},
}));
}
TEST(LookupPathElem, suffixIfPotentialMatch_justPath)
{
LookupPath::Prefix prefix{.s = ""};
ASSERT_EQ(prefix.suffixIfPotentialMatch("any/thing"), std::optional{"any/thing"});
}
TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix1)
{
LookupPath::Prefix prefix{.s = "foo"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX"), std::nullopt);
}
TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix2)
{
LookupPath::Prefix prefix{.s = "foo"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX/bar"), std::nullopt);
}
TEST(LookupPathElem, suffixIfPotentialMatch_partialPrefix)
{
LookupPath::Prefix prefix{.s = "fooX"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::nullopt);
}
TEST(LookupPathElem, suffixIfPotentialMatch_exactPrefix)
{
LookupPath::Prefix prefix{.s = "foo"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::optional{""});
}
TEST(LookupPathElem, suffixIfPotentialMatch_multiKey)
{
LookupPath::Prefix prefix{.s = "foo/bar"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional{"baz"});
}
TEST(LookupPathElem, suffixIfPotentialMatch_trailingSlash)
{
LookupPath::Prefix prefix{.s = "foo"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/"), std::optional{""});
}
TEST(LookupPathElem, suffixIfPotentialMatch_trailingDoubleSlash)
{
LookupPath::Prefix prefix{.s = "foo"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo//"), std::optional{"/"});
}
TEST(LookupPathElem, suffixIfPotentialMatch_trailingPath)
{
LookupPath::Prefix prefix{.s = "foo"};
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional{"bar/baz"});
}
} // namespace nix