mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-08-03 12:50:02 +00:00
Add unit test for the SettingsBag.
This commit is contained in:
parent
85363e0db1
commit
b4291becf0
4 changed files with 96 additions and 6 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <boost/phoenix/bind/bind_member_variable.hpp>
|
||||
#include <boost/fusion/adapted/std_pair.hpp>
|
||||
#include <type_traits>
|
||||
#include <iterator>
|
||||
|
||||
namespace tawashi {
|
||||
namespace {
|
||||
|
@ -89,15 +90,18 @@ namespace tawashi {
|
|||
start = *(section_head >> key_values);
|
||||
}
|
||||
|
||||
IniFile::IniMapType parse_ini (const std::string* parIni) {
|
||||
IniFile::IniMapType parse_ini (const std::string* parIni, bool& parParseOk, int& parParsedCharCount) {
|
||||
using boost::spirit::qi::blank;
|
||||
using boost::spirit::qi::blank_type;
|
||||
|
||||
IniGrammar<std::string::const_iterator, blank_type> gramm(parIni);
|
||||
IniFile::IniMapType result;
|
||||
|
||||
parParseOk = false;
|
||||
parParsedCharCount = 0;
|
||||
|
||||
std::string::const_iterator start_it = parIni->cbegin();
|
||||
/*const bool parse_ok =*/ boost::spirit::qi::phrase_parse(
|
||||
const bool parse_ok = boost::spirit::qi::phrase_parse(
|
||||
start_it,
|
||||
parIni->cend(),
|
||||
gramm,
|
||||
|
@ -105,7 +109,8 @@ namespace tawashi {
|
|||
result
|
||||
);
|
||||
|
||||
//assert(parse_ok and (parIni->cend() == start_it));
|
||||
parParseOk = parse_ok and (parIni->cend() == start_it);
|
||||
parParsedCharCount = std::distance(parIni->cbegin(), start_it);
|
||||
return result;
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
@ -117,7 +122,7 @@ namespace tawashi {
|
|||
|
||||
IniFile::IniFile (std::string&& parIniData) :
|
||||
m_raw_ini(std::move(parIniData)),
|
||||
m_map(parse_ini(&m_raw_ini))
|
||||
m_map(parse_ini(&m_raw_ini, m_parse_ok, m_parsed_chars))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -127,7 +132,7 @@ namespace tawashi {
|
|||
if (m_raw_ini.data() == old_data_ptr)
|
||||
m_map = std::move(parOther.m_map);
|
||||
else
|
||||
m_map = parse_ini(&m_raw_ini);
|
||||
m_map = parse_ini(&m_raw_ini, m_parse_ok, m_parsed_chars);
|
||||
}
|
||||
|
||||
IniFile::~IniFile() noexcept {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <iterator>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
namespace tawashi {
|
||||
class IniFile : public Kakoune::SafeCountable {
|
||||
|
@ -38,10 +39,20 @@ namespace tawashi {
|
|||
IniFile& operator== (IniFile&&) = delete;
|
||||
IniFile& operator== (const IniFile&) = delete;
|
||||
|
||||
const IniMapType& parsed() const { return m_map; }
|
||||
bool parse_success() const { return m_parse_ok; }
|
||||
int parsed_characters() const { return m_parsed_chars; }
|
||||
|
||||
const IniMapType& parsed() const;
|
||||
|
||||
private:
|
||||
std::string m_raw_ini;
|
||||
IniMapType m_map;
|
||||
int m_parsed_chars;
|
||||
bool m_parse_ok;
|
||||
};
|
||||
|
||||
inline const IniFile::IniMapType& IniFile::parsed() const {
|
||||
assert(parse_success());
|
||||
return m_map;
|
||||
}
|
||||
} //namespace tawashi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue