summaryrefslogtreecommitdiff
path: root/cli-tests/position
diff options
context:
space:
mode:
Diffstat (limited to 'cli-tests/position')
-rw-r--r--cli-tests/position/buildfile9
-rw-r--r--cli-tests/position/driver.cxx38
-rw-r--r--cli-tests/position/test.cli13
-rw-r--r--cli-tests/position/testscript36
4 files changed, 96 insertions, 0 deletions
diff --git a/cli-tests/position/buildfile b/cli-tests/position/buildfile
new file mode 100644
index 0000000..371cc54
--- /dev/null
+++ b/cli-tests/position/buildfile
@@ -0,0 +1,9 @@
+# file : position/buildfile
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: {hxx cxx}{* -test} cli.cxx{test} testscript
+
+cxx.poptions =+ "-I$out_base"
+
+cli.cxx{test}: cli{test}
+cli.options = --generate-file-scanner --generate-specifier
diff --git a/cli-tests/position/driver.cxx b/cli-tests/position/driver.cxx
new file mode 100644
index 0000000..77b9a8d
--- /dev/null
+++ b/cli-tests/position/driver.cxx
@@ -0,0 +1,38 @@
+// file : position/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+// Test argument/option position.
+//
+#include <iostream>
+
+#include "test.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ cli::argv_file_scanner scan (argc, argv, "--file");
+ options ops (scan);
+
+ if (ops.a_specified ())
+ cout << ops.a ().second << ": " << "-a " << ops.a ().first << endl;
+
+ for (const pair<int, size_t>& b: ops.b ())
+ {
+ cout << b.second << ": " << "-b " << b.first << endl;
+ }
+
+ while (scan.more ())
+ cout << scan.position () << ": " << scan.next () << endl;
+
+ cout << "max: " << scan.position () << endl;
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ }
+}
diff --git a/cli-tests/position/test.cli b/cli-tests/position/test.cli
new file mode 100644
index 0000000..7fc8655
--- /dev/null
+++ b/cli-tests/position/test.cli
@@ -0,0 +1,13 @@
+// file : position/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// license : MIT; see accompanying LICENSE file
+
+include <vector>;
+include <utility>;
+include <cstddef>;
+
+class options
+{
+ std::pair<int, std::size_t> -a;
+ std::vector<std::pair<int, std::size_t> > -b;
+};
diff --git a/cli-tests/position/testscript b/cli-tests/position/testscript
new file mode 100644
index 0000000..568e571
--- /dev/null
+++ b/cli-tests/position/testscript
@@ -0,0 +1,36 @@
+# file : position/testscript
+# license : MIT; see accompanying LICENSE file
+
+: basics
+:
+$* -b 1 -a 2 -b 3 foo bar baz >>EOO
+3: -a 2
+1: -b 1
+5: -b 3
+7: foo
+8: bar
+9: baz
+max: 10
+EOO
+
+: override
+:
+$* -a 1 -a 2 >>EOO
+3: -a 2
+max: 5
+EOO
+
+: file
+:
+cat <<EOI >=test.ops;
+-a 2
+EOI
+$* -b 1 --file test.ops -b 2 foo bar baz >>EOO
+5: -a 2
+1: -b 1
+7: -b 2
+9: foo
+10: bar
+11: baz
+max: 12
+EOO