summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-21 15:29:02 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-21 15:29:02 +0200
commitdd817b37a1139f0bbc1414c8b542734662c5da88 (patch)
tree4abd8a892e4751334a78ff90fde41061dc54b50c /tests
parent6520b63cb25580420e477cba2c776b2639cbf21b (diff)
Implement group_scanner
Diffstat (limited to 'tests')
-rw-r--r--tests/group/buildfile10
-rw-r--r--tests/group/driver.cxx59
-rw-r--r--tests/group/test.cli8
-rw-r--r--tests/group/testscript141
4 files changed, 218 insertions, 0 deletions
diff --git a/tests/group/buildfile b/tests/group/buildfile
new file mode 100644
index 0000000..c28920f
--- /dev/null
+++ b/tests/group/buildfile
@@ -0,0 +1,10 @@
+# file : tests/group/buildfile
+# copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: {hxx cxx}{* -test} cli.cxx{test} test{testscript}
+
+cxx.poptions =+ "-I$out_base"
+
+cli.cxx{test}: cli{test}
+cli.options = --generate-group-scanner
diff --git a/tests/group/driver.cxx b/tests/group/driver.cxx
new file mode 100644
index 0000000..1077670
--- /dev/null
+++ b/tests/group/driver.cxx
@@ -0,0 +1,59 @@
+// file : tests/group/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+// Test group_scanner.
+//
+
+#include <iostream>
+
+#include "test.hxx"
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ using namespace cli;
+
+ // Mode flags.
+ //
+ // 'g' -- don't handle groups.
+ // 's' -- skip arguments.
+ //
+ string m (argv[1]);
+
+ argv_scanner as (--argc, ++argv);
+ group_scanner s (as);
+
+ while (s.more ())
+ {
+ if (m.find ('s') == string::npos)
+ {
+ const char* a (s.next ());
+ cout << "'" << a << "'";
+ }
+ else
+ s.skip ();
+
+ if (m.find ('g') == string::npos)
+ {
+ scanner& gs (s.group ());
+ while (gs.more ())
+ cout << " '" << gs.next () << "'";
+ }
+
+ cout << endl;
+ }
+
+ return 0;
+ }
+ catch (const cli::exception& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+}
diff --git a/tests/group/test.cli b/tests/group/test.cli
new file mode 100644
index 0000000..082c2db
--- /dev/null
+++ b/tests/group/test.cli
@@ -0,0 +1,8 @@
+// file : tests/group/test.cli
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+class options
+{
+};
diff --git a/tests/group/testscript b/tests/group/testscript
new file mode 100644
index 0000000..3bc333c
--- /dev/null
+++ b/tests/group/testscript
@@ -0,0 +1,141 @@
+# file : tests/group/testscript
+# copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
+# license : MIT; see accompanying LICENSE file
+
+: no-args
+:
+$* ''
+
+: no-groups
+:
+$* '' --foo arg >>EOO
+'--foo'
+'arg'
+EOO
+
+: group-pre
+:
+$* '' { --foo --bar }+ arg1 arg2 >>EOO
+'arg1' '--foo' '--bar'
+'arg2'
+EOO
+
+: group-pre-multi
+:
+$* '' { --foo }+ { --bar }+ arg1 arg2 >>EOO
+'arg1' '--foo' '--bar'
+'arg2'
+EOO
+
+: group-post
+:
+$* '' arg1 arg2 +{ foo bar } >>EOO
+'arg1'
+'arg2' 'foo' 'bar'
+EOO
+
+: group-post-multi
+:
+$* '' arg1 arg2 +{ foo } +{ bar } >>EOO
+'arg1'
+'arg2' 'foo' 'bar'
+EOO
+
+: group-both
+:
+$* '' arg1 { --foo --bar }+ arg2 +{ foo bar } arg3 >>EOO
+'arg1'
+'arg2' '--foo' '--bar' 'foo' 'bar'
+'arg3'
+EOO
+
+: group-both-multi
+:
+$* '' arg1 { --foo }+ { --bar }+ arg2 +{ foo } +{ bar } arg3 >>EOO
+'arg1'
+'arg2' '--foo' '--bar' 'foo' 'bar'
+'arg3'
+EOO
+
+: multi-group
+:
+$* '' { --foo }+ arg1 arg2 +{ bar } >>EOO
+'arg1' '--foo'
+'arg2' 'bar'
+EOO
+
+: empty-group
+:
+$* '' { }+ arg1 arg2 +{ } >>EOO
+'arg1'
+'arg2'
+EOO
+
+: escape-arg
+:
+$* '' '\{' '\}' '\+{' '\}+' '{x' '}x' >>EOO
+'{'
+'}'
+'+{'
+'}+'
+'{x'
+'}x'
+EOO
+
+: escape-group
+:
+$* '' { '\{' '\}' '\+{' '\}+' '{x' '}x' }+ arg >>EOO
+'arg' '{' '}' '+{' '}+' '{x' '}x'
+EOO
+
+: not-group
+:
+$* '' { --foo } 2>>EOE != 0
+expected group separator '}+' instead of '}', use '\}' to escape
+EOE
+
+: no-arg-pre
+:
+$* '' { --foo }+ 2>>EOE != 0
+unexpected group separator '{', use '\{' to escape
+EOE
+
+: no-arg-pre-empty
+:
+$* '' { }+ 2>>EOE != 0
+unexpected group separator '{', use '\{' to escape
+EOE
+
+: no-arg-post
+:
+$* '' +{ --foo } 2>>EOE != 0
+unexpected group separator '+{', use '\+{' to escape
+EOE
+
+: no-arg-post-empty
+:
+$* '' +{ } 2>>EOE != 0
+unexpected group separator '+{', use '\+{' to escape
+EOE
+
+: unhandled-group-pre
+:
+$* 'g' { --foo }+ arg >>EOO 2>>EOE != 0
+'arg'
+EOO
+unexpected grouped argument '--foo' for argument 'arg'
+EOE
+
+: unhandled-group-post
+:
+$* 'g' arg +{ bar } >>EOO 2>>EOE != 0
+'arg'
+EOO
+unexpected grouped argument 'bar' for argument 'arg'
+EOE
+
+: unhandled-group-skip
+:
+$* 'sg' { --foo }+ arg +{ bar } >>EOO
+
+EOO