2024-02-13 16:54:07 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "content-address.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* ContentAddressMethod::parse, ContentAddressMethod::render
|
|
|
|
* --------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
TEST(ContentAddressMethod, testRoundTripPrintParse_1) {
|
2024-05-17 02:08:28 +03:00
|
|
|
for (ContentAddressMethod cam : {
|
|
|
|
ContentAddressMethod::Raw::Text,
|
|
|
|
ContentAddressMethod::Raw::Flat,
|
|
|
|
ContentAddressMethod::Raw::NixArchive,
|
|
|
|
ContentAddressMethod::Raw::Git,
|
2024-02-13 16:54:07 +02:00
|
|
|
}) {
|
|
|
|
EXPECT_EQ(ContentAddressMethod::parse(cam.render()), cam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContentAddressMethod, testRoundTripPrintParse_2) {
|
|
|
|
for (const std::string_view camS : {
|
|
|
|
"text",
|
|
|
|
"flat",
|
|
|
|
"nar",
|
2023-09-04 16:51:23 +03:00
|
|
|
"git",
|
2024-02-13 16:54:07 +02:00
|
|
|
}) {
|
|
|
|
EXPECT_EQ(ContentAddressMethod::parse(camS).render(), camS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContentAddressMethod, testParseContentAddressMethodOptException) {
|
|
|
|
EXPECT_THROW(ContentAddressMethod::parse("narwhal"), UsageError);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|