1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-22 02:09:36 +01:00
nix/src/libstore-test-support/path.cc
Sergei Zimmerman a5264aa46e
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:36:36 +03:00

68 lines
1.6 KiB
C++

#include <rapidcheck/gen/Arbitrary.h>
#include <regex>
#include <rapidcheck.h>
#include "nix/store/path-regex.hh"
#include "nix/store/store-api.hh"
#include "nix/util/tests/hash.hh"
#include "nix/store/tests/path.hh"
namespace nix {
void showValue(const StorePath & p, std::ostream & os)
{
os << p.to_string();
}
} // namespace nix
namespace rc {
using namespace nix;
Gen<char> storePathChar()
{
return rc::gen::apply(
[](uint8_t i) -> char {
switch (i) {
case 0 ... 9:
return '0' + i;
case 10 ... 35:
return 'A' + (i - 10);
case 36 ... 61:
return 'a' + (i - 36);
case 62:
return '+';
case 63:
return '-';
case 64:
return '.';
case 65:
return '_';
case 66:
return '?';
case 67:
return '=';
default:
assert(false);
}
},
gen::inRange<uint8_t>(0, 10 + 2 * 26 + 6));
}
Gen<StorePathName> Arbitrary<StorePathName>::arbitrary()
{
return gen::construct<StorePathName>(
gen::suchThat(gen::container<std::string>(storePathChar()), [](const std::string & s) {
return !(s == "" || s == "." || s == ".." || s.starts_with(".-") || s.starts_with("..-"));
}));
}
Gen<StorePath> Arbitrary<StorePath>::arbitrary()
{
return gen::construct<StorePath>(
gen::arbitrary<Hash>(), gen::apply([](StorePathName n) { return n.name; }, gen::arbitrary<StorePathName>()));
}
} // namespace rc