From dd817b37a1139f0bbc1414c8b542734662c5da88 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 21 Mar 2018 15:29:02 +0200 Subject: Implement group_scanner --- tests/group/buildfile | 10 ++++ tests/group/driver.cxx | 59 +++++++++++++++++++++ tests/group/test.cli | 8 +++ tests/group/testscript | 141 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 tests/group/buildfile create mode 100644 tests/group/driver.cxx create mode 100644 tests/group/test.cli create mode 100644 tests/group/testscript (limited to 'tests') 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 +// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +// Test group_scanner. +// + +#include + +#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 +// 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 -- cgit v1.1