toml11/tests/test_lex_aux.hpp
ToruNiina b13e727b90 refactor: remove unused func, combinator::pattern
because it is not human-readable (too long and redundant)
2019-05-30 18:05:47 +09:00

36 lines
2.2 KiB
C++

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <toml/region.hpp>
#include <toml/result.hpp>
#define TOML11_TEST_LEX_ACCEPT(lxr, tkn, expct) \
do { \
const std::string token (tkn); \
const std::string expected(expct); \
toml::detail::location<std::string> loc("test", token); \
const auto result = lxr::invoke(loc); \
BOOST_CHECK(result.is_ok()); \
if(result.is_ok()){ \
const auto region = result.unwrap(); \
BOOST_CHECK_EQUAL(region.str(), expected); \
BOOST_CHECK_EQUAL(region.str().size(), expected.size()); \
BOOST_CHECK_EQUAL(static_cast<std::size_t>(std::distance( \
loc.begin(), loc.iter())), region.size()); \
} else { \
std::cerr << "lexer failed with input `"; \
std::cerr << token << "`. expected `" << expected << "`\n"; \
std::cerr << "reason: " << result.unwrap_err() << '\n'; \
} \
} while(false); \
/**/
#define TOML11_TEST_LEX_REJECT(lxr, tkn) \
do { \
const std::string token (tkn); \
toml::detail::location<std::string> loc("test", token); \
const auto result = lxr::invoke(loc); \
BOOST_CHECK(result.is_err()); \
BOOST_CHECK(loc.begin() == loc.iter()); \
} while(false); /**/