mirror of
https://github.com/NixOS/nix.git
synced 2025-11-23 18:59:35 +01:00
For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
80 lines
1.8 KiB
C++
80 lines
1.8 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 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
|