1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <regex>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <rapidcheck/gen/Arbitrary.h>
#include <rapidcheck.h>
#pragma GCC diagnostic pop

#include "lix/libstore/path-regex.hh"
#include "lix/libstore/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<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