From 720c5a33b6a49cf328fdd7611f49153cf8f60247 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 8 Apr 2020 14:51:57 +0300 Subject: Separate tests and examples into individual packages Also make cli module to be explicitly enabled via the config.cli configuration variable. --- cli-tests/merge/driver.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 cli-tests/merge/driver.cxx (limited to 'cli-tests/merge/driver.cxx') 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 +// license : MIT; see accompanying LICENSE file + +// Test parsed options merging. +// + +#include +#include + +#include "test.hxx" + +using namespace std; + +template +static T +merge (const char* (&av1)[N1], const char* (&av2)[N2]) +{ + int ac1 (N1); + int ac2 (N2); + T o1 (ac1, const_cast (av1)); + T o2 (ac2, const_cast (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 (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 (a1, a2)); + assert (r.i_specified () && r.i () == 456); + } +} -- cgit v1.1