summaryrefslogtreecommitdiff
path: root/cli-tests/group
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-09-10 13:38:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-09-10 13:38:03 +0200
commita599248e9dfab9f5d57c06bed56f75941cb00047 (patch)
tree1dc188ebf4002e9c1cded6a1edb9011304c146a0 /cli-tests/group
parentfab7d03508109bffb23cde8f46ed19e3d9400308 (diff)
Add multi-argument grouping support in group_scanner
Diffstat (limited to 'cli-tests/group')
-rw-r--r--cli-tests/group/driver.cxx41
-rw-r--r--cli-tests/group/testscript84
2 files changed, 116 insertions, 9 deletions
diff --git a/cli-tests/group/driver.cxx b/cli-tests/group/driver.cxx
index 68f6107..01abf23 100644
--- a/cli-tests/group/driver.cxx
+++ b/cli-tests/group/driver.cxx
@@ -5,6 +5,8 @@
// Test group_scanner.
//
+#include <string>
+#include <cassert>
#include <iostream>
#include "test.hxx"
@@ -25,27 +27,58 @@ main (int argc, char* argv[])
//
string m (argv[1]);
+ bool sa (m.find ('s') != string::npos);
+ bool sg (m.find ('g') != string::npos);
+
argv_scanner as (--argc, ++argv);
group_scanner s (as);
+ // Verify previous two args are still valid for good measure.
+ //
+ const char* prev_a (0);
+ string prev_s;
+
+ // Verify position.
+ //
+ size_t pos (0); // argv_scanner starts from 1.
+
while (s.more ())
{
- if (m.find ('s') == string::npos)
+ assert (pos < s.position ());
+ pos = s.position ();
+
+ s.peek ();
+ assert (pos == s.position ());
+
+ const char* a;
+ if (!sa)
{
- const char* a (s.next ());
+ a = s.next ();
cout << "'" << a << "'";
}
else
s.skip ();
- if (m.find ('g') == string::npos)
+ if (!sg)
{
scanner& gs (s.group ());
while (gs.more ())
cout << " '" << gs.next () << "'";
}
- cout << endl;
+ if (!sa || !sg)
+ cout << endl;
+
+ if (!sa && !sg)
+ {
+ s.more ();
+
+ if (prev_a != 0)
+ assert (prev_a == prev_s);
+
+ prev_a = a;
+ prev_s = a;
+ }
}
return 0;
diff --git a/cli-tests/group/testscript b/cli-tests/group/testscript
index 6269ca2..0b1d939 100644
--- a/cli-tests/group/testscript
+++ b/cli-tests/group/testscript
@@ -19,6 +19,14 @@ $* '' { --foo --bar }+ arg1 arg2 >>EOO
'arg2'
EOO
+: group-pre-pack
+:
+$* '' { --foo --bar }+ { arg1 arg2 } arg3 >>EOO
+'arg1' '--foo' '--bar'
+'arg2' '--foo' '--bar'
+'arg3'
+EOO
+
: group-pre-multi
:
$* '' { --foo }+ { --bar }+ arg1 arg2 >>EOO
@@ -26,6 +34,14 @@ $* '' { --foo }+ { --bar }+ arg1 arg2 >>EOO
'arg2'
EOO
+: group-pre-multi-pack
+:
+$* '' { --foo }+ { --bar }+ { arg1 arg2 } arg3 >>EOO
+'arg1' '--foo' '--bar'
+'arg2' '--foo' '--bar'
+'arg3'
+EOO
+
: group-post
:
$* '' arg1 arg2 +{ foo bar } >>EOO
@@ -33,6 +49,14 @@ $* '' arg1 arg2 +{ foo bar } >>EOO
'arg2' 'foo' 'bar'
EOO
+: group-post-pack
+:
+$* '' arg1 { arg2 arg3 } +{ foo bar } >>EOO
+'arg1'
+'arg2' 'foo' 'bar'
+'arg3' 'foo' 'bar'
+EOO
+
: group-post-multi
:
$* '' arg1 arg2 +{ foo } +{ bar } >>EOO
@@ -40,6 +64,14 @@ $* '' arg1 arg2 +{ foo } +{ bar } >>EOO
'arg2' 'foo' 'bar'
EOO
+: group-post-multi-pack
+:
+$* '' arg1 { arg2 arg3 } +{ foo } +{ bar } >>EOO
+'arg1'
+'arg2' 'foo' 'bar'
+'arg3' 'foo' 'bar'
+EOO
+
: group-both
:
$* '' arg1 { --foo --bar }+ arg2 +{ foo bar } arg3 >>EOO
@@ -48,6 +80,15 @@ $* '' arg1 { --foo --bar }+ arg2 +{ foo bar } arg3 >>EOO
'arg3'
EOO
+: group-both-pack
+:
+$* '' arg1 { --foo --bar }+ { arg2 arg3 } +{ foo bar } arg4 >>EOO
+'arg1'
+'arg2' '--foo' '--bar' 'foo' 'bar'
+'arg3' '--foo' '--bar' 'foo' 'bar'
+'arg4'
+EOO
+
: group-both-multi
:
$* '' arg1 { --foo }+ { --bar }+ arg2 +{ foo } +{ bar } arg3 >>EOO
@@ -56,6 +97,15 @@ $* '' arg1 { --foo }+ { --bar }+ arg2 +{ foo } +{ bar } arg3 >>EOO
'arg3'
EOO
+: group-both-multi-pack
+:
+$* '' arg1 { --foo }+ { --bar }+ { arg2 arg3 } +{ foo } +{ bar } arg4 >>EOO
+'arg1'
+'arg2' '--foo' '--bar' 'foo' 'bar'
+'arg3' '--foo' '--bar' 'foo' 'bar'
+'arg4'
+EOO
+
: multi-group
:
$* '' { --foo }+ arg1 arg2 +{ bar } >>EOO
@@ -63,6 +113,15 @@ $* '' { --foo }+ arg1 arg2 +{ bar } >>EOO
'arg2' 'bar'
EOO
+: multi-group-pack
+:
+$* '' { --foo }+ { arg1 arg2 } { arg3 arg4 } +{ bar } >>EOO
+'arg1' '--foo'
+'arg2' '--foo'
+'arg3' 'bar'
+'arg4' 'bar'
+EOO
+
: empty-group
:
$* '' { }+ arg1 arg2 +{ } >>EOO
@@ -70,6 +129,13 @@ $* '' { }+ arg1 arg2 +{ } >>EOO
'arg2'
EOO
+: empty-group-pack
+:
+$* '' { }+ { arg1 arg2 } +{ } >>EOO
+'arg1'
+'arg2'
+EOO
+
: escape-arg
:
$* '' '\{' '\}' '\+{' '\}+' '{x' '}x' >>EOO
@@ -87,10 +153,16 @@ $* '' { '\{' '\}' '\+{' '\}+' '{x' '}x' }+ arg >>EOO
'arg' '{' '}' '+{' '}+' '{x' '}x'
EOO
-: not-group
+: pack-no-group
:
-$* '' { --foo } 2>>EOE != 0
-expected group separator '}+' instead of '}', use '\}' to escape
+$* '' { --foo } { arg2 }+ 2>>EOE != 0
+unexpected group separator '{', use '\{' to escape
+EOE
+
+: empty-pack
+:
+$* '' { --foo }+ { } 2>>EOE != 0
+unexpected group separator '{', use '\{' to escape
EOE
: no-arg-pre
@@ -135,6 +207,8 @@ EOE
: unhandled-group-skip
:
-$* 'sg' { --foo }+ arg +{ bar } >>EOO
+$* 'sg' { --foo }+ arg +{ bar }
-EOO
+: unhandled-group-skip-pack
+:
+$* 'sg' { --foo }+ { arg1 arg2 } +{ bar }