Skip to content

Commit c03e4e8

Browse files
committed
Add tests from string_view
1 parent 7d6ea22 commit c03e4e8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/string_view.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <sqlite_modern_cpp.h>
4+
#include <catch.hpp>
5+
6+
7+
#ifdef MODERN_SQLITE_STRINGVIEW_SUPPORT
8+
#include <string_view>
9+
10+
using namespace sqlite;
11+
using namespace std;
12+
TEST_CASE("std::string_view works", "[string_view]") {
13+
database db(":memory:");;
14+
db << "CREATE TABLE foo (a integer, b string);\n";
15+
const std::string_view test1 = "null terminated string view";
16+
db << "INSERT INTO foo VALUES (?, ?)" << 1 << test1;
17+
std::string str;
18+
db << "SELECT b from FOO where a=?;" << 1 >> str;
19+
REQUIRE(test1 == str);
20+
const char s[] = "hello world";
21+
std::string_view test2(&s[0], 2);
22+
db << "INSERT INTO foo VALUES (?,?)" << 2 << test2;
23+
db << "SELECT b from FOO where a=?" << 2 >> str;
24+
REQUIRE(str == "he");
25+
}
26+
#endif

0 commit comments

Comments
 (0)