2018-12-04 11:30:21 +00:00
|
|
|
#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); \
|
2018-12-05 08:19:37 +00:00
|
|
|
toml::detail::location<std::string> loc("test", token); \
|
2018-12-04 11:30:21 +00:00
|
|
|
const auto result = lxr::invoke(loc); \
|
2019-06-21 06:22:46 +00:00
|
|
|
BOOST_TEST(result.is_ok()); \
|
2018-12-04 11:30:21 +00:00
|
|
|
if(result.is_ok()){ \
|
2019-06-21 06:22:46 +00:00
|
|
|
const auto region = result.unwrap(); \
|
|
|
|
BOOST_TEST(region.str() == expected); \
|
|
|
|
BOOST_TEST(region.str().size() == expected.size()); \
|
|
|
|
BOOST_TEST(static_cast<std::size_t>(std::distance( \
|
|
|
|
loc.begin(), loc.iter())) == region.size()); \
|
2018-12-04 11:30:21 +00:00
|
|
|
} else { \
|
2019-06-21 06:22:46 +00:00
|
|
|
std::cerr << "lexer failed with input `"; \
|
|
|
|
std::cerr << token << "`. expected `" << expected << "`\n"; \
|
|
|
|
std::cerr << "reason: " << result.unwrap_err() << '\n'; \
|
2018-12-04 11:30:21 +00:00
|
|
|
} \
|
|
|
|
} while(false); \
|
|
|
|
/**/
|
|
|
|
|
|
|
|
#define TOML11_TEST_LEX_REJECT(lxr, tkn) \
|
|
|
|
do { \
|
|
|
|
const std::string token (tkn); \
|
2018-12-05 08:19:37 +00:00
|
|
|
toml::detail::location<std::string> loc("test", token); \
|
2018-12-04 11:30:21 +00:00
|
|
|
const auto result = lxr::invoke(loc); \
|
2019-06-21 06:22:46 +00:00
|
|
|
BOOST_TEST(result.is_err()); \
|
|
|
|
const bool loc_same = (loc.begin() == loc.iter()); \
|
|
|
|
BOOST_TEST(loc_same); \
|
2018-12-04 11:30:21 +00:00
|
|
|
} while(false); /**/
|