#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REQUIRE_STRING_CONTAINS(str, match) REQUIRE(std::string(str).find(match) != std::string::npos) #define REQUIRE_STRING_NOT_CONTAINS(str, match) REQUIRE(std::string(str).find(match) == std::string::npos) namespace hocon { namespace test_utils { shared_origin fake_origin(std::string description = "fake", int line_number = 0); /** Tokens */ std::shared_ptr string_token(std::string text, config_string_type type = config_string_type::QUOTED); std::shared_ptr bool_token(bool boolean); std::shared_ptr double_token(double number, std::string original_text); std::shared_ptr int_token(int number, std::string original_text); std::shared_ptr long_token(int64_t number, std::string original_text); std::shared_ptr null_token(); std::shared_ptr substitution_token(shared_token inner, bool optional = false); std::shared_ptr line_token(int line_number); std::shared_ptr whitespace_token(std::string whitespace); std::shared_ptr unquoted_text_token(std::string text); std::shared_ptr double_slash_comment_token(std::string text); std::shared_ptr hash_comment_token(std::string text); /** Nodes */ std::shared_ptr colon_node(); std::shared_ptr open_brace_node(); std::shared_ptr close_brace_node(); std::shared_ptr space_node(); std::shared_ptr comma_node(); std::shared_ptr node_key_value_pair(std::shared_ptr key, shared_node_value value); std::shared_ptr node_key(std::string key); std::shared_ptr int_node(int number); std::shared_ptr long_node(int64_t number); std::shared_ptr double_node(double number); std::shared_ptr string_node(std::string text); std::shared_ptr null_node(); std::shared_ptr bool_node(bool value); std::shared_ptr unquoted_text_node(std::string text); std::shared_ptr substitution_node(shared_token key, bool optional); std::shared_ptr line_node(int line_number); std::shared_ptr whitespace_node(std::string whitespace); std::shared_ptr double_slash_comment_node(std::string text); // it's important that these do NOT use the public API to create the // instances, because we may be testing that the public API returns the // right instance by comparing to these, so using public API here would // make the test compare public API to itself. std::shared_ptr int_value(int i); // TODO: remaining value helpers std::shared_ptr bool_value(bool b); std::shared_ptr null_value(); std::shared_ptr string_value(std::string s); std::shared_ptr double_value(double d); std::shared_ptr subst(std::string ref, bool optional = false); std::shared_ptr subst_in_string(std::string ref, bool optional = false); /** Paths */ path test_path(std::initializer_list path_elements); shared_object parse_object(std::string); shared_config parse_config(std::string); struct parse_test { parse_test(std::string t, bool lbe = false, bool wm = false) : test(move(t)), lift_behavior_unexpected(lbe), whitespace_matters(wm) { } std::string test; bool lift_behavior_unexpected, whitespace_matters; }; std::vector const& invalid_json(); std::vector const& invalid_conf(); std::vector const& valid_json(); std::vector const& valid_conf(); std::vector whitespace_variations(std::vector const& tests, bool valid_in_lift); std::string fixture_path(std::string fixture_name); }} // namespace hocon::test_utils