diff options
-rw-r--r-- | trie.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -103,16 +103,31 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered) string s = asString(contents(testPath + "/trietest.json")); BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?"); js::read_string(s, v); + for (auto& i: v.get_obj()) { cnote << i.first; js::mObject& o = i.second.get_obj(); vector<pair<string, string>> ss; + vector<string> keysToBeDeleted; for (auto& i: o["in"].get_array()) { vector<string> values; for (auto& s: i.get_array()) - values.push_back(s.get_str()); + { + if (s.type() == json_spirit::str_type) + values.push_back(s.get_str()); + else if (s.type() == json_spirit::null_type) + { + // mark entry for deletion + values.push_back(""); + if (!values[0].find("0x")) + values[0] = asString(fromHex(values[0].substr(2))); + keysToBeDeleted.push_back(values[0]); + } + else + cwarn << "Bad type (expected string): " << s.type(); + } assert(values.size() == 2); ss.push_back(make_pair(values[0], values[1])); @@ -128,9 +143,13 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered) BOOST_REQUIRE(t.check(true)); for (auto const& k: ss) { - t.insert(k.first, k.second); + if (find(keysToBeDeleted.begin(), keysToBeDeleted.end(), k.first) != keysToBeDeleted.end() && k.second.empty()) + t.remove(k.first); + else + t.insert(k.first, k.second); BOOST_REQUIRE(t.check(true)); } + BOOST_REQUIRE(!o["root"].is_null()); BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray())); } |