#include #include #include "path-regex.hh" #include "store-api.hh" #include "tests/hash.hh" #include "tests/path.hh" namespace nix { void showValue(const StorePath & p, std::ostream & os) { os << p.to_string(); } } namespace rc { using namespace nix; Gen Arbitrary::arbitrary() { auto len = *gen::inRange( 1, StorePath::MaxPathLen - StorePath::HashLen); std::string pre; pre.reserve(len); for (size_t c = 0; c < len; ++c) { switch (auto i = *gen::inRange(0, 10 + 2 * 26 + 6)) { case 0 ... 9: pre += '0' + i; case 10 ... 35: pre += 'A' + (i - 10); break; case 36 ... 61: pre += 'a' + (i - 36); break; case 62: pre += '+'; break; case 63: pre += '-'; break; case 64: // names aren't permitted to start with a period, // so just fall through to the next case here if (c != 0) { pre += '.'; break; } case 65: pre += '_'; break; case 66: pre += '?'; break; case 67: pre += '='; break; default: assert(false); } } return gen::just(StorePathName { .name = std::move(pre), }); } Gen Arbitrary::arbitrary() { return gen::just(StorePath { *gen::arbitrary(), (*gen::arbitrary()).name, }); } } // namespace rc