aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-01-08 15:30:40 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-01-08 15:31:29 +0300
commit6ac4f3bcc0bd1306bf1a8dd1bebae1a00081c6b7 (patch)
tree18557b6da8fafbdc511a0c0f505137ca9317d5ef /tests
parent6876fd23ef84487c016e7be46d3deb7d1e695cef (diff)
Add support for filtering during manifest parsing and serialization
Diffstat (limited to 'tests')
-rw-r--r--tests/manifest-parser/driver.cxx35
-rw-r--r--tests/manifest-serializer/driver.cxx18
2 files changed, 41 insertions, 12 deletions
diff --git a/tests/manifest-parser/driver.cxx b/tests/manifest-parser/driver.cxx
index 30b754f..d2d54e9 100644
--- a/tests/manifest-parser/driver.cxx
+++ b/tests/manifest-parser/driver.cxx
@@ -7,7 +7,7 @@
#ifndef __cpp_lib_modules
#include <vector>
#include <string>
-#include <utility> // pair
+#include <utility> // pair, move()
#include <sstream>
#include <iostream>
#endif
@@ -30,7 +30,9 @@ using namespace butl;
using pairs = vector<pair<string, string>>;
static bool
-test (const char* manifest, const pairs& expected);
+test (const char* manifest,
+ const pairs& expected,
+ manifest_parser::filter_function = {});
static bool
fail (const char* manifest);
@@ -160,6 +162,25 @@ main ()
auto p (manifest_parser::split_comment ("; comment"));
assert (p.first == "" && p.second == "comment");
}
+
+ // Filtering.
+ //
+ assert (test (":1\na: abc\nb: bca\nc: cab",
+ {{"","1"},{"a","abc"},{"c","cab"},{"",""},{"",""}},
+ [] (manifest_name_value& nv) {return nv.name != "b";}));
+
+ assert (test (":1\na: abc\nb: bca",
+ {{"","1"},{"ax","abc."},{"bx","bca."},{"",""},{"",""}},
+ [] (manifest_name_value& nv)
+ {
+ if (!nv.name.empty ())
+ {
+ nv.name += 'x';
+ nv.value += '.';
+ }
+
+ return true;
+ }));
}
static ostream&
@@ -177,11 +198,11 @@ operator<< (ostream& os, const pairs& ps)
}
static pairs
-parse (const char* m)
+parse (const char* m, manifest_parser::filter_function f = {})
{
istringstream is (m);
is.exceptions (istream::failbit | istream::badbit);
- manifest_parser p (is, "");
+ manifest_parser p (is, "", move (f));
pairs r;
@@ -197,16 +218,16 @@ parse (const char* m)
else
eom = false;
- r.emplace_back (nv.name, nv.value); // move
+ r.emplace_back (move (nv.name), move (nv.value));
}
return r;
}
static bool
-test (const char* m, const pairs& e)
+test (const char* m, const pairs& e, manifest_parser::filter_function f)
{
- pairs r (parse (m));
+ pairs r (parse (m, move (f)));
if (r != e)
{
diff --git a/tests/manifest-serializer/driver.cxx b/tests/manifest-serializer/driver.cxx
index d9a7255..be00106 100644
--- a/tests/manifest-serializer/driver.cxx
+++ b/tests/manifest-serializer/driver.cxx
@@ -30,7 +30,9 @@ using namespace butl;
using pairs = vector<pair<string, string>>;
static bool
-test (const pairs& manifest, const string& expected);
+test (const pairs& manifest,
+ const string& expected,
+ manifest_serializer::filter_function f = {});
static bool
fail (const pairs& manifest);
@@ -234,14 +236,20 @@ main ()
assert (manifest_serializer::merge_comment ("value text", "") ==
"value text");
+
+ // Filtering.
+ //
+ assert (test ({{"","1"},{"a","abc"},{"b","bca"},{"c","cab"},{"",""},{"",""}},
+ ": 1\na: abc\nc: cab\n",
+ [] (const string& n, const string&) {return n != "b";}));
}
static string
-serialize (const pairs& m)
+serialize (const pairs& m, manifest_serializer::filter_function f = {})
{
ostringstream os;
os.exceptions (istream::failbit | istream::badbit);
- manifest_serializer s (os, "");
+ manifest_serializer s (os, "", f);
for (const auto& p: m)
{
@@ -255,9 +263,9 @@ serialize (const pairs& m)
}
static bool
-test (const pairs& m, const string& e)
+test (const pairs& m, const string& e, manifest_serializer::filter_function f)
{
- string r (serialize (m));
+ string r (serialize (m, f));
if (r != e)
{