summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-05-08 13:30:19 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commit367530b6495a455ad53827bce7f331419ed2ab83 (patch)
tree89485bf948505efeff9f7c99253724b617ad3fda
parentInitial commit where writing objects back out to JSON (diff)
downloadilt-367530b6495a455ad53827bce7f331419ed2ab83.tar.bz2
ilt-367530b6495a455ad53827bce7f331419ed2ab83.tar.xz
ilt-367530b6495a455ad53827bce7f331419ed2ab83.zip
Update tests to coverage encoding strings
Fixes char (byte) type lookup.
-rw-r--r--lib/jsonParse-persistence.cpp2
-rw-r--r--test/test-persistence.cpp44
2 files changed, 28 insertions, 18 deletions
diff --git a/lib/jsonParse-persistence.cpp b/lib/jsonParse-persistence.cpp
index 6ecfff8..5062796 100644
--- a/lib/jsonParse-persistence.cpp
+++ b/lib/jsonParse-persistence.cpp
@@ -170,7 +170,7 @@ namespace Persistence {
{
strm << '"';
std::for_each(value.begin(), value.end(), [this](char ch) {
- outFuncs[ch](strm, ch);
+ outFuncs[(unsigned char)ch](strm, ch);
});
strm << '"';
}
diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp
index 547396b..ab16166 100644
--- a/test/test-persistence.cpp
+++ b/test/test-persistence.cpp
@@ -257,23 +257,25 @@ BOOST_FIXTURE_TEST_CASE(load_shared_object_null, JPP)
}
using svs = std::tuple<const char * const, std::string_view>;
-BOOST_DATA_TEST_CASE_F(JPP, load_strings,
- boost::unit_test::data::make<svs>({
- {R"J("")J", ""},
- {R"J("non empty")J", "non empty"},
- {R"J("new\nline")J", "new\nline"},
- {R"J("quote\"mark")J", "quote\"mark"},
- {R"J("tab\t")J", "tab\t"},
- {R"J("back\bspace?")J", "back\bspace?"},
- {R"J("form\ffeed?")J", "form\ffeed?"},
- {R"J("forward\/slash")J", "forward/slash"},
- {R"J("\u00a5 yen")J", "¥ yen"},
- {R"J("gbp \u00a3")J", "gbp £"},
- {R"J("\u007E tilde")J", "~ tilde"},
- {R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"},
- {R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"},
- }),
- in, exp)
+auto const TEST_STRINGS = boost::unit_test::data::make<svs>({
+ {R"J("")J", ""},
+ {R"J("non empty")J", "non empty"},
+ {R"J("new\nline")J", "new\nline"},
+ {R"J("quote\"mark")J", "quote\"mark"},
+ {R"J("tab\t")J", "tab\t"},
+ {R"J("back\bspace?")J", "back\bspace?"},
+ {R"J("form\ffeed?")J", "form\ffeed?"},
+ {R"J("a \u0007 bell")J", "a \a bell"},
+});
+auto const TEST_STRINGS_DECODE_ONLY = boost::unit_test::data::make<svs>({
+ {R"J("forward\/slash")J", "forward/slash"},
+ {R"J("\u00a5 yen")J", "¥ yen"},
+ {R"J("gbp \u00a3")J", "gbp £"},
+ {R"J("\u007E tilde")J", "~ tilde"},
+ {R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"},
+ {R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"},
+});
+BOOST_DATA_TEST_CASE_F(JPP, load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, exp)
{
std::stringstream str {in};
BOOST_CHECK_EQUAL(loadState<std::string>(str), exp);
@@ -346,3 +348,11 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded_shared, JPP)
// BOOST_CHECK_EQUAL(ss.str(),
// R"({"@typeid":"SharedTestObject","sptr":{"@typeid":"SubObject","@id":"someid"},"ssptr":"someid"})");
}
+
+BOOST_DATA_TEST_CASE(write_special_strings, TEST_STRINGS, exp, in)
+{
+ std::stringstream ss;
+ std::string copy(in);
+ Persistence::JsonWritePersistence {ss}.saveState(copy);
+ BOOST_CHECK_EQUAL(ss.str(), exp);
+}