1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// file : libbuild2/name.test.cxx -*- C++ -*-
// license : MIT; see accompanying LICENSE file
#include <sstream>
#include <iostream>
#include <libbuild2/types.hxx> // Includes name.
#include <libbuild2/utility.hxx>
#include <libbuild2/diagnostics.hxx>
#undef NDEBUG
#include <cassert>
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, quote_mode quote = quote_mode::normal)
{
ostringstream os;
stream_verb (os, stream_verbosity (0, 1));
to_stream (os, n, quote);
return os.str ();
};
assert (ts (name ()) == "''");
assert (ts (name (), quote_mode::none) == "{}");
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}");
// Normal quoting.
//
assert (ts (name (dir ("bar baz/"), "dir", "foo fox")) == "'bar baz/'dir{'foo fox'}");
// Effective quoting.
//
assert (ts (name ("bar\\baz"), quote_mode::effective) == "bar\\baz");
assert (ts (name ("bar[baz]"), quote_mode::effective) == "bar[baz]");
assert (ts (name ("bar$baz"), quote_mode::effective) == "'bar$baz'");
assert (ts (name ("bar\\\\baz"), quote_mode::effective) == "'bar\\\\baz'");
assert (ts (name ("bar\\$baz"), quote_mode::effective) == "'bar\\$baz'");
// 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);
}
|