mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
add a test for parser (WIP)
This commit is contained in:
38
tests/test_parse_aux.hpp
Normal file
38
tests/test_parse_aux.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <toml/region.hpp>
|
||||
#include <toml/result.hpp>
|
||||
|
||||
// some of the parsers returns not only a value but also a region.
|
||||
#define TOML11_TEST_PARSE_EQUAL(psr, tkn, expct) \
|
||||
do { \
|
||||
const std::string token(tkn); \
|
||||
toml::detail::location<std::string> loc("test", token); \
|
||||
const auto result = psr(loc); \
|
||||
BOOST_CHECK(result.is_ok()); \
|
||||
if(result.is_ok()){ \
|
||||
BOOST_CHECK(result.unwrap().first == expct); \
|
||||
} else { \
|
||||
std::cerr << "parser " << #psr << " failed with input `"; \
|
||||
std::cerr << token << "`.\n"; \
|
||||
std::cerr << "reason: " << result.unwrap_err() << '\n'; \
|
||||
} \
|
||||
} while(false); \
|
||||
/**/
|
||||
|
||||
#define TOML11_TEST_PARSE_EQUAL_VALUE(tkn, expct) \
|
||||
do { \
|
||||
const std::string token(tkn); \
|
||||
toml::detail::location<std::string> loc("test", token); \
|
||||
const auto result = toml::detail::parse_value(loc); \
|
||||
BOOST_CHECK(result.is_ok()); \
|
||||
if(result.is_ok()){ \
|
||||
BOOST_CHECK(result.unwrap() == expct); \
|
||||
} else { \
|
||||
std::cerr << "parse_value failed with input `"; \
|
||||
std::cerr << token << "`.\n"; \
|
||||
std::cerr << "reason: " << result.unwrap_err() << '\n'; \
|
||||
} \
|
||||
} while(false); \
|
||||
/**/
|
Reference in New Issue
Block a user