summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-07-27 11:38:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-07-27 16:34:32 +0200
commitdca38b27afc25d329fd7a7241095b40e2a1ecae2 (patch)
treec656421398fd818d68f9e07130f96d7eeeaa6490 /tests
parentc5979a2814c9211e0e3c8ae7232ea66f171d54d0 (diff)
Add support for option merging (--generate-merge)
Diffstat (limited to 'tests')
-rw-r--r--tests/merge/buildfile10
-rw-r--r--tests/merge/driver.cxx56
-rw-r--r--tests/merge/test.cli19
3 files changed, 85 insertions, 0 deletions
diff --git a/tests/merge/buildfile b/tests/merge/buildfile
new file mode 100644
index 0000000..c1ef0a1
--- /dev/null
+++ b/tests/merge/buildfile
@@ -0,0 +1,10 @@
+# file : tests/merge/buildfile
+# copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
+# 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/tests/merge/driver.cxx b/tests/merge/driver.cxx
new file mode 100644
index 0000000..a0791e6
--- /dev/null
+++ b/tests/merge/driver.cxx
@@ -0,0 +1,56 @@
+// file : tests/merge/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
+// 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/tests/merge/test.cli b/tests/merge/test.cli
new file mode 100644
index 0000000..64da534
--- /dev/null
+++ b/tests/merge/test.cli
@@ -0,0 +1,19 @@
+// file : tests/merge/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
+// 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;
+};