summaryrefslogtreecommitdiff
path: root/Tests/LibSQL
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-09-22 08:35:47 -0400
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-10-14 17:47:44 +0330
commit7d41b46a7da8e8cbf624a28ba3841618ffa08f48 (patch)
tree36673878f391ef3fabcc54070a304c55ffbf2aae /Tests/LibSQL
parentaf3980384bf043ffaf81c82314324bfda5dfb6ff (diff)
downloadserenity-7d41b46a7da8e8cbf624a28ba3841618ffa08f48.zip
LibSQL: Remove infallible type conversions from SQL::Value
Force the callers to either know that the type is convertible, or to handle the conversion failure.
Diffstat (limited to 'Tests/LibSQL')
-rw-r--r--Tests/LibSQL/TestSqlBtreeIndex.cpp2
-rw-r--r--Tests/LibSQL/TestSqlHashIndex.cpp6
-rw-r--r--Tests/LibSQL/TestSqlValueAndTuple.cpp20
3 files changed, 12 insertions, 16 deletions
diff --git a/Tests/LibSQL/TestSqlBtreeIndex.cpp b/Tests/LibSQL/TestSqlBtreeIndex.cpp
index d38547762d..986998dda1 100644
--- a/Tests/LibSQL/TestSqlBtreeIndex.cpp
+++ b/Tests/LibSQL/TestSqlBtreeIndex.cpp
@@ -211,7 +211,7 @@ void insert_into_and_scan_btree(int num_keys)
if (prev.size()) {
EXPECT(prev < key);
}
- auto key_value = (int)key[0];
+ auto key_value = key[0].to_int();
for (auto ix = 0; ix < num_keys; ix++) {
if (keys[ix] == key_value) {
EXPECT_EQ(key.pointer(), pointers[ix]);
diff --git a/Tests/LibSQL/TestSqlHashIndex.cpp b/Tests/LibSQL/TestSqlHashIndex.cpp
index 7b47ad9d00..6425dbb4a9 100644
--- a/Tests/LibSQL/TestSqlHashIndex.cpp
+++ b/Tests/LibSQL/TestSqlHashIndex.cpp
@@ -268,12 +268,14 @@ void insert_into_and_scan_hash_index(int num_keys)
int count = 0;
for (auto iter = hash_index->begin(); !iter.is_end(); iter++, count++) {
auto key = (*iter);
- auto key_value = (int)key[0];
+ auto key_value = key[0].to_int();
+ VERIFY(key_value.has_value());
+
for (auto ix = 0; ix < num_keys; ix++) {
if (keys[ix] == key_value) {
EXPECT_EQ(key.pointer(), pointers[ix]);
if (found[ix])
- FAIL(String::formatted("Key {}, index {} already found previously", key_value, ix));
+ FAIL(String::formatted("Key {}, index {} already found previously", *key_value, ix));
found[ix] = true;
break;
}
diff --git a/Tests/LibSQL/TestSqlValueAndTuple.cpp b/Tests/LibSQL/TestSqlValueAndTuple.cpp
index df34af70bb..4d05530700 100644
--- a/Tests/LibSQL/TestSqlValueAndTuple.cpp
+++ b/Tests/LibSQL/TestSqlValueAndTuple.cpp
@@ -84,12 +84,6 @@ TEST_CASE(text_value_to_other_types)
}
}
-TEST_CASE(text_value_to_int_crash)
-{
- SQL::Value v(SQL::SQLType::Text, "Not a valid integer");
- EXPECT_CRASH("Can't convert 'Not a valid integer' to integer", [&]() { (void) (int) v; return Test::Crash::Failure::DidNotCrash; });
-}
-
TEST_CASE(serialize_text_value)
{
SQL::Value v("Test");
@@ -100,7 +94,7 @@ TEST_CASE(serialize_text_value)
serializer.rewind();
auto v2 = serializer.deserialize<SQL::Value>();
- EXPECT((String)v2 == "Test");
+ EXPECT(v2.to_string() == "Test");
}
TEST_CASE(integer_value)
@@ -226,14 +220,14 @@ TEST_CASE(assign_int_to_text_value)
{
SQL::Value text(SQL::SQLType::Text);
text = 42;
- EXPECT_EQ((String)text, "42");
+ EXPECT_EQ(text.to_string(), "42");
}
TEST_CASE(copy_value)
{
SQL::Value text(SQL::SQLType::Text, 42);
SQL::Value copy(text);
- EXPECT_EQ((String)copy, "42");
+ EXPECT_EQ(copy.to_string(), "42");
}
TEST_CASE(compare_text_to_int)
@@ -281,7 +275,7 @@ TEST_CASE(serialize_boolean_value)
{
SQL::Value v(true);
EXPECT_EQ(v.type(), SQL::SQLType::Boolean);
- EXPECT(bool(v));
+ EXPECT_EQ(v.to_bool(), true);
SQL::Serializer serializer;
serializer.serialize<SQL::Value>(v);
@@ -290,7 +284,7 @@ TEST_CASE(serialize_boolean_value)
auto v2 = serializer.deserialize<SQL::Value>();
EXPECT(!v2.is_null());
EXPECT_EQ(v2.type(), SQL::SQLType::Boolean);
- EXPECT(bool(v2));
+ EXPECT_EQ(v2.to_bool(), true);
EXPECT_EQ(v, v2);
}
@@ -508,8 +502,8 @@ TEST_CASE(serialize_tuple)
tuple["col1"] = "Test";
tuple["col2"] = 42;
- EXPECT_EQ((String)tuple[0], "Test");
- EXPECT_EQ((int)tuple[1], 42);
+ EXPECT_EQ(tuple[0], "Test");
+ EXPECT_EQ(tuple[1], 42);
SQL::Serializer serializer;
serializer.serialize<SQL::Tuple>(tuple);