summaryrefslogtreecommitdiff
path: root/cli-tests/merge
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-04-08 14:51:57 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-27 11:38:53 +0300
commit720c5a33b6a49cf328fdd7611f49153cf8f60247 (patch)
tree9725f3d1f42ec90fde84520f49647edea013ce5e /cli-tests/merge
parent3183f3bb927a90783ae0aeaf190a0919377aabe4 (diff)
Separate tests and examples into individual packages
Also make cli module to be explicitly enabled via the config.cli configuration variable.
Diffstat (limited to 'cli-tests/merge')
-rw-r--r--cli-tests/merge/buildfile9
-rw-r--r--cli-tests/merge/driver.cxx55
-rw-r--r--cli-tests/merge/test.cli18
3 files changed, 82 insertions, 0 deletions
diff --git a/cli-tests/merge/buildfile b/cli-tests/merge/buildfile
new file mode 100644
index 0000000..ed93cda
--- /dev/null
+++ b/cli-tests/merge/buildfile
@@ -0,0 +1,9 @@
+# file : merge/buildfile
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: {hxx cxx}{* -test} cli.cxx{test}
+
+cxx.poptions =+ "-I$out_base"
+
+cli.cxx{test}: cli{test}
+cli.options = --generate-merge
diff --git a/cli-tests/merge/driver.cxx b/cli-tests/merge/driver.cxx
new file mode 100644
index 0000000..43b1c59
--- /dev/null
+++ b/cli-tests/merge/driver.cxx
@@ -0,0 +1,55 @@
+// file : merge/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+// Test parsed options merging.
+//
+
+#include <string>
+#include <cassert>
+
+#include "test.hxx"
+
+using namespace std;
+
+template <typename T, int N1, int N2>
+static T
+merge (const char* (&av1)[N1], const char* (&av2)[N2])
+{
+ int ac1 (N1);
+ int ac2 (N2);
+ T o1 (ac1, const_cast<char**> (av1));
+ T o2 (ac2, const_cast<char**> (av2));
+ o1.merge (o2);
+ return o1;
+}
+
+int
+main ()
+{
+ // Basics.
+ //
+ {
+ const char* a1[] = {"", "-i=123", "-v=1", "-v=2"};
+ const char* a2[] = {"", "-b", "-i=456", "-s=xyz", "-v=3", "-v=4"};
+ derived r (merge<derived> (a1, a2));
+
+ assert (r.b ());
+ assert (r.i_specified () && r.i () == 456);
+ assert (r.s_specified () && r.s () == "xyz");
+ assert (r.v_specified () && r.v ().size () == 4 &&
+ r.v ()[0] == 1 &&
+ r.v ()[1] == 2 &&
+ r.v ()[2] == 3 &&
+ r.v ()[3] == 4);
+ }
+
+ // Default value does not override.
+ //
+ {
+ const char* a1[] = {"", "-i=456"};
+ const char* a2[] = {"" };
+ derived r (merge<derived> (a1, a2));
+ assert (r.i_specified () && r.i () == 456);
+ }
+}
diff --git a/cli-tests/merge/test.cli b/cli-tests/merge/test.cli
new file mode 100644
index 0000000..67f50c6
--- /dev/null
+++ b/cli-tests/merge/test.cli
@@ -0,0 +1,18 @@
+// file : merge/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+include <string>;
+include <vector>;
+
+class base
+{
+ bool -b;
+ int -i = -1;
+ std::string -s;
+};
+
+class derived: base
+{
+ std::vector<int> -v;
+};