aboutsummaryrefslogtreecommitdiff
path: root/tests/project-name/driver.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-07-25 20:11:47 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-07-25 20:22:33 +0300
commit84f6ebab62a9f2553ae454d67861b0b142470d0b (patch)
tree63d41dc772ebcaf6f1821de3b155cadd90d309dc /tests/project-name/driver.cxx
parent35e9273090109e5fb87fe65e3f1631ff6fc5fb3a (diff)
Move bpkg::package_name class to butl::project_name
Diffstat (limited to 'tests/project-name/driver.cxx')
-rw-r--r--tests/project-name/driver.cxx84
1 files changed, 84 insertions, 0 deletions
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 <cassert>
+
+#ifndef __cpp_lib_modules
+#include <ios> // ios::*bit
+#include <string>
+#include <iostream>
+#include <stdexcept> // 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 <libbutl/utility.mxx>
+#include <libbutl/project-name.mxx>
+#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;
+}