1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibSQL: Add parsing and evaluation of BOOLEAN type literals

This allows you to enter TRUE or FALSE in a SQL statement for BOOLEAN
types. Note that this differs from SQLite, which requires entering 1 or
0 for BOOLEANs; having explicit keywords feels a bit more natural.
This commit is contained in:
Timothy Flynn 2022-12-31 09:28:09 -05:00 committed by Sam Atkins
parent c67c7dd1f2
commit 41e0e4cdd7
5 changed files with 43 additions and 0 deletions

View file

@ -118,6 +118,23 @@ TEST_CASE(blob_literal)
validate("x'DEADC0DE'"sv, "DEADC0DE"sv);
}
TEST_CASE(boolean_literal)
{
auto validate = [](StringView sql, bool expected_value) {
auto result = parse(sql);
EXPECT(!result.is_error());
auto expression = result.release_value();
EXPECT(is<SQL::AST::BooleanLiteral>(*expression));
auto const& literal = static_cast<SQL::AST::BooleanLiteral const&>(*expression);
EXPECT_EQ(literal.value(), expected_value);
};
validate("TRUE"sv, true);
validate("FALSE"sv, false);
}
TEST_CASE(null_literal)
{
auto validate = [](StringView sql) {