2023-06-23 20:51:25 +03:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
|
|
#include "search-path.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, parse_justPath) {
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(
|
2024-04-13 18:35:15 +03:00
|
|
|
LookupPath::Elem::parse("foo"),
|
|
|
|
(LookupPath::Elem {
|
|
|
|
.prefix = LookupPath::Prefix { .s = "" },
|
|
|
|
.path = LookupPath::Path { .s = "foo" },
|
2023-06-23 20:51:25 +03:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, parse_emptyPrefix) {
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(
|
2024-04-13 18:35:15 +03:00
|
|
|
LookupPath::Elem::parse("=foo"),
|
|
|
|
(LookupPath::Elem {
|
|
|
|
.prefix = LookupPath::Prefix { .s = "" },
|
|
|
|
.path = LookupPath::Path { .s = "foo" },
|
2023-06-23 20:51:25 +03:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, parse_oneEq) {
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(
|
2024-04-13 18:35:15 +03:00
|
|
|
LookupPath::Elem::parse("foo=bar"),
|
|
|
|
(LookupPath::Elem {
|
|
|
|
.prefix = LookupPath::Prefix { .s = "foo" },
|
|
|
|
.path = LookupPath::Path { .s = "bar" },
|
2023-06-23 20:51:25 +03:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, parse_twoEqs) {
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(
|
2024-04-13 18:35:15 +03:00
|
|
|
LookupPath::Elem::parse("foo=bar=baz"),
|
|
|
|
(LookupPath::Elem {
|
|
|
|
.prefix = LookupPath::Prefix { .s = "foo" },
|
|
|
|
.path = LookupPath::Path { .s = "bar=baz" },
|
2023-06-23 20:51:25 +03:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_justPath) {
|
|
|
|
LookupPath::Prefix prefix { .s = "" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("any/thing"), std::optional { "any/thing" });
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix1) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX"), std::nullopt);
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix2) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX/bar"), std::nullopt);
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_partialPrefix) {
|
|
|
|
LookupPath::Prefix prefix { .s = "fooX" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::nullopt);
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_exactPrefix) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::optional { "" });
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_multiKey) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo/bar" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "baz" });
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_trailingSlash) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/"), std::optional { "" });
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_trailingDoubleSlash) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo//"), std::optional { "/" });
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:35:15 +03:00
|
|
|
TEST(LookupPathElem, suffixIfPotentialMatch_trailingPath) {
|
|
|
|
LookupPath::Prefix prefix { .s = "foo" };
|
2023-06-23 20:51:25 +03:00
|
|
|
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "bar/baz" });
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|