QMCPACK
test_hdf_path.cpp File Reference
+ Include dependency graph for test_hdf_path.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("hdf_path_constructor", "[hdf]")
 
 TEST_CASE ("hdf_path_append", "[hdf]")
 
 TEST_CASE ("hdf_path_concat", "[hdf]")
 
 TEST_CASE ("hdf_path_remove_path", "[hdf]")
 
 TEST_CASE ("hdf_path_replace_path", "[hdf]")
 
 TEST_CASE ("hdf_path_has_root_path", "[hdf]")
 

Function Documentation

◆ TEST_CASE() [1/6]

TEST_CASE ( "hdf_path_constructor"  ,
""  [hdf] 
)

Definition at line 17 of file test_hdf_path.cpp.

References qmcplusplus::REQUIRE(), and hdf_path::string().

18 {
19  auto gold_string("a/b/c");
20  const hdf_path gold_path(gold_string);
21  REQUIRE(gold_path.string() == gold_string);
22 
23  hdf_path path_sv(std::string_view{gold_string});
24  REQUIRE(path_sv.string() == gold_string);
25  REQUIRE(path_sv == gold_path);
26 
27  hdf_path path_s(std::string{gold_string});
28  REQUIRE(path_s.string() == gold_string);
29  REQUIRE(path_s == gold_path);
30 
31  hdf_path path_path(gold_path);
32  REQUIRE(path_path.string() == gold_string);
33  REQUIRE(path_path == gold_path);
34 }
REQUIRE(std::filesystem::exists(filename))

◆ TEST_CASE() [2/6]

TEST_CASE ( "hdf_path_append"  ,
""  [hdf] 
)

Definition at line 36 of file test_hdf_path.cpp.

References hdf_path::append(), qmcplusplus::REQUIRE(), and hdf_path::string().

37 {
38  hdf_path path;
39  REQUIRE(path.string().empty());
40  REQUIRE(path == hdf_path());
41 
42  path.append("a");
43  REQUIRE(path.string() == "a");
44  REQUIRE(path == hdf_path("a"));
45 
46  path /= "b";
47  REQUIRE(path.string() == "a/b");
48  REQUIRE(path == hdf_path("a/b"));
49 
50  hdf_path result = path / std::string_view("c");
51  REQUIRE(result.string() == "a/b/c");
52  REQUIRE(result == hdf_path("a/b/c"));
53 
54  result = path / std::string("c");
55  REQUIRE(result.string() == "a/b/c");
56  REQUIRE(result == hdf_path("a/b/c"));
57 
58  result = path / "c/";
59  REQUIRE(result.string() == "a/b/c/");
60  REQUIRE(result == hdf_path("a/b/c/"));
61 
62  result = result / "d";
63  REQUIRE(result.string() == "a/b/c/d");
64  REQUIRE(result == hdf_path("a/b/c/d"));
65 
66  result = path / "/c";
67  REQUIRE(result.string() == "/c");
68  REQUIRE(result == hdf_path("/c"));
69 
70  result /= hdf_path{"d"};
71  REQUIRE(result.string() == "/c/d");
72  REQUIRE(result == hdf_path("/c/d"));
73 }
const std::string & string() const
Return std::string for use with HDF5.
Definition: hdf_path.h:67
REQUIRE(std::filesystem::exists(filename))
hdf_path & append(std::string_view p)
Appends elements to the path with a directory separator.
Definition: hdf_path.cpp:20

◆ TEST_CASE() [3/6]

TEST_CASE ( "hdf_path_concat"  ,
""  [hdf] 
)

Definition at line 75 of file test_hdf_path.cpp.

References hdf_path::concat(), qmcplusplus::REQUIRE(), and hdf_path::string().

76 {
77  hdf_path path;
78  REQUIRE(path.string().empty());
79  REQUIRE(path == hdf_path());
80 
81  path.concat("a");
82  REQUIRE(path.string() == "a");
83  REQUIRE(path == hdf_path("a"));
84 
85  path += "b";
86  REQUIRE(path.string() == "ab");
87  REQUIRE(path == hdf_path("ab"));
88 
89  path += hdf_path{"c"};
90  REQUIRE(path.string() == "abc");
91  REQUIRE(path == hdf_path("abc"));
92 }
const std::string & string() const
Return std::string for use with HDF5.
Definition: hdf_path.h:67
REQUIRE(std::filesystem::exists(filename))
hdf_path & concat(std::string_view p)
Concatenates two paths without introducing a directory separator.
Definition: hdf_path.cpp:31

◆ TEST_CASE() [4/6]

TEST_CASE ( "hdf_path_remove_path"  ,
""  [hdf] 
)

Definition at line 94 of file test_hdf_path.cpp.

References hdf_path::remove_subgroup(), and qmcplusplus::REQUIRE().

95 {
96  hdf_path path("/a/b/c/d");
97  REQUIRE(path == hdf_path("/a/b/c/d"));
98 
99  path.remove_subgroup();
100  REQUIRE(path == hdf_path("/a/b/c"));
101 
102  path.remove_subgroup();
103  REQUIRE(path == hdf_path("/a/b"));
104 
105  path.remove_subgroup();
106  REQUIRE(path == hdf_path("/a"));
107 
108  path.remove_subgroup();
109  REQUIRE(path == hdf_path("/"));
110 
111  path.remove_subgroup();
112  REQUIRE(path == hdf_path("/"));
113 
114  hdf_path relative_path("a/b/c/d");
115  REQUIRE(relative_path == hdf_path("a/b/c/d"));
116 
117  relative_path.remove_subgroup();
118  REQUIRE(relative_path == hdf_path("a/b/c"));
119 
120  relative_path.remove_subgroup();
121  REQUIRE(relative_path == hdf_path("a/b"));
122 
123  relative_path.remove_subgroup();
124  REQUIRE(relative_path == hdf_path("a"));
125 
126  relative_path.remove_subgroup();
127  REQUIRE(relative_path == hdf_path(""));
128 
129  relative_path.remove_subgroup();
130  REQUIRE(relative_path == hdf_path(""));
131 }
REQUIRE(std::filesystem::exists(filename))

◆ TEST_CASE() [5/6]

TEST_CASE ( "hdf_path_replace_path"  ,
""  [hdf] 
)

Definition at line 133 of file test_hdf_path.cpp.

References hdf_path::replace_subgroup(), and qmcplusplus::REQUIRE().

134 {
135  hdf_path path("/a/b");
136  REQUIRE(path == hdf_path("/a/b"));
137 
138  path.replace_subgroup("c");
139  REQUIRE(path == hdf_path("/a/c"));
140 
141  path.replace_subgroup(std::string{"de"});
142  REQUIRE(path == hdf_path("/a/de"));
143 
144  path.replace_subgroup(std::string_view{"fs"});
145  REQUIRE(path == hdf_path("/a/fs"));
146 }
REQUIRE(std::filesystem::exists(filename))

◆ TEST_CASE() [6/6]

TEST_CASE ( "hdf_path_has_root_path"  ,
""  [hdf] 
)

Definition at line 148 of file test_hdf_path.cpp.

References hdf_path::has_root_directory(), and qmcplusplus::REQUIRE().

149 {
150  hdf_path root_path("/a/b");
151  REQUIRE(root_path.has_root_directory());
152 
153  hdf_path relative_path("a/b");
154  REQUIRE(!relative_path.has_root_directory());
155 }
REQUIRE(std::filesystem::exists(filename))