aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/small-forward-list/buildfile8
-rw-r--r--tests/small-forward-list/driver.cxx164
-rw-r--r--tests/small-list/buildfile8
-rw-r--r--tests/small-list/driver.cxx162
-rw-r--r--tests/small-vector/driver.cxx3
5 files changed, 343 insertions, 2 deletions
diff --git a/tests/small-forward-list/buildfile b/tests/small-forward-list/buildfile
new file mode 100644
index 0000000..8a6c7d6
--- /dev/null
+++ b/tests/small-forward-list/buildfile
@@ -0,0 +1,8 @@
+# file : tests/small-forward-list/buildfile
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import libs = libbutl%lib{butl}
+libs += $stdmod_lib
+
+exe{driver}: {hxx cxx}{*} $libs
diff --git a/tests/small-forward-list/driver.cxx b/tests/small-forward-list/driver.cxx
new file mode 100644
index 0000000..e6fc717
--- /dev/null
+++ b/tests/small-forward-list/driver.cxx
@@ -0,0 +1,164 @@
+// file : tests/small-forward-list/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <cassert>
+
+#ifndef __cpp_lib_modules
+#include <string>
+#include <iostream>
+#endif
+
+// Other includes.
+
+#ifdef __cpp_modules
+#ifdef __cpp_lib_modules
+import std.core;
+import std.io;
+#endif
+import butl.small_forward_list;
+#else
+#include <libbutl/small-forward-list.mxx>
+#endif
+
+using namespace std;
+using namespace butl;
+
+// Return true if the data is stored entirely inside l.
+//
+template <typename T, size_t N>
+inline bool
+small (const small_forward_list<T, N>& l)
+{
+ for (const T& x: l)
+ {
+ const void* p (&x);
+
+ if (p < &l || p >= (&l + 1))
+ return false;
+ }
+
+ return true;
+}
+
+template <typename T, size_t N>
+inline const T&
+front (const small_forward_list<T, N>& l)
+{
+ return l.front ();
+}
+
+template <typename T, size_t N>
+inline const T&
+back (const small_forward_list<T, N>& l)
+{
+ auto i (l.begin ());;
+ for (auto j (i); ++j != l.end (); ) i = j;
+ return *i;
+}
+
+int
+main ()
+{
+ using list = small_forward_list<string, 1>;
+
+ {
+ list l;
+
+ l.push_front ("abc");
+ assert (front (l) == "abc" && small (l));
+
+ l.push_front ("ABC");
+ assert (front (l) == "ABC" && back (l) == "abc" && !small (l));
+
+ l.pop_front ();
+ assert (front (l) == "abc" && small (l));
+
+ l.push_front ("ABC");
+ l.reverse ();
+ l.pop_front ();
+ assert (front (l) == "ABC" && !small (l));
+
+ l.push_front ("abc");
+ l.reverse ();
+ l.pop_front ();
+ assert (front (l) == "abc" && small (l));
+
+ l.clear ();
+ l.push_front ("abc");
+ assert (front (l) == "abc" && small (l));
+ }
+
+ // Copy constructor.
+ //
+ {
+ list s1 ({"abc"}), s2 (s1);
+ assert (s1 == s2 && small (s2));
+
+ list l1 ({"abc", "ABC"}), l2 (l1);
+ assert (l1 == l2 && !small (l2));
+ }
+
+ // Move constructor.
+ //
+ {
+ struct mstring: string // Move-only string.
+ {
+ mstring () = default;
+ explicit mstring (const char* s): string (s) {}
+
+ mstring (mstring&&) = default;
+ mstring& operator= (mstring&&) = default;
+
+ mstring (const mstring&) = delete;
+ mstring& operator= (const mstring&) = delete;
+ };
+
+ using list = small_forward_list<mstring, 1>;
+
+ {
+ list s1;
+ s1.emplace_front ("abc");
+ list s2 (move (s1));
+ assert (front (s2) == "abc" && small (s2));
+ }
+
+ {
+ list l1;
+ l1.emplace_front ("ABC");
+ l1.emplace_front ("abc");
+ list l2 (move (l1));
+ assert (front (l2) == "abc" && back (l2) == "ABC" && !small (l2));
+ }
+ }
+
+ // Other constructors.
+ //
+
+ {
+ const char* sa[] = {"abc"};
+ const char* la[] = {"abc", "ABC"};
+
+ list s (sa, sa + 1);
+ assert (front (s) == "abc" && small (s));
+
+ list l (la, la + 2);
+ assert (front (l) == "abc" && back (l) == "ABC" && !small (l));
+ }
+
+ {
+ list s (1, "abc");
+ assert (front (s) == "abc" && small (s));
+
+ list l (3, "abc");
+ assert (front (l) == "abc" && back (l) == "abc" && !small (l));
+ }
+
+ {
+ list s (1);
+ assert (s.front () == "" && small (s));
+
+ list l (3);
+ assert (front (l) == "" && back (l) == "" && !small (l));
+ }
+}
diff --git a/tests/small-list/buildfile b/tests/small-list/buildfile
new file mode 100644
index 0000000..02a87ad
--- /dev/null
+++ b/tests/small-list/buildfile
@@ -0,0 +1,8 @@
+# file : tests/small-list/buildfile
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+import libs = libbutl%lib{butl}
+libs += $stdmod_lib
+
+exe{driver}: {hxx cxx}{*} $libs
diff --git a/tests/small-list/driver.cxx b/tests/small-list/driver.cxx
new file mode 100644
index 0000000..970adc3
--- /dev/null
+++ b/tests/small-list/driver.cxx
@@ -0,0 +1,162 @@
+// file : tests/small-list/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <cassert>
+
+#ifndef __cpp_lib_modules
+#include <string>
+#include <iostream>
+#endif
+
+// Other includes.
+
+#ifdef __cpp_modules
+#ifdef __cpp_lib_modules
+import std.core;
+import std.io;
+#endif
+import butl.small_list;
+#else
+#include <libbutl/small-list.mxx>
+#endif
+
+using namespace std;
+using namespace butl;
+
+// Return true if the data is stored entirely inside l.
+//
+template <typename T, size_t N>
+inline bool
+small (const small_list<T, N>& l)
+{
+ // In VC it is always "large" (see note in small_list) so we omit this
+ // test.
+ //
+#ifndef _MSC_VER
+ for (const T& x: l)
+ {
+ const void* p (&x);
+
+ if (p < &l || p >= (&l + 1))
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+template <typename T, size_t N>
+inline bool
+large (const small_list<T, N>& l)
+{
+#ifndef _MSC_VER
+ return !small (l);
+#else
+ return true;
+#endif
+}
+
+int
+main ()
+{
+ using list = small_list<string, 1>;
+
+ {
+ list l;
+
+ l.push_back ("abc");
+ assert (l.front () == "abc" && small (l));
+
+ l.push_back ("ABC");
+ assert (l.front () == "abc" && l.back () == "ABC" && large (l));
+
+ l.pop_back ();
+ assert (l.front () == "abc" && small (l));
+
+ l.push_back ("ABC");
+ l.pop_front ();
+ assert (l.front () == "ABC" && large (l));
+
+ l.push_back ("abc");
+ l.pop_front ();
+ assert (l.front () == "abc" && small (l));
+
+ l.clear ();
+ l.push_back ("abc");
+ assert (l.front () == "abc" && small (l));
+ }
+
+ // Copy constructor.
+ //
+ {
+ list s1 ({"abc"}), s2 (s1);
+ assert (s1 == s2 && small (s2));
+
+ list l1 ({"abc", "ABC"}), l2 (l1);
+ assert (l1 == l2 && large (l2));
+ }
+
+ // Move constructor.
+ //
+ {
+ struct mstring: string // Move-only string.
+ {
+ mstring () = default;
+ explicit mstring (const char* s): string (s) {}
+
+ mstring (mstring&&) = default;
+ mstring& operator= (mstring&&) = default;
+
+ mstring (const mstring&) = delete;
+ mstring& operator= (const mstring&) = delete;
+ };
+
+ using list = small_list<mstring, 1>;
+
+ {
+ list s1;
+ s1.emplace_back ("abc");
+ list s2 (move (s1));
+ assert (s2.front () == "abc" && small (s2));
+ }
+
+ {
+ list l1;
+ l1.emplace_back ("abc");
+ l1.emplace_back ("ABC");
+ list l2 (move (l1));
+ assert (l2.front () == "abc" && l2.back () == "ABC" && large (l2));
+ }
+ }
+
+ // Other constructors.
+ //
+
+ {
+ const char* sa[] = {"abc"};
+ const char* la[] = {"abc", "ABC"};
+
+ list s (sa, sa + 1);
+ assert (s.front () == "abc" && small (s));
+
+ list l (la, la + 2);
+ assert (l.front () == "abc" && l.back () == "ABC" && large (l));
+ }
+
+ {
+ list s (1, "abc");
+ assert (s.front () == "abc" && small (s));
+
+ list l (3, "abc");
+ assert (l.front () == "abc" && l.back () == "abc" && large (l));
+ }
+
+ {
+ list s (1);
+ assert (s.front () == "" && small (s));
+
+ list l (3);
+ assert (l.front () == "" && l.back () == "" && large (l));
+ }
+}
diff --git a/tests/small-vector/driver.cxx b/tests/small-vector/driver.cxx
index fe386a4..a9f1584 100644
--- a/tests/small-vector/driver.cxx
+++ b/tests/small-vector/driver.cxx
@@ -6,7 +6,6 @@
#ifndef __cpp_lib_modules
#include <string>
-#include <vector>
#include <iostream>
#endif
@@ -25,7 +24,7 @@ import butl.small_vector;
using namespace std;
using namespace butl;
-// Return if v.data() points to somewhere inside v.
+// Return true if v.data() points to somewhere inside v.
//
template <typename T, size_t N>
inline bool