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(), "/");
58 EXPECT_EQUAL(path.str(), "/foo");
60 EXPECT_EQUAL(path.str(), "/");
63 void PathTests::concatenation()
67 EXPECT_EQUAL(path.str(), "./foo");
69 EXPECT_EQUAL(path.str(), "./foo");
71 EXPECT_EQUAL(path.str(), "./foo/bar");
73 EXPECT_EQUAL(path.str(), "./quux");
75 EXPECT_EQUAL(path.str(), "/");
77 EXPECT_EQUAL(path.str(), "/");
80 void PathTests::iterator_abs()
82 FS::Path path("/foo/bar");
83 FS::Path::Iterator iter = path.begin();
84 EXPECT(iter==path.begin());
85 EXPECT_EQUAL(*iter, "/");
87 EXPECT_EQUAL(*iter, "foo");
89 EXPECT_EQUAL(*iter, "bar");
91 EXPECT(iter==path.end());
94 void PathTests::iterator_rel()
96 FS::Path path("./foo");
97 FS::Path::Iterator iter = path.begin();
98 EXPECT(iter==path.begin());
99 EXPECT_EQUAL(*iter, ".");
101 EXPECT_EQUAL(*iter, "foo");
103 EXPECT(iter==path.end());
106 void PathTests::iterator_special()
109 EXPECT(path.begin()==path.end());
112 FS::Path::Iterator iter = path.begin();
113 EXPECT_EQUAL(*iter, ".");
115 EXPECT(iter==path.end());
119 EXPECT_EQUAL(*iter, "/");
121 EXPECT(iter==path.end());
124 void PathTests::indexing()
126 FS::Path path("/foo/bar");
127 EXPECT_EQUAL(path.size(), 3);
128 EXPECT_EQUAL(path[0], "/");
129 EXPECT_EQUAL(path[1], "foo");
130 EXPECT_EQUAL(path[-1], "bar");
133 void PathTests::invalid_index()
135 FS::Path path("foo");