From 84f6ebab62a9f2553ae454d67861b0b142470d0b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 25 Jul 2018 20:11:47 +0300 Subject: Move bpkg::package_name class to butl::project_name --- tests/project-name/buildfile | 8 ++++ tests/project-name/driver.cxx | 84 +++++++++++++++++++++++++++++++++++++++ tests/project-name/testscript | 78 ++++++++++++++++++++++++++++++++++++ tests/standard-version/buildfile | 2 +- tests/standard-version/driver.cxx | 10 ++--- 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 tests/project-name/buildfile create mode 100644 tests/project-name/driver.cxx create mode 100644 tests/project-name/testscript (limited to 'tests') diff --git a/tests/project-name/buildfile b/tests/project-name/buildfile new file mode 100644 index 0000000..3e16fe8 --- /dev/null +++ b/tests/project-name/buildfile @@ -0,0 +1,8 @@ +# file : tests/project-name/buildfile +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +import libs = libbutl%lib{butl} +libs += $stdmod_lib + +exe{driver}: {hxx cxx}{*} $libs testscript diff --git a/tests/project-name/driver.cxx b/tests/project-name/driver.cxx new file mode 100644 index 0000000..51c8782 --- /dev/null +++ b/tests/project-name/driver.cxx @@ -0,0 +1,84 @@ +// file : tests/project-name/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#ifndef __cpp_lib_modules +#include // ios::*bit +#include +#include +#include // invalid_argument +#endif + +// Other includes. + +#ifdef __cpp_modules +#ifdef __cpp_lib_modules +import std.core; +import std.io; +#endif +import butl.utility; // operator<<(ostream,exception), eof(), *case() +import butl.project_name; +#else +#include +#include +#endif + +using namespace std; +using namespace butl; + +// Create project_name from string and also perform some tests for the created +// object. +// +static project_name +name (const string& s) +{ + project_name r (s); + + assert (r == project_name (lcase (s))); + assert (r == project_name (ucase (s))); + + assert (r > project_name ("!", project_name::raw_string)); + assert (r < project_name ("~", project_name::raw_string)); + + return r; +} + +// Usage: argv[0] (string|base|extension|variable) +// +// Create project names from stdin lines, and for each of them print the +// result of the specified member function to stdout, one per line. +// +int +main (int argc, char* argv[]) +try +{ + assert (argc == 2); + + string m (argv[1]); + assert (m == "string" || m == "base" || m == "extension" || m == "variable"); + + cin.exceptions (ios::badbit); + cout.exceptions (ios::failbit | ios::badbit); + + string l; + while (!eof (getline (cin, l))) + { + project_name n (name (l)); + + const string& s (m == "string" ? n.string () : + m == "base" ? n.base () : + m == "extension" ? n.extension () : + n.variable ()); + + cout << s << endl; + } + + return 0; +} +catch (const invalid_argument& e) +{ + cerr << e << endl; + return 1; +} diff --git a/tests/project-name/testscript b/tests/project-name/testscript new file mode 100644 index 0000000..92bd5e8 --- /dev/null +++ b/tests/project-name/testscript @@ -0,0 +1,78 @@ +# file : tests/project-name/testscript +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +: string +{ + test.arguments += 'string' + + : valid + : + $* <>EOF + foo + foo1 + Foo + foo_bar + foo+bar + foo-bar + foo.bar + build2 + EOF + + $* <'a' 2>'length is less than two characters' != 0: short + $* <'nul' 2>'illegal name' != 0: illegal-name + $* <'1a' 2>'illegal first character (must be alphabetic)' != 0: illegal-first-char + $* <'a!b' 2>'illegal character' != 0: illegal-char + + : illegal-last-char + : + $* <'a.' 2>'illegal last character (must be alphabetic, digit, or plus)' != 0 +} + +: base +: +{ + test.arguments += 'base'; + + $* <>EOO + libbutl + libbutl.bash + a.b.c + EOI + libbutl + libbutl + a.b + EOO +} + +: extension +: +{ + test.arguments += 'extension'; + + $* <>EOO + libbutl + libbutl.bash + a.b.c + EOI + + bash + c + EOO +} + +: variable +: +{ + test.arguments += 'variable'; + + $* <>EOO + foo-bar + libc++ + libbutl.bash + EOI + foo_bar + libc__ + libbutl_bash + EOO +} diff --git a/tests/standard-version/buildfile b/tests/standard-version/buildfile index 8e8ded6..7ae054e 100644 --- a/tests/standard-version/buildfile +++ b/tests/standard-version/buildfile @@ -1,4 +1,4 @@ -# file : tests/tab-parser/buildfile +# file : tests/standard-version/buildfile # copyright : Copyright (c) 2014-2018 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file diff --git a/tests/standard-version/driver.cxx b/tests/standard-version/driver.cxx index 3bc1d31..7ad5b00 100644 --- a/tests/standard-version/driver.cxx +++ b/tests/standard-version/driver.cxx @@ -18,7 +18,7 @@ import std.core; import std.io; #endif -import butl.utility; // operator<<(ostream,exception) +import butl.utility; // operator<<(ostream,exception), eof() import butl.standard_version; #else #include @@ -124,11 +124,11 @@ version (const string& s, // -a output 'y' for alpha-version, 'n' otherwise // -b output 'y' for beta-version, 'n' otherwise // -c output 0 if versions are equal, -1 if the first one is less, 1 otherwise -// -r create version constraints from STDIN lines, and print them to STDOUT +// -r create version constraints from stdin lines, and print them to stdout // -s output 'y' if version satisfies constraint, 'n' otherwise // -// If no options are specified, then create versions from STDIN lines, and -// print them to STDOUT. +// If no options are specified, then create versions from stdin lines, and +// print them to stdout. // int main (int argc, char* argv[]) @@ -186,7 +186,7 @@ try } string s; - while (getline (cin, s)) + while (!eof (getline (cin, s))) cout << (s.empty () ? standard_version () : version (s)) << endl; return 0; -- cgit v1.1