halcheck 1.0
Loading...
Searching...
No Matches
deserialize.hpp
1#ifndef HALCHECK_TEST_DESERIALIZE_HPP
2#define HALCHECK_TEST_DESERIALIZE_HPP
3
4#include <halcheck/lib/effect.hpp>
5#include <halcheck/lib/optional.hpp>
6#include <halcheck/lib/string.hpp>
7#include <halcheck/lib/utility.hpp>
8#include <halcheck/test/strategy.hpp>
9
10#include <string>
11
12namespace halcheck { namespace test {
13
14struct read_effect {
15 std::string key;
16 lib::optional<std::string> fallback() const { return lib::getenv("HALCHECK_" + key); }
17};
18
19inline lib::optional<std::string> read(std::string key) { return lib::effect::invoke<read_effect>(std::move(key)); }
20
21template<typename T>
22inline lib::optional<T> read(std::string key) {
23 auto value = test::read(std::move(key));
24 return value ? lib::of_string<T>(std::move(*value)) : lib::nullopt;
25}
26
27test::strategy deserialize(std::string name);
28
29}} // namespace halcheck::test
30
31#endif
static lib::effect_result_t< T > invoke(T args)
Invokes an effect.
Definition effect.hpp:118
lib::optional< std::string > getenv(const std::string &name)
Gets the value of an environment variable.
lib::optional< T > of_string(const std::string &value)
Converts a std::string to a value using operator>>.
Definition string.hpp:43