diff options
Diffstat (limited to 'tests/standard-version/driver.cxx')
-rw-r--r-- | tests/standard-version/driver.cxx | 117 |
1 files changed, 97 insertions, 20 deletions
diff --git a/tests/standard-version/driver.cxx b/tests/standard-version/driver.cxx index 7ad5b00..f20eb28 100644 --- a/tests/standard-version/driver.cxx +++ b/tests/standard-version/driver.cxx @@ -7,6 +7,7 @@ #ifndef __cpp_lib_modules #include <ios> // ios::failbit, ios::badbit #include <string> +#include <cstdint> // uint*_t #include <iostream> #include <stdexcept> // invalid_argument #endif @@ -19,16 +20,19 @@ import std.core; import std.io; #endif import butl.utility; // operator<<(ostream,exception), eof() +import butl.optional; import butl.standard_version; #else #include <libbutl/utility.mxx> +#include <libbutl/optional.mxx> #include <libbutl/standard-version.mxx> #endif using namespace std; using namespace butl; -// Create standard version from string, and also test another ctors. +// Return the standard version created from a string, and also perform some +// resulting version tests (check other constructors, invariants, etc.). // static standard_version version (const string& s, @@ -37,6 +41,8 @@ version (const string& s, { standard_version r (s, f); + // Test the other constructors. + // try { standard_version v (r.epoch, @@ -76,6 +82,8 @@ version (const string& s, assert (r == v); } + // Test using the resulting version with shortcut operators. + // if (!r.stub ()) { auto max_ver = [&v] (char c) -> string @@ -102,6 +110,29 @@ version (const string& s, assert (c1 == c2); } } + + // Check some invariants for the resulting version. + // + // Stub is not a final (pre-)release nor snapshot. + // + assert (!r.stub () || !(r.final () || r.snapshot ())); + + // Earliest is a final alpha. + // + assert (!r.earliest () || (r.final () && r.alpha ())); + + // Final is a release or a pre-release but not a snapshot. + // + assert (r.final () == + (r.release () || (r.pre_release () && !r.snapshot ()))); + + // Snapshot is a pre-release. + // + assert (!r.snapshot () || r.pre_release ()); + + // Pre-release is either alpha or beta. + // + assert (r.pre_release ().has_value () == (r.alpha () || r.beta ())); } catch (const invalid_argument& e) { @@ -114,18 +145,24 @@ version (const string& s, // Usages: // -// argv[0] -a <version> -// argv[0] -b <version> -// argv[0] -c <version> <version> -// argv[0] -r -// argv[0] -s <version> <constraint> +// argv[0] (-rl|-pr|-al|-bt|-st|-el|-sn|-fn) <version> +// argv[0] -cm <version> <version> +// argv[0] -cr +// argv[0] -sf <version> <constraint> // argv[0] // -// -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 -// -s output 'y' if version satisfies constraint, 'n' otherwise +// -rl output 'y' for release, 'n' otherwise +// -pr output DDD version part for pre-release, '-' otherwise +// -al output alpha version number for alpha-version, '-' otherwise +// -bt output beta version number for beta-version, '-' otherwise +// -st output 'y' for stub, 'n' otherwise +// -el output 'y' for earliest, 'n' otherwise +// -sn output 'y' for snapshot, 'n' otherwise +// -fn output 'y' for final, 'n' otherwise +// +// -cm output 0 if versions are equal, -1 if the first one is less, 1 otherwise +// -cr create version constraints from stdin lines, and print them to stdout +// -sf output 'y' if version satisfies constraint, 'n' otherwise // // If no options are specified, then create versions from stdin lines, and // print them to stdout. @@ -134,6 +171,8 @@ int main (int argc, char* argv[]) try { + using butl::optional; + cin.exceptions (ios::badbit); cout.exceptions (ios::failbit | ios::badbit); @@ -141,28 +180,66 @@ try { string o (argv[1]); - if (o == "-a") + if (o == "-rl") + { + assert (argc == 3); + cout << (version (argv[2]).release () ? 'y' : 'n') << endl; + } + else if (o == "-pr") { assert (argc == 3); - char r (version (argv[2]).alpha () ? 'y' : 'n'); - cout << r << endl; + if (optional<uint16_t> n = version (argv[2]).pre_release ()) + cout << *n << endl; + else + cout << '-' << endl; } - else if (o == "-b") + else if (o == "-al") { assert (argc == 3); - char r (version (argv[2]).beta () ? 'y' : 'n'); - cout << r << endl; + if (optional<uint16_t> n = version (argv[2]).alpha ()) + cout << *n << endl; + else + cout << '-' << endl; + } + else if (o == "-bt") + { + assert (argc == 3); + + if (optional<uint16_t> n = version (argv[2]).beta ()) + cout << *n << endl; + else + cout << '-' << endl; + } + else if (o == "-st") + { + assert (argc == 3); + cout << (version (argv[2]).stub () ? 'y' : 'n') << endl; + } + else if (o == "-el") + { + assert (argc == 3); + cout << (version (argv[2]).earliest () ? 'y' : 'n') << endl; + } + else if (o == "-sn") + { + assert (argc == 3); + cout << (version (argv[2]).snapshot () ? 'y' : 'n') << endl; + } + else if (o == "-fn") + { + assert (argc == 3); + cout << (version (argv[2]).final () ? 'y' : 'n') << endl; } - else if (o == "-c") + else if (o == "-cm") { assert (argc == 4); int r (version (argv[2]).compare (version (argv[3]))); cout << r << endl; } - else if (o == "-r") + else if (o == "-cr") { assert (argc == 2); @@ -170,7 +247,7 @@ try while (getline (cin, s)) cout << standard_version_constraint (s) << endl; } - else if (o == "-s") + else if (o == "-sf") { assert (argc == 4); |