1 #include <msp/fs/path.h>
2 #include <msp/test/test.h>
7 class PathTests: public Test::RegisteredTest<PathTests>
12 static const char *get_name() { return "Path"; }
20 void iterator_special();
21 void invalid_iterator();
26 PathTests::PathTests()
28 add(&PathTests::empty, "Emptiness");
29 add(&PathTests::normalization, "Normalization");
30 add(&PathTests::concatenation, "Concatenation");
31 add(&PathTests::iterator_abs, "Iterator (absolute path)");
32 add(&PathTests::iterator_rel, "Iterator (relative path)");
33 add(&PathTests::iterator_special, "Iterator (special cases)");
34 add(&PathTests::invalid_iterator, "Invalid iterator").expect_throw<logic_error>();
35 add(&PathTests::indexing, "Indexing");
36 add(&PathTests::invalid_index, "Invalid index").expect_throw<invalid_argument>();
39 void PathTests::empty()
41 EXPECT(FS::Path().empty());
42 EXPECT(FS::Path("").empty());
43 EXPECT(!FS::Path(".").empty());
46 void PathTests::normalization()
49 EXPECT_EQUAL(path.str(), "./foo");
51 EXPECT_EQUAL(path.str(), "./foo");
53 EXPECT_EQUAL(path.str(), "./foo");
55 EXPECT_EQUAL(path.str(), ".");
57 EXPECT_EQUAL(path.str(), "/foo");
59 EXPECT_EQUAL(path.str(), "/");
62 void PathTests::concatenation()
66 EXPECT_EQUAL(path.str(), "./foo");
68 EXPECT_EQUAL(path.str(), "./foo");
70 EXPECT_EQUAL(path.str(), "./foo/bar");
72 EXPECT_EQUAL(path.str(), "./quux");
74 EXPECT_EQUAL(path.str(), "/");
76 EXPECT_EQUAL(path.str(), "/");
79 void PathTests::iterator_abs()
81 FS::Path path("/foo/bar");
82 FS::Path::Iterator iter = path.begin();
83 EXPECT(iter==path.begin());
84 EXPECT_EQUAL(*iter, "/");
86 EXPECT_EQUAL(*iter, "foo");
88 EXPECT_EQUAL(*iter, "bar");
90 EXPECT(iter==path.end());
93 void PathTests::iterator_rel()
95 FS::Path path("./foo");
96 FS::Path::Iterator iter = path.begin();
97 EXPECT(iter==path.begin());
98 EXPECT_EQUAL(*iter, ".");
100 EXPECT_EQUAL(*iter, "foo");
102 EXPECT(iter==path.end());
105 void PathTests::iterator_special()
108 EXPECT(path.begin()==path.end());
111 FS::Path::Iterator iter = path.begin();
112 EXPECT_EQUAL(*iter, ".");
114 EXPECT(iter==path.end());
118 EXPECT_EQUAL(*iter, "/");
120 EXPECT(iter==path.end());
123 void PathTests::invalid_iterator()
125 FS::Path path("foo");
129 void PathTests::indexing()
131 FS::Path path("/foo/bar");
132 EXPECT_EQUAL(path.size(), 3);
133 EXPECT_EQUAL(path[0], "/");
134 EXPECT_EQUAL(path[1], "foo");
135 EXPECT_EQUAL(path[-1], "bar");
138 void PathTests::invalid_index()
140 FS::Path path("foo");