1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00

AK: Add tests for GenericShorthands

This commit is contained in:
Ivan Zuzak 2025-01-07 16:04:26 +01:00 committed by Jelle Raaijmakers
parent e469c884d4
commit 49fc569136
Notes: github-actions[bot] 2025-01-09 08:04:56 +00:00
3 changed files with 258 additions and 0 deletions

View file

@ -32,6 +32,7 @@ tests = [
"TestFlyString",
"TestFormat",
"TestGenericLexer",
"TestGenericShorthands",
"TestHashFunctions",
"TestHashMap",
"TestHashTable",

View file

@ -30,6 +30,7 @@ set(AK_TEST_SOURCES
TestFlyString.cpp
TestFormat.cpp
TestGenericLexer.cpp
TestGenericShorthands.cpp
TestHashFunctions.cpp
TestHashMap.cpp
TestHashTable.cpp

View file

@ -0,0 +1,256 @@
/*
* Copyright (c) 2025, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestCase.h>
#include <AK/GenericShorthands.h>
TEST_CASE(first_is_one_of)
{
// Finds item if in list of arguments
static_assert(first_is_one_of(3, 1, 2, 3, 4, 5));
EXPECT(first_is_one_of(3, 1, 2, 3, 4, 5));
// Finds item when single value in list
static_assert(first_is_one_of(42, 42));
EXPECT(first_is_one_of(42, 42));
// Finds item when duplicate values in list
static_assert(first_is_one_of(42, 42, 42));
EXPECT(first_is_one_of(42, 42, 42));
// Doesn't find items not in list
static_assert(!first_is_one_of(10, 1, 2, 3, 4, 5));
EXPECT(!first_is_one_of(10, 1, 2, 3, 4, 5));
// Doesn't find item when single value in list
static_assert(!first_is_one_of(10, 1));
EXPECT(!first_is_one_of(10, 1));
// Doesn't find items when duplicate values in list
static_assert(!first_is_one_of(10, 1, 1));
EXPECT(!first_is_one_of(10, 1, 1));
// Doesn't find item when empty list
static_assert(!first_is_one_of(10));
EXPECT(!first_is_one_of(10));
}
TEST_CASE(first_is_smaller_or_equal_than_one_of)
{
// Finds smaller items
static_assert(first_is_smaller_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_or_equal_than_one_of(-10, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_or_equal_than_one_of(-10, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_or_equal_than_one_of(42, 43));
EXPECT(first_is_smaller_or_equal_than_one_of(42, 43));
// Find equal items
static_assert(first_is_smaller_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_or_equal_than_one_of(-2, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_or_equal_than_one_of(-2, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_or_equal_than_one_of(42, 42));
EXPECT(first_is_smaller_or_equal_than_one_of(42, 42));
// Doesn't find larger items
static_assert(!first_is_smaller_or_equal_than_one_of(10, 1, 2, 3, 4, 5));
EXPECT(!first_is_smaller_or_equal_than_one_of(10, 1, 2, 3, 4, 5));
// Doesn't find item when empty list
static_assert(!first_is_smaller_or_equal_than_one_of(10));
EXPECT(!first_is_smaller_or_equal_than_one_of(10));
}
TEST_CASE(first_is_smaller_than_one_of)
{
// Finds smaller items
static_assert(first_is_smaller_than_one_of(1, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_than_one_of(1, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_than_one_of(-10, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_than_one_of(-10, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_than_one_of(42, 43));
EXPECT(first_is_smaller_than_one_of(42, 43));
// Doesn't find equal items
static_assert(!first_is_smaller_than_one_of(5, 1, -2, 3, -4, 5));
EXPECT(!first_is_smaller_than_one_of(5, 1, -2, 3, -4, 5));
// Doesn't find larger items
static_assert(!first_is_smaller_than_one_of(10, 1, 2, 3, 4, 5));
EXPECT(!first_is_smaller_than_one_of(10, 1, 2, 3, 4, 5));
// Doesn't find item when empty list
static_assert(!first_is_smaller_than_one_of(10));
EXPECT(!first_is_smaller_than_one_of(10));
}
TEST_CASE(first_is_smaller_or_equal_than_all_of)
{
// Finds smaller than all items
static_assert(first_is_smaller_or_equal_than_all_of(-10, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_or_equal_than_all_of(-10, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_or_equal_than_all_of(42, 43));
EXPECT(first_is_smaller_or_equal_than_all_of(42, 43));
// Find equal items
static_assert(first_is_smaller_or_equal_than_all_of(42, 42));
EXPECT(first_is_smaller_or_equal_than_all_of(42, 42));
// Match on empty list
static_assert(first_is_smaller_or_equal_than_all_of(10));
EXPECT(first_is_smaller_or_equal_than_all_of(10));
// Doesn't find smaller than some items
static_assert(!first_is_smaller_or_equal_than_all_of(1, 1, -2, 3, -4, 5));
EXPECT(!first_is_smaller_or_equal_than_all_of(1, 1, -2, 3, -4, 5));
// Doesn't find larger items
static_assert(!first_is_smaller_or_equal_than_all_of(10, 1, 2, 3, 4, 5));
EXPECT(!first_is_smaller_or_equal_than_all_of(10, 1, 2, 3, 4, 5));
}
TEST_CASE(first_is_smaller_than_all_of)
{
// Finds smaller than all items
static_assert(first_is_smaller_than_all_of(-10, 1, -2, 3, -4, 5));
EXPECT(first_is_smaller_than_all_of(-10, 1, -2, 3, -4, 5));
static_assert(first_is_smaller_than_all_of(42, 43));
EXPECT(first_is_smaller_than_all_of(42, 43));
// Match on empty list
static_assert(first_is_smaller_than_all_of(10));
EXPECT(first_is_smaller_than_all_of(10));
// Doesn't find equal items
static_assert(!first_is_smaller_than_all_of(42, 42));
EXPECT(!first_is_smaller_than_all_of(42, 42));
// Doesn't find smaller than some items
static_assert(!first_is_smaller_than_all_of(1, 1, -2, 3, -4, 5));
EXPECT(!first_is_smaller_than_all_of(1, 1, -2, 3, -4, 5));
// Doesn't find larger items
static_assert(!first_is_smaller_than_all_of(10, 1, 2, 3, 4, 5));
EXPECT(!first_is_smaller_than_all_of(10, 1, 2, 3, 4, 5));
}
TEST_CASE(first_is_larger_or_equal_than_one_of)
{
// Finds larger items
static_assert(first_is_larger_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
static_assert(first_is_larger_or_equal_than_one_of(10, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_or_equal_than_one_of(10, 1, -2, 3, -4, 5));
static_assert(first_is_larger_or_equal_than_one_of(44, 43));
EXPECT(first_is_larger_or_equal_than_one_of(44, 43));
// Finds equal items
static_assert(first_is_larger_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_or_equal_than_one_of(1, 1, -2, 3, -4, 5));
static_assert(first_is_larger_or_equal_than_one_of(-2, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_or_equal_than_one_of(-2, 1, -2, 3, -4, 5));
static_assert(first_is_larger_or_equal_than_one_of(42, 42));
EXPECT(first_is_larger_or_equal_than_one_of(42, 42));
// Doesn't find smaller items
static_assert(!first_is_larger_or_equal_than_one_of(-10, 1, 2, 3, 4, 5));
EXPECT(!first_is_larger_or_equal_than_one_of(-10, 1, 2, 3, 4, 5));
// Doesn't find item when empty list
static_assert(!first_is_larger_or_equal_than_one_of(10));
EXPECT(!first_is_larger_or_equal_than_one_of(10));
}
TEST_CASE(first_is_larger_than_one_of)
{
// Finds larger items
static_assert(first_is_larger_than_one_of(1, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_than_one_of(1, 1, -2, 3, -4, 5));
static_assert(first_is_larger_than_one_of(10, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_than_one_of(10, 1, -2, 3, -4, 5));
static_assert(first_is_larger_than_one_of(44, 43));
EXPECT(first_is_larger_than_one_of(44, 43));
// Doesn't find equal items
static_assert(!first_is_larger_than_one_of(-4, 1, -2, 3, -4, 5));
EXPECT(!first_is_larger_than_one_of(-4, 1, -2, 3, -4, 5));
// Doesn't find smaller items
static_assert(!first_is_larger_than_one_of(-10, 1, 2, 3, 4, 5));
EXPECT(!first_is_larger_than_one_of(-10, 1, 2, 3, 4, 5));
// Doesn't find item when empty list
static_assert(!first_is_larger_than_one_of(10));
EXPECT(!first_is_larger_than_one_of(10));
}
TEST_CASE(first_is_larger_or_equal_than_all_of)
{
// Finds larger than all items
static_assert(first_is_larger_or_equal_than_all_of(10, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_or_equal_than_all_of(10, 1, -2, 3, -4, 5));
static_assert(first_is_larger_or_equal_than_all_of(44, 43));
EXPECT(first_is_larger_or_equal_than_all_of(44, 43));
// Find equal items
static_assert(first_is_larger_or_equal_than_all_of(42, 42));
EXPECT(first_is_larger_or_equal_than_all_of(42, 42));
// Match on empty list
static_assert(first_is_larger_or_equal_than_all_of(10));
EXPECT(first_is_larger_or_equal_than_all_of(10));
// Doesn't find larger than some items
static_assert(!first_is_larger_or_equal_than_all_of(1, 1, -2, 3, -4, 5));
EXPECT(!first_is_larger_or_equal_than_all_of(1, 1, -2, 3, -4, 5));
// Doesn't find smaller items
static_assert(!first_is_larger_or_equal_than_all_of(-10, 1, 2, 3, 4, 5));
EXPECT(!first_is_larger_or_equal_than_all_of(-10, 1, 2, 3, 4, 5));
}
TEST_CASE(first_is_larger_than_all_of)
{
// Finds larger than all items
static_assert(first_is_larger_than_all_of(10, 1, -2, 3, -4, 5));
EXPECT(first_is_larger_than_all_of(10, 1, -2, 3, -4, 5));
static_assert(first_is_larger_than_all_of(44, 43));
EXPECT(first_is_larger_than_all_of(44, 43));
// Match on empty list
static_assert(first_is_larger_than_all_of(10));
EXPECT(first_is_larger_than_all_of(10));
// Doesn't find equal items
static_assert(!first_is_larger_than_all_of(42, 42));
EXPECT(!first_is_larger_than_all_of(42, 42));
// Doesn't find larger than some items
static_assert(!first_is_larger_than_all_of(1, 1, -2, 3, -4, 5));
EXPECT(!first_is_larger_than_all_of(1, 1, -2, 3, -4, 5));
// Doesn't find smaller items
static_assert(!first_is_larger_than_all_of(-10, 1, 2, 3, 4, 5));
EXPECT(!first_is_larger_than_all_of(-10, 1, 2, 3, 4, 5));
}