1 | #include "catch.hpp" |
2 | #include "test_helpers.hpp" |
3 | |
4 | using namespace duckdb; |
5 | using namespace std; |
6 | |
7 | TEST_CASE("Test unicode strings" , "[unicode]" ) { |
8 | unique_ptr<QueryResult> result; |
9 | DuckDB db(nullptr); |
10 | Connection con(db); |
11 | |
12 | // insert unicode strings into the database |
13 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE emojis(id INTEGER, s VARCHAR);" )); |
14 | REQUIRE_NO_FAIL(con.Query("INSERT INTO emojis VALUES (1, '🦆'), (2, '🦆🍞🦆')" )); |
15 | |
16 | // retrieve unicode strings again |
17 | result = con.Query("SELECT * FROM emojis ORDER BY id" ); |
18 | REQUIRE(CHECK_COLUMN(result, 0, {1, 2})); |
19 | REQUIRE(CHECK_COLUMN(result, 1, {"🦆" , "🦆🍞🦆" })); |
20 | |
21 | // substring on emojis |
22 | result = con.Query("SELECT substring(s, 1, 1), substring(s, 2, 1) FROM emojis ORDER BY id" ); |
23 | REQUIRE(CHECK_COLUMN(result, 0, {"🦆" , "🦆" })); |
24 | REQUIRE(CHECK_COLUMN(result, 1, {"" , "🍞" })); |
25 | |
26 | // length on emojis |
27 | result = con.Query("SELECT length(s) FROM emojis ORDER BY id" ); |
28 | REQUIRE(CHECK_COLUMN(result, 0, {1, 3})); |
29 | } |
30 | |