mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 10:01:13 +09:00
AK: Add tests for GenericShorthands
This commit is contained in:
parent
e469c884d4
commit
49fc569136
Notes:
github-actions[bot]
2025-01-09 08:04:56 +00:00
Author: https://github.com/izuzak
Commit: 49fc569136
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3170
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/gmta ✅
3 changed files with 258 additions and 0 deletions
|
@ -32,6 +32,7 @@ tests = [
|
||||||
"TestFlyString",
|
"TestFlyString",
|
||||||
"TestFormat",
|
"TestFormat",
|
||||||
"TestGenericLexer",
|
"TestGenericLexer",
|
||||||
|
"TestGenericShorthands",
|
||||||
"TestHashFunctions",
|
"TestHashFunctions",
|
||||||
"TestHashMap",
|
"TestHashMap",
|
||||||
"TestHashTable",
|
"TestHashTable",
|
||||||
|
|
|
@ -30,6 +30,7 @@ set(AK_TEST_SOURCES
|
||||||
TestFlyString.cpp
|
TestFlyString.cpp
|
||||||
TestFormat.cpp
|
TestFormat.cpp
|
||||||
TestGenericLexer.cpp
|
TestGenericLexer.cpp
|
||||||
|
TestGenericShorthands.cpp
|
||||||
TestHashFunctions.cpp
|
TestHashFunctions.cpp
|
||||||
TestHashMap.cpp
|
TestHashMap.cpp
|
||||||
TestHashTable.cpp
|
TestHashTable.cpp
|
||||||
|
|
256
Tests/AK/TestGenericShorthands.cpp
Normal file
256
Tests/AK/TestGenericShorthands.cpp
Normal 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));
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue