From c2339b07fb683355c6a6155ec312b1616167614e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 14 Jan 2015 11:46:32 +0200 Subject: Implement prefix_map --- tests/build/prefix_map/buildfile | 2 + tests/build/prefix_map/driver.cxx | 156 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 tests/build/prefix_map/buildfile create mode 100644 tests/build/prefix_map/driver.cxx (limited to 'tests') diff --git a/tests/build/prefix_map/buildfile b/tests/build/prefix_map/buildfile new file mode 100644 index 0000000..dbef7db --- /dev/null +++ b/tests/build/prefix_map/buildfile @@ -0,0 +1,2 @@ +exe{driver}: obj{driver} +obj{driver}: cxx{driver} diff --git a/tests/build/prefix_map/driver.cxx b/tests/build/prefix_map/driver.cxx new file mode 100644 index 0000000..ba9478c --- /dev/null +++ b/tests/build/prefix_map/driver.cxx @@ -0,0 +1,156 @@ +// file : tests/build/prefix_map/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include + +#include + +using namespace std; +using namespace build; + +int +main () +{ + typedef prefix_map pm; + + { + const pm m ('.'); + + { + auto r (m.find ("")); + assert (r.first == r.second); + } + + { + auto r (m.find ("foo")); + assert (r.first == r.second); + } + } + + { + pm m {{{"foo", 1}}, '.'}; + + { + auto r (m.find ("")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fo")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fox")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fooo")); + assert (r.first == r.second); + } + + { + auto r (m.find ("foo.bar")); + assert (r.first == r.second); + } + + { + auto r (m.find ("foo")); + assert (r.first != r.second && r.first->second == 1 && + ++r.first == r.second); + } + } + + { + pm m {{{"foo", 1}, {"bar", 2}}, '.'}; + + { + auto r (m.find ("")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fo")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fox")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fooo")); + assert (r.first == r.second); + } + + { + auto r (m.find ("foo.bar")); + assert (r.first == r.second); + } + + { + auto r (m.find ("foo")); + assert (r.first != r.second && r.first->second == 1 && + ++r.first == r.second); + } + + { + auto r (m.find ("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 ("")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fo")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fox")); + assert (r.first == r.second); + } + + { + auto r (m.find ("fooo")); + assert (r.first == r.second); + } + + { + auto r (m.find ("foo.bar")); + assert (r.first != r.second && r.first->second == 4 && + ++r.first == r.second); + } + + { + auto r (m.find ("foo.fox")); + assert (r.first != r.second && r.first->second == 5 && + ++r.first == r.second); + } + + { + auto r (m.find ("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); + } + } +} -- cgit v1.1