aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/name/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-12-16 12:00:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-12-16 12:00:53 +0200
commit44e1022f8141bd57756c2be4277c728ca7443eb3 (patch)
tree4b3d7e4be8c79d00acc52aec7f1cf64d184f9f73 /unit-tests/name/driver.cxx
parent497353a7eeec26d35741afd45b7cd759105f0246 (diff)
Redo string/stream representation of dir{} name/target
Now instead of: dir{foo/bar/} We get: foo/dir{bar/} Which feels more consistent with how we print other names/targets. That is, "directory bar/ in directory foo/" similar how foo/exe{bar} is "executable bar in directory foo/".
Diffstat (limited to 'unit-tests/name/driver.cxx')
-rw-r--r--unit-tests/name/driver.cxx96
1 files changed, 96 insertions, 0 deletions
diff --git a/unit-tests/name/driver.cxx b/unit-tests/name/driver.cxx
new file mode 100644
index 0000000..d454685
--- /dev/null
+++ b/unit-tests/name/driver.cxx
@@ -0,0 +1,96 @@
+// file : unit-tests/name/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <sstream>
+
+#include <cassert>
+#include <iostream>
+
+#include <build2/types.hxx> // Includes name.
+#include <build2/utility.hxx>
+
+#include <build2/diagnostics.hxx>
+
+using namespace std;
+
+namespace build2
+{
+ int
+ main (int, char*[])
+ {
+ using dir = dir_path;
+
+ // Test string representation.
+ //
+ {
+ auto ts = [] (const name& n) {return to_string (n);};
+
+ assert (ts (name ()) == "");
+
+ assert (ts (name ("foo")) == "foo");
+
+ assert (ts (name (dir ("bar/"))) == "bar/");
+ assert (ts (name (dir ("bar/baz/"))) == "bar/baz/");
+
+ assert (ts (name (dir ("bar/"), "dir", "")) == "dir{bar/}");
+ assert (ts (name (dir ("bar/baz/"), "dir", "")) == "bar/dir{baz/}");
+
+ assert (ts (name (dir ("bar/"), "foo")) == "bar/foo");
+
+ assert (ts (name (dir ("bar/"), "dir", "foo")) == "bar/dir{foo}");
+ assert (ts (name (dir ("bar/baz/"), "dir", "foo")) == "bar/baz/dir{foo}");
+ }
+
+ // Test stream representation.
+ //
+ {
+ auto ts = [] (const name& n, bool quote = true)
+ {
+ ostringstream os;
+ stream_verb (os, 1);
+ to_stream (os, n, quote);
+ return os.str ();
+ };
+
+ assert (ts (name ()) == "''");
+ assert (ts (name (), false) == "{}");
+
+ assert (ts (name ("foo")) == "foo");
+
+ assert (ts (name (dir ("bar/"))) == "bar/");
+ assert (ts (name (dir ("bar/baz/"))) == "bar/baz/");
+
+ assert (ts (name (dir ("bar/"), "dir", "")) == "dir{bar/}");
+ assert (ts (name (dir ("bar/baz/"), "dir", "")) == "bar/dir{baz/}");
+
+ assert (ts (name (dir ("bar/"), "foo")) == "bar/foo");
+
+ assert (ts (name (dir ("bar/"), "dir", "foo")) == "bar/dir{foo}");
+ assert (ts (name (dir ("bar/baz/"), "dir", "foo")) == "bar/baz/dir{foo}");
+
+ // Quoting.
+ //
+ assert (ts (name (dir ("bar baz/"), "dir", "foo fox")) == "'bar baz/'dir{'foo fox'}");
+
+ // Relative logic.
+ //
+#ifndef _WIN32
+ dir rb ("/bar/");
+ relative_base = &rb;
+
+ assert (ts (name (dir ("/bar/"), "dir", "")) == "dir{./}");
+ assert (ts (name (dir ("/bar/"), "", "foo")) == "foo");
+ assert (ts (name (dir ("/bar/baz/"), "dir", "")) == "dir{baz/}");
+#endif
+ }
+
+ return 0;
+ }
+}
+
+int
+main (int argc, char* argv[])
+{
+ return build2::main (argc, argv);
+}