Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/UsageTests/ToStringVector.tests.cpp
diff options
context:
space:
mode:
authorPhil Nash2017-11-13 16:03:27 +0000
committerPhil Nash2017-11-13 16:03:27 +0000
commit74d3dfd4cc45088f3f7ab82c2168dbfd43cb048c (patch)
tree7f72dafe4a3f23c565977dee9838d6cc26e52848 /projects/SelfTest/UsageTests/ToStringVector.tests.cpp
parente34754e4331ef5b161555495d13549a2a13f81b2 (diff)
downloadcatch3-74d3dfd4cc45088f3f7ab82c2168dbfd43cb048c.tar.gz
All tests files have .tests.cpp suffix. Also moved tests out of TestMain.cpp and moved up a level
Diffstat (limited to 'projects/SelfTest/UsageTests/ToStringVector.tests.cpp')
-rw-r--r--projects/SelfTest/UsageTests/ToStringVector.tests.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/projects/SelfTest/UsageTests/ToStringVector.tests.cpp b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp
new file mode 100644
index 00000000..df9c55ab
--- /dev/null
+++ b/projects/SelfTest/UsageTests/ToStringVector.tests.cpp
@@ -0,0 +1,68 @@
+#include "catch.hpp"
+#include <vector>
+
+
+// vedctor
+TEST_CASE( "vector<int> -> toString", "[toString][vector]" )
+{
+ std::vector<int> vv;
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ }" );
+ vv.push_back( 42 );
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ 42 }" );
+ vv.push_back( 250 );
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ 42, 250 }" );
+}
+
+TEST_CASE( "vector<string> -> toString", "[toString][vector]" )
+{
+ std::vector<std::string> vv;
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ }" );
+ vv.push_back( "hello" );
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\" }" );
+ vv.push_back( "world" );
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ \"hello\", \"world\" }" );
+}
+
+namespace {
+ /* Minimal Allocator */
+ template<typename T>
+ struct minimal_allocator {
+ using value_type = T;
+ using size_type = std::size_t;
+
+ minimal_allocator() = default;
+ template <typename U>
+ minimal_allocator(const minimal_allocator<U>&) {}
+
+
+ T *allocate( size_type n ) {
+ return static_cast<T *>( ::operator new( n * sizeof(T) ) );
+ }
+ void deallocate( T *p, size_type /*n*/ ) {
+ ::operator delete( static_cast<void *>(p) );
+ }
+ template<typename U>
+ bool operator==( const minimal_allocator<U>& ) const { return true; }
+ template<typename U>
+ bool operator!=( const minimal_allocator<U>& ) const { return false; }
+ };
+}
+
+TEST_CASE( "vector<int,allocator> -> toString", "[toString][vector,allocator]" ) {
+ std::vector<int,minimal_allocator<int> > vv;
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ }" );
+ vv.push_back( 42 );
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ 42 }" );
+ vv.push_back( 250 );
+ REQUIRE( ::Catch::Detail::stringify(vv) == "{ 42, 250 }" );
+}
+
+TEST_CASE( "vec<vec<string,alloc>> -> toString", "[toString][vector,allocator]" ) {
+ using inner = std::vector<std::string, minimal_allocator<std::string>>;
+ using vector = std::vector<inner>;
+ vector v;
+ REQUIRE( ::Catch::Detail::stringify(v) == "{ }" );
+ v.push_back( inner { "hello" } );
+ v.push_back( inner { "world" } );
+ REQUIRE( ::Catch::Detail::stringify(v) == "{ { \"hello\" }, { \"world\" } }" );
+}