diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-18 12:25:02 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-18 12:25:02 +0200 |
commit | dc65f9612e9feea1732572e8188d900495349059 (patch) | |
tree | 6fa08b0b919da7eda16280b469b99ac54eb8d3d1 /tests | |
parent | a9e2221dfddfbe26eebd6fca92a99be9e8ec1082 (diff) |
Move prefix-map from build2 to libbutl
Diffstat (limited to 'tests')
-rw-r--r-- | tests/buildfile | 7 | ||||
-rw-r--r-- | tests/prefix-map/buildfile | 7 | ||||
-rwxr-xr-x | tests/prefix-map/driver | bin | 0 -> 199753 bytes | |||
-rw-r--r-- | tests/prefix-map/driver.cxx | 153 |
4 files changed, 167 insertions, 0 deletions
diff --git a/tests/buildfile b/tests/buildfile new file mode 100644 index 0000000..19d85db --- /dev/null +++ b/tests/buildfile @@ -0,0 +1,7 @@ +# file : tests/buildfile +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +d = prefix-map/ +.: $d +include $d diff --git a/tests/prefix-map/buildfile b/tests/prefix-map/buildfile new file mode 100644 index 0000000..0fe9664 --- /dev/null +++ b/tests/prefix-map/buildfile @@ -0,0 +1,7 @@ +# file : tests/prefix-map/buildfile +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../butl/lib{butl} + +include ../../butl/ diff --git a/tests/prefix-map/driver b/tests/prefix-map/driver Binary files differnew file mode 100755 index 0000000..215146d --- /dev/null +++ b/tests/prefix-map/driver diff --git a/tests/prefix-map/driver.cxx b/tests/prefix-map/driver.cxx new file mode 100644 index 0000000..2aa59c7 --- /dev/null +++ b/tests/prefix-map/driver.cxx @@ -0,0 +1,153 @@ +// file : tests/prefix-map/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <string> +#include <cassert> +#include <iostream> + +#include <butl/prefix-map> + +using namespace std; +using namespace butl; + +int +main () +{ + typedef prefix_map<string, int, '.'> pm; + + { + const pm m; + + { + auto r (m.find_prefix ("")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("foo")); + assert (r.first == r.second); + } + } + + { + pm m {{{"foo", 1}}}; + + { + auto r (m.find_prefix ("")); + assert (r.first != r.second && r.first->second == 1 && + ++r.first == r.second); + } + + { + auto r (m.find_prefix ("fo")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("fox")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("fooo")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("foo.bar")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("foo")); + assert (r.first != r.second && r.first->second == 1 && + ++r.first == r.second); + } + } + + { + pm m {{{"foo", 1}, {"bar", 2}}}; + + { + auto r (m.find_prefix ("")); + assert (r.first != r.second && r.first->second == 2 && + ++r.first != r.second && r.first->second == 1 && + ++r.first == r.second); + } + + { + auto r (m.find_prefix ("fo")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("fox")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("fooo")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("foo.bar")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("foo")); + assert (r.first != r.second && r.first->second == 1 && + ++r.first == r.second); + } + + { + auto r (m.find_prefix ("bar")); + assert (r.first != r.second && r.first->second == 2 && + ++r.first == r.second); + } + } + + { + pm m ( + {{"boo", 1}, + {"foo", 2}, {"fooa", 3}, {"foo.bar", 4}, {"foo.fox", 5}, + {"xoo", 5}}); + + { + auto r (m.find_prefix ("fo")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("fox")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("fooo")); + assert (r.first == r.second); + } + + { + auto r (m.find_prefix ("foo.bar")); + assert (r.first != r.second && r.first->second == 4 && + ++r.first == r.second); + } + + { + auto r (m.find_prefix ("foo.fox")); + assert (r.first != r.second && r.first->second == 5 && + ++r.first == r.second); + } + + { + auto r (m.find_prefix ("foo")); + assert (r.first != r.second && r.first->second == 2 && + ++r.first != r.second && r.first->second == 4 && + ++r.first != r.second && r.first->second == 5 && + ++r.first == r.second); + } + } +} |