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::indexing, "Indexing");
35 add(&PathTests::invalid_index, "Invalid index").expect_throw<invalid_argument>();
38 void PathTests::empty()
40 EXPECT(FS::Path().empty());
41 EXPECT(FS::Path("").empty());
42 EXPECT(!FS::Path(".").empty());
45 void PathTests::normalization()
48 EXPECT_EQUAL(path.str(), "./foo");
50 EXPECT_EQUAL(path.str(), "./foo");
52 EXPECT_EQUAL(path.str(), "./foo");
54 EXPECT_EQUAL(path.str(), ".");
56 EXPECT_EQUAL(path.str(), "/foo");
58 EXPECT_EQUAL(path.str(), "/");
61 void PathTests::concatenation()
65 EXPECT_EQUAL(path.str(), "./foo");
67 EXPECT_EQUAL(path.str(), "./foo");
69 EXPECT_EQUAL(path.str(), "./foo/bar");
71 EXPECT_EQUAL(path.str(), "./quux");
73 EXPECT_EQUAL(path.str(), "/");
75 EXPECT_EQUAL(path.str(), "/");
78 void PathTests::iterator_abs()
80 FS::Path path("/foo/bar");
81 FS::Path::Iterator iter = path.begin();
82 EXPECT(iter==path.begin());
83 EXPECT_EQUAL(*iter, "/");
85 EXPECT_EQUAL(*iter, "foo");
87 EXPECT_EQUAL(*iter, "bar");
89 EXPECT(iter==path.end());
92 void PathTests::iterator_rel()
94 FS::Path path("./foo");
95 FS::Path::Iterator iter = path.begin();
96 EXPECT(iter==path.begin());
97 EXPECT_EQUAL(*iter, ".");
99 EXPECT_EQUAL(*iter, "foo");
101 EXPECT(iter==path.end());
104 void PathTests::iterator_special()
107 EXPECT(path.begin()==path.end());
110 FS::Path::Iterator iter = path.begin();
111 EXPECT_EQUAL(*iter, ".");
113 EXPECT(iter==path.end());
117 EXPECT_EQUAL(*iter, "/");
119 EXPECT(iter==path.end());
122 void PathTests::indexing()
124 FS::Path path("/foo/bar");
125 EXPECT_EQUAL(path.size(), 3);
126 EXPECT_EQUAL(path[0], "/");
127 EXPECT_EQUAL(path[1], "foo");
128 EXPECT_EQUAL(path[-1], "bar");
131 void PathTests::invalid_index()
133 FS::Path path("foo");