From 6321e97b0969e3a619601ebe94db06e3393a35e8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Jun 2024 08:17:14 +0200 Subject: [PATCH] AK: Remove various unused things --- AK/BinaryBufferWriter.h | 47 ------ AK/CMakeLists.txt | 2 - AK/CircularDeque.h | 46 ------ AK/FPControl.h | 124 ---------------- AK/FuzzyMatch.cpp | 136 ------------------ AK/FuzzyMatch.h | 25 ---- AK/MACAddress.h | 118 --------------- AK/Ptr32.h | 61 -------- AK/RefCountForwarder.h | 34 ----- AK/SetOnce.h | 36 ----- AK/Slugify.cpp | 33 ----- AK/Slugify.h | 17 --- Meta/gn/secondary/AK/BUILD.gn | 9 -- Meta/gn/secondary/Tests/AK/BUILD.gn | 2 - Tests/AK/CMakeLists.txt | 4 - Tests/AK/TestCircularDeque.cpp | 63 -------- Tests/AK/TestFuzzyMatch.cpp | 70 --------- Tests/AK/TestMACAddress.cpp | 124 ---------------- Tests/AK/TestSlugify.cpp | 43 ------ .../LibWeb/WebGL/WebGLRenderingContextBase.h | 1 - 20 files changed, 995 deletions(-) delete mode 100644 AK/BinaryBufferWriter.h delete mode 100644 AK/CircularDeque.h delete mode 100644 AK/FPControl.h delete mode 100644 AK/FuzzyMatch.cpp delete mode 100644 AK/FuzzyMatch.h delete mode 100644 AK/MACAddress.h delete mode 100644 AK/Ptr32.h delete mode 100644 AK/RefCountForwarder.h delete mode 100644 AK/SetOnce.h delete mode 100644 AK/Slugify.cpp delete mode 100644 AK/Slugify.h delete mode 100644 Tests/AK/TestCircularDeque.cpp delete mode 100644 Tests/AK/TestFuzzyMatch.cpp delete mode 100644 Tests/AK/TestMACAddress.cpp delete mode 100644 Tests/AK/TestSlugify.cpp diff --git a/AK/BinaryBufferWriter.h b/AK/BinaryBufferWriter.h deleted file mode 100644 index abbade998a9..00000000000 --- a/AK/BinaryBufferWriter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2021, Sahan Fernando - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace AK { - -class BinaryBufferWriter { -public: - BinaryBufferWriter(Bytes target) - : m_target(target) - { - } - - template - requires(IsTriviallyConstructible) T& append_structure() - { - VERIFY((reinterpret_cast(m_target.data()) + m_offset) % alignof(T) == 0); - VERIFY(m_offset + sizeof(T) <= m_target.size()); - T* allocated = new (m_target.data() + m_offset) T; - m_offset += sizeof(T); - return *allocated; - } - - void skip_bytes(size_t num_bytes) - { - VERIFY(m_offset + num_bytes <= m_target.size()); - m_offset += num_bytes; - } - - [[nodiscard]] size_t current_offset() const - { - return m_offset; - } - -private: - Bytes m_target; - size_t m_offset { 0 }; -}; - -} diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 2e4513b8386..96ca7b7eda6 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -11,7 +11,6 @@ set(AK_SOURCES FloatingPointStringConversions.cpp FlyString.cpp Format.cpp - FuzzyMatch.cpp GenericLexer.cpp Hex.cpp JsonObject.cpp @@ -24,7 +23,6 @@ set(AK_SOURCES OptionParser.cpp Random.cpp SipHash.cpp - Slugify.cpp StackInfo.cpp Stream.cpp String.cpp diff --git a/AK/CircularDeque.h b/AK/CircularDeque.h deleted file mode 100644 index 0a3d077d845..00000000000 --- a/AK/CircularDeque.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace AK { - -template -class CircularDeque : public CircularQueue { -public: - template - void enqueue_begin(U&& value) - { - auto const new_head = (this->m_head - 1 + Capacity) % Capacity; - auto& slot = this->elements()[new_head]; - if (this->m_size == Capacity) - slot.~T(); - else - ++this->m_size; - - new (&slot) T(forward(value)); - this->m_head = new_head; - } - - T dequeue_end() - { - VERIFY(!this->is_empty()); - auto& slot = this->elements()[(this->m_head + this->m_size - 1) % Capacity]; - T value = move(slot); - slot.~T(); - this->m_size--; - return value; - } -}; - -} - -#if USING_AK_GLOBALLY -using AK::CircularDeque; -#endif diff --git a/AK/FPControl.h b/AK/FPControl.h deleted file mode 100644 index b5cf575b1d2..00000000000 --- a/AK/FPControl.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2022, Leon Albrecht - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -// FIXME: Add equivalent datastructures for aarch64 -VALIDATE_IS_X86(); - -namespace AK { - -enum class RoundingMode : u16 { - NEAREST = 0b00, - DOWN = 0b01, - UP = 0b10, - TRUNC = 0b11 -}; - -union X87ControlWord { - u16 cw; - struct { - u16 mask_invalid : 1; // IM - u16 mask_denorm : 1; // DM - u16 mask_zero_div : 1; // ZM - u16 mask_overflow : 1; // OM - u16 mask_underflow : 1; // UM - u16 mask_precision : 1; // PM - u16 : 2; // unused - u16 precision : 2; // PC - RoundingMode rounding_control : 2; // RC - u16 infinity_control : 1; // X - u16 : 3; // unused - }; -}; -static_assert(sizeof(X87ControlWord) == sizeof(u16)); - -union MXCSR { - u32 mxcsr; - struct { - u32 invalid_operation_flag : 1; // IE - u32 denormal_operation_flag : 1; // DE - u32 divide_by_zero_flag : 1; // ZE - u32 overflow_flag : 1; // OE - u32 underflow_flag : 1; // UE - u32 precision_flag : 1; // PE - u32 denormals_are_zero : 1; // DAZ - u32 invalid_operation_mask : 1; // IM - u32 denormal_operation_mask : 1; // DM - u32 divide_by_zero_mask : 1; // ZM - u32 overflow_mask : 1; // OM - u32 underflow_mask : 1; // UM - u32 precision_mask : 1; // PM - RoundingMode rounding_control : 2; // RC - u32 flush_to_zero : 1; // FTZ - u32 __reserved : 16; - }; -}; -static_assert(sizeof(MXCSR) == sizeof(u32)); - -ALWAYS_INLINE X87ControlWord get_cw_x87() -{ - X87ControlWord control_word; - asm("fnstcw %0" - : "=m"(control_word)); - return control_word; -} -ALWAYS_INLINE void set_cw_x87(X87ControlWord control_word) -{ - asm("fldcw %0" ::"m"(control_word)); -} - -ALWAYS_INLINE MXCSR get_mxcsr() -{ - MXCSR mxcsr; - asm("stmxcsr %0" - : "=m"(mxcsr)); - return mxcsr; -} -ALWAYS_INLINE void set_mxcsr(MXCSR mxcsr) -{ - asm("ldmxcsr %0" ::"m"(mxcsr)); -} - -class X87RoundingModeScope { -public: - X87RoundingModeScope(RoundingMode rounding_mode) - { - m_cw = get_cw_x87(); - auto cw = m_cw; - cw.rounding_control = rounding_mode; - set_cw_x87(cw); - } - ~X87RoundingModeScope() - { - set_cw_x87(m_cw); - } - -private: - X87ControlWord m_cw; -}; - -class SSERoundingModeScope { -public: - SSERoundingModeScope(RoundingMode rounding_mode) - { - m_mxcsr = get_mxcsr(); - auto mxcsr = m_mxcsr; - mxcsr.rounding_control = rounding_mode; - set_mxcsr(mxcsr); - } - ~SSERoundingModeScope() - { - set_mxcsr(m_mxcsr); - } - -private: - MXCSR m_mxcsr; -}; - -} diff --git a/AK/FuzzyMatch.cpp b/AK/FuzzyMatch.cpp deleted file mode 100644 index fc090c7248a..00000000000 --- a/AK/FuzzyMatch.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2021, Spencer Dixon - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include - -namespace AK { - -static constexpr int const RECURSION_LIMIT = 10; -static constexpr int const MAX_MATCHES = 256; - -// Bonuses and penalties are used to build up a final score for the match. -static constexpr int const SEQUENTIAL_BONUS = 15; // bonus for adjacent matches (needle: 'ca', haystack: 'cat') -static constexpr int const SEPARATOR_BONUS = 30; // bonus if match occurs after a separator ('_' or ' ') -static constexpr int const CAMEL_BONUS = 30; // bonus if match is uppercase and prev is lower (needle: 'myF' haystack: '/path/to/myFile.txt') -static constexpr int const FIRST_LETTER_BONUS = 15; // bonus if the first letter is matched (needle: 'c' haystack: 'cat') -static constexpr int const LEADING_LETTER_PENALTY = -5; // penalty applied for every letter in str before the first match -static constexpr int const MAX_LEADING_LETTER_PENALTY = -15; // maximum penalty for leading letters -static constexpr int const UNMATCHED_LETTER_PENALTY = -1; // penalty for every letter that doesn't matter - -static int calculate_score(StringView string, u8* index_points, size_t index_points_size) -{ - int out_score = 100; - - int penalty = LEADING_LETTER_PENALTY * index_points[0]; - if (penalty < MAX_LEADING_LETTER_PENALTY) - penalty = MAX_LEADING_LETTER_PENALTY; - out_score += penalty; - - int unmatched = string.length() - index_points_size; - out_score += UNMATCHED_LETTER_PENALTY * unmatched; - - for (size_t i = 0; i < index_points_size; i++) { - u8 current_idx = index_points[i]; - - if (i > 0) { - u8 previous_idx = index_points[i - 1]; - if (current_idx - 1 == previous_idx) - out_score += SEQUENTIAL_BONUS; - } - - if (current_idx == 0) { - out_score += FIRST_LETTER_BONUS; - } else { - u32 current_character = string[current_idx]; - u32 neighbor_character = string[current_idx - 1]; - - if (is_ascii_lower_alpha(neighbor_character) && is_ascii_upper_alpha(current_character)) - out_score += CAMEL_BONUS; - - if (neighbor_character == '_' || neighbor_character == ' ') - out_score += SEPARATOR_BONUS; - } - } - - return out_score; -} - -static FuzzyMatchResult fuzzy_match_recursive(StringView needle, StringView haystack, size_t needle_idx, size_t haystack_idx, - u8 const* src_matches, u8* matches, int next_match, int& recursion_count) -{ - int out_score = 0; - - ++recursion_count; - if (recursion_count >= RECURSION_LIMIT) - return { false, out_score }; - - if (needle.length() == needle_idx || haystack.length() == haystack_idx) - return { false, out_score }; - - bool had_recursive_match = false; - constexpr size_t recursive_match_limit = 256; - u8 best_recursive_matches[recursive_match_limit]; - int best_recursive_score = 0; - - bool first_match = true; - while (needle_idx < needle.length() && haystack_idx < haystack.length()) { - - if (to_ascii_lowercase(needle[needle_idx]) == to_ascii_lowercase(haystack[haystack_idx])) { - if (next_match >= MAX_MATCHES) - return { false, out_score }; - - if (first_match && src_matches) { - memcpy(matches, src_matches, next_match); - first_match = false; - } - - u8 recursive_matches[recursive_match_limit] {}; - auto result = fuzzy_match_recursive(needle, haystack, needle_idx, haystack_idx + 1, matches, recursive_matches, next_match, recursion_count); - if (result.matched) { - if (!had_recursive_match || result.score > best_recursive_score) { - memcpy(best_recursive_matches, recursive_matches, recursive_match_limit); - best_recursive_score = result.score; - } - had_recursive_match = true; - } - matches[next_match++] = haystack_idx; - needle_idx++; - } - haystack_idx++; - } - - bool matched = needle_idx == needle.length(); - if (!matched) - return { false, out_score }; - - out_score = calculate_score(haystack, matches, next_match); - - if (had_recursive_match && (best_recursive_score > out_score)) { - memcpy(matches, best_recursive_matches, MAX_MATCHES); - out_score = best_recursive_score; - } - - return { true, out_score }; -} - -// This fuzzy_match algorithm is based off a similar algorithm used by Sublime Text. The key insight is that instead -// of doing a total in the distance between characters (I.E. Levenshtein Distance), we apply some meaningful heuristics -// related to our dataset that we're trying to match to build up a score. Scores can then be sorted and displayed -// with the highest at the top. -// -// Scores are not normalized between any values and have no particular meaning. The starting value is 100 and when we -// detect good indicators of a match we add to the score. When we detect bad indicators, we penalize the match and subtract -// from its score. Therefore, the longer the needle/haystack the greater the range of scores could be. -FuzzyMatchResult fuzzy_match(StringView needle, StringView haystack) -{ - int recursion_count = 0; - u8 matches[MAX_MATCHES] {}; - return fuzzy_match_recursive(needle, haystack, 0, 0, nullptr, matches, 0, recursion_count); -} - -} diff --git a/AK/FuzzyMatch.h b/AK/FuzzyMatch.h deleted file mode 100644 index a8f4235dbc4..00000000000 --- a/AK/FuzzyMatch.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021, Spencer Dixon - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -namespace AK { - -struct FuzzyMatchResult { - bool matched { false }; - int score { 0 }; -}; - -FuzzyMatchResult fuzzy_match(StringView needle, StringView haystack); - -} - -#if USING_AK_GLOBALLY -using AK::fuzzy_match; -using AK::FuzzyMatchResult; -#endif diff --git a/AK/MACAddress.h b/AK/MACAddress.h deleted file mode 100644 index b948575e5ad..00000000000 --- a/AK/MACAddress.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include - -#ifdef KERNEL -# include -#else -# include -#endif - -class [[gnu::packed]] MACAddress { - static constexpr size_t s_mac_address_length = 6u; - -public: - constexpr MACAddress() = default; - - constexpr MACAddress(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f) - { - m_data[0] = a; - m_data[1] = b; - m_data[2] = c; - m_data[3] = d; - m_data[4] = e; - m_data[5] = f; - } - - constexpr ~MACAddress() = default; - - constexpr u8 const& operator[](unsigned i) const - { - VERIFY(i < s_mac_address_length); - return m_data[i]; - } - - constexpr u8& operator[](unsigned i) - { - VERIFY(i < s_mac_address_length); - return m_data[i]; - } - - constexpr bool operator==(MACAddress const& other) const - { - for (auto i = 0u; i < m_data.size(); ++i) { - if (m_data[i] != other.m_data[i]) { - return false; - } - } - return true; - } - -#ifdef KERNEL - ErrorOr> to_string() const - { - return Kernel::KString::formatted("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", m_data[0], m_data[1], m_data[2], m_data[3], m_data[4], m_data[5]); - } -#else - ByteString to_byte_string() const - { - return ByteString::formatted("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", m_data[0], m_data[1], m_data[2], m_data[3], m_data[4], m_data[5]); - } -#endif - - static Optional from_string(StringView string) - { - if (string.is_null()) - return {}; - - auto const parts = string.split_view(':'); - if (parts.size() != 6) - return {}; - - auto a = AK::StringUtils::convert_to_uint_from_hex(parts[0]).value_or(256); - auto b = AK::StringUtils::convert_to_uint_from_hex(parts[1]).value_or(256); - auto c = AK::StringUtils::convert_to_uint_from_hex(parts[2]).value_or(256); - auto d = AK::StringUtils::convert_to_uint_from_hex(parts[3]).value_or(256); - auto e = AK::StringUtils::convert_to_uint_from_hex(parts[4]).value_or(256); - auto f = AK::StringUtils::convert_to_uint_from_hex(parts[5]).value_or(256); - - if (a > 255 || b > 255 || c > 255 || d > 255 || e > 255 || f > 255) - return {}; - - return MACAddress(a, b, c, d, e, f); - } - - constexpr bool is_zero() const - { - return all_of(m_data, [](auto const octet) { return octet == 0; }); - } - - void copy_to(Bytes destination) const - { - m_data.span().copy_to(destination); - } - -private: - Array m_data {}; -}; - -static_assert(sizeof(MACAddress) == 6u); - -namespace AK { - -template<> -struct Traits : public DefaultTraits { - static unsigned hash(MACAddress const& address) { return string_hash((char const*)&address, sizeof(address)); } -}; - -} diff --git a/AK/Ptr32.h b/AK/Ptr32.h deleted file mode 100644 index 0441feb5392..00000000000 --- a/AK/Ptr32.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * Copyright (c) 2021, Leon Albrecht - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace AK { - -template -class Ptr32 { -public: - constexpr Ptr32() = default; - Ptr32(T* const ptr) - : m_ptr((u32) reinterpret_cast(ptr)) - { - VERIFY((reinterpret_cast(ptr) & 0xFFFFFFFFULL) == static_cast(m_ptr)); - } - T& operator*() { return *static_cast(*this); } - T const& operator*() const { return *static_cast(*this); } - - T* operator->() { return *this; } - T const* operator->() const { return *this; } - - operator T*() { return reinterpret_cast(static_cast(m_ptr)); } - operator T const*() const { return reinterpret_cast(static_cast(m_ptr)); } - - T& operator[](size_t index) { return static_cast(*this)[index]; } - T const& operator[](size_t index) const { return static_cast(*this)[index]; } - - constexpr explicit operator bool() { return m_ptr; } - template - constexpr bool operator==(Ptr32 other) { return m_ptr == other.m_ptr; } - - constexpr Ptr32 operator+(u32 other) const - { - Ptr32 ptr {}; - ptr.m_ptr = m_ptr + other; - return ptr; - } - constexpr Ptr32 operator-(u32 other) const - { - Ptr32 ptr {}; - ptr.m_ptr = m_ptr - other; - return ptr; - } - -private: - u32 m_ptr { 0 }; -}; - -} - -#if USING_AK_GLOBALLY -using AK::Ptr32; -#endif diff --git a/AK/RefCountForwarder.h b/AK/RefCountForwarder.h deleted file mode 100644 index 65b63a1fdfd..00000000000 --- a/AK/RefCountForwarder.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -namespace AK { - -template -class RefCountForwarder { -public: - void ref() { m_ref_count_target.ref(); } - void unref() { m_ref_count_target.unref(); } - - T& ref_count_target() { return m_ref_count_target; } - T const& ref_count_target() const { return m_ref_count_target; } - -protected: - RefCountForwarder(T& target) - : m_ref_count_target(target) - { - } - -private: - T& m_ref_count_target; -}; - -} - -#if USING_AK_GLOBALLY -using AK::RefCountForwarder; -#endif diff --git a/AK/SetOnce.h b/AK/SetOnce.h deleted file mode 100644 index b64998f73fb..00000000000 --- a/AK/SetOnce.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2024, Liav A. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace AK { - -class SetOnce { - AK_MAKE_NONCOPYABLE(SetOnce); - AK_MAKE_NONMOVABLE(SetOnce); - -public: - SetOnce() = default; - - void set() - { - m_value = true; - } - - bool was_set() const { return m_value; } - -private: - bool m_value { false }; -}; - -} - -#if USING_AK_GLOBALLY -using AK::SetOnce; -#endif diff --git a/AK/Slugify.cpp b/AK/Slugify.cpp deleted file mode 100644 index 51feb5ef781..00000000000 --- a/AK/Slugify.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2023, Gurkirat Singh - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include - -namespace AK { -ErrorOr slugify(String const& input, char const glue) -{ - StringBuilder sb; - bool just_processed_space = false; - - for (auto const& code_point : input.code_points()) { - if (is_ascii_alphanumeric(code_point)) { - sb.append_code_point(to_ascii_lowercase(code_point)); - just_processed_space = false; - } else if ((code_point == static_cast(glue) || is_ascii_space(code_point)) && !just_processed_space) { - sb.append_code_point(glue); - just_processed_space = true; - } - } - - auto output = TRY(sb.to_string()); - if (output.ends_with(static_cast(glue))) { - return output.trim(StringView { &glue, 1 }, TrimMode::Right); - } - return output; -} -} diff --git a/AK/Slugify.h b/AK/Slugify.h deleted file mode 100644 index 477f09a9a17..00000000000 --- a/AK/Slugify.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2023, Gurkirat Singh - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -namespace AK { -ErrorOr slugify(String const& input, char glue = '-'); -} - -#if USING_AK_GLOBALLY -using AK::slugify; -#endif diff --git a/Meta/gn/secondary/AK/BUILD.gn b/Meta/gn/secondary/AK/BUILD.gn index bf2f6c02b53..51974a0a2bf 100644 --- a/Meta/gn/secondary/AK/BUILD.gn +++ b/Meta/gn/secondary/AK/BUILD.gn @@ -27,7 +27,6 @@ shared_library("AK") { "Base64.cpp", "Base64.h", "BigIntBase.h", - "BinaryBufferWriter.h", "BinaryHeap.h", "BinarySearch.h", "BitCast.h", @@ -46,7 +45,6 @@ shared_library("AK") { "CheckedFormatString.h", "CircularBuffer.cpp", "CircularBuffer.h", - "CircularDeque.h", "CircularQueue.h", "Complex.h", "Concepts.h", @@ -69,7 +67,6 @@ shared_library("AK") { "EnumBits.h", "Error.cpp", "Error.h", - "FPControl.h", "Find.h", "FixedArray.h", "FixedPoint.h", @@ -82,8 +79,6 @@ shared_library("AK") { "Format.h", "Forward.h", "Function.h", - "FuzzyMatch.cpp", - "FuzzyMatch.h", "GenericLexer.cpp", "GenericLexer.h", "GenericShorthands.h", @@ -117,7 +112,6 @@ shared_library("AK") { "LEB128.h", "LexicalPath.cpp", "LexicalPath.h", - "MACAddress.h", "Math.h", "MaybeOwned.h", "MemMem.h", @@ -146,7 +140,6 @@ shared_library("AK") { "Random.h", "RecursionDecision.h", "RedBlackTree.h", - "RefCountForwarder.h", "RefCounted.h", "RefPtr.h", "Result.h", @@ -162,8 +155,6 @@ shared_library("AK") { "SinglyLinkedListSizePolicy.h", "SipHash.cpp", "SipHash.h", - "Slugify.cpp", - "Slugify.h", "SourceGenerator.h", "SourceLocation.h", "Span.h", diff --git a/Meta/gn/secondary/Tests/AK/BUILD.gn b/Meta/gn/secondary/Tests/AK/BUILD.gn index 219186c8c1a..65184eb8620 100644 --- a/Meta/gn/secondary/Tests/AK/BUILD.gn +++ b/Meta/gn/secondary/Tests/AK/BUILD.gn @@ -18,7 +18,6 @@ tests = [ "TestCharacterTypes", "TestChecked", "TestCircularBuffer", - "TestCircularDeque", "TestCircularQueue", "TestComplex", "TestByteString", @@ -50,7 +49,6 @@ tests = [ "TestJSON", "TestLEB128", "TestLexicalPath", - "TestMACAddress", "TestMemory", "TestMemoryStream", "TestNeverDestroyed", diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index ec85150dae9..66ed914954b 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -17,7 +17,6 @@ set(AK_TEST_SOURCES TestCharacterTypes.cpp TestChecked.cpp TestCircularBuffer.cpp - TestCircularDeque.cpp TestCircularQueue.cpp TestComplex.cpp TestDisjointChunks.cpp @@ -33,7 +32,6 @@ set(AK_TEST_SOURCES TestFloatingPointParsing.cpp TestFlyString.cpp TestFormat.cpp - TestFuzzyMatch.cpp TestGenericLexer.cpp TestHashFunctions.cpp TestHashMap.cpp @@ -49,7 +47,6 @@ set(AK_TEST_SOURCES TestJSON.cpp TestLEB128.cpp TestLexicalPath.cpp - TestMACAddress.cpp TestMemory.cpp TestMemoryStream.cpp TestNeverDestroyed.cpp @@ -68,7 +65,6 @@ set(AK_TEST_SOURCES TestSegmentedVector.cpp TestSIMD.cpp TestSinglyLinkedList.cpp - TestSlugify.cpp TestSourceGenerator.cpp TestSourceLocation.cpp TestSpan.cpp diff --git a/Tests/AK/TestCircularDeque.cpp b/Tests/AK/TestCircularDeque.cpp deleted file mode 100644 index a843ca7d68e..00000000000 --- a/Tests/AK/TestCircularDeque.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2020, Fei Wu - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#include -#include -#include - -TEST_CASE(enqueue_begin) -{ - CircularDeque ints; - - ints.enqueue_begin(0); - EXPECT_EQ(ints.size(), 1u); - EXPECT_EQ(ints.first(), 0); - - ints.enqueue_begin(1); - EXPECT_EQ(ints.size(), 2u); - EXPECT_EQ(ints.first(), 1); - EXPECT_EQ(ints.last(), 0); - - ints.enqueue_begin(2); - EXPECT_EQ(ints.size(), 3u); - EXPECT_EQ(ints.first(), 2); - EXPECT_EQ(ints.last(), 0); - - ints.enqueue_begin(3); - EXPECT_EQ(ints.size(), 3u); - EXPECT_EQ(ints.first(), 3); - EXPECT_EQ(ints.at(1), 2); - EXPECT_EQ(ints.last(), 1); -} - -TEST_CASE(enqueue_begin_being_moved_from) -{ - CircularDeque strings; - - ByteString str { "test" }; - strings.enqueue_begin(move(str)); - EXPECT(str.is_empty()); -} - -TEST_CASE(deque_end) -{ - CircularDeque ints; - ints.enqueue(0); - ints.enqueue(1); - ints.enqueue(2); - EXPECT_EQ(ints.size(), 3u); - - EXPECT_EQ(ints.dequeue_end(), 2); - EXPECT_EQ(ints.size(), 2u); - - EXPECT_EQ(ints.dequeue_end(), 1); - EXPECT_EQ(ints.size(), 1u); - - EXPECT_EQ(ints.dequeue_end(), 0); - EXPECT(ints.is_empty()); -} diff --git a/Tests/AK/TestFuzzyMatch.cpp b/Tests/AK/TestFuzzyMatch.cpp deleted file mode 100644 index 388a35765f6..00000000000 --- a/Tests/AK/TestFuzzyMatch.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2023, Tim Ledbetter - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#include - -TEST_CASE(is_leading_letter_penalty_correctly_applied) -{ - // Leading penalty is -5 points for each initial unmatched letter up to a maximum of -15. - EXPECT_EQ(fuzzy_match("b"sv, "ab"sv).score, 94); - EXPECT_EQ(fuzzy_match("c"sv, "abc"sv).score, 88); - EXPECT_EQ(fuzzy_match("d"sv, "abcd"sv).score, 82); - EXPECT_EQ(fuzzy_match("e"sv, "abcde"sv).score, 81); -} - -TEST_CASE(is_first_letter_bonus_applied_correctly) -{ - // First letter bonus is +15 if the first letter matches. - EXPECT_EQ(fuzzy_match("a"sv, "a"sv).score, 115); - EXPECT_EQ(fuzzy_match("a"sv, "A"sv).score, 115); - EXPECT_EQ(fuzzy_match(" "sv, " "sv).score, 115); -} - -TEST_CASE(is_sequential_bonus_applied_correctly) -{ - // Sequential bonus is +15 for each sequential match. - EXPECT_EQ(fuzzy_match("bc"sv, "abc"sv).score, 109); - EXPECT_EQ(fuzzy_match("bcd"sv, "ab-cd"sv).score, 108); - EXPECT_EQ(fuzzy_match("bcd"sv, "abcd"sv).score, 124); - EXPECT_EQ(fuzzy_match("bcde"sv, "ab-cde"sv).score, 123); - EXPECT_EQ(fuzzy_match("bcde"sv, "abcde"sv).score, 139); - EXPECT_EQ(fuzzy_match("bcde"sv, "abcdef"sv).score, 138); -} - -TEST_CASE(is_camel_case_bonus_applied_correctly) -{ - // Camel case bonus is +30 if the matching character is uppercase and the preceding character is lowercase. - // These cases get no camel case bonus. - EXPECT_EQ(fuzzy_match("b"sv, "Ab"sv).score, 94); - EXPECT_EQ(fuzzy_match("abc"sv, "ABc"sv).score, 145); - EXPECT_EQ(fuzzy_match("abc"sv, "ABC"sv).score, 145); - EXPECT_EQ(fuzzy_match("abc"sv, "Abc"sv).score, 145); - EXPECT_EQ(fuzzy_match("abcd"sv, "abcd"sv).score, 160); - - // These cases get a camel case bonus. - EXPECT_EQ(fuzzy_match("b"sv, "aB"sv).score, 124); - EXPECT_EQ(fuzzy_match("abc"sv, "aBc"sv).score, 175); - EXPECT_EQ(fuzzy_match("abc"sv, "aBC"sv).score, 175); - EXPECT_EQ(fuzzy_match("abc"sv, "aBC-"sv).score, 174); - EXPECT_EQ(fuzzy_match("abcd"sv, "aBcD"sv).score, 220); - EXPECT_EQ(fuzzy_match("abcd"sv, "aBcD-"sv).score, 219); -} - -TEST_CASE(is_separator_bonus_applied_correctly) -{ - // Separator bonus is +30 if the character preceding the matching character is a space or an underscore. - EXPECT_EQ(fuzzy_match("b"sv, "a b"sv).score, 118); - EXPECT_EQ(fuzzy_match("bc"sv, "a b c"sv).score, 147); - EXPECT_EQ(fuzzy_match("ab cd"sv, "ab cd"sv).score, 205); - EXPECT_EQ(fuzzy_match("ab_cd"sv, "ab_cd"sv).score, 205); - EXPECT_EQ(fuzzy_match("abcd"sv, "a b c d"sv).score, 202); - EXPECT_EQ(fuzzy_match("abcd"sv, "a_b_c_d"sv).score, 202); - EXPECT_EQ(fuzzy_match("b c"sv, "ab cd"sv).score, 153); - EXPECT_EQ(fuzzy_match("b_c"sv, "ab_cd"sv).score, 153); - EXPECT_EQ(fuzzy_match("bc"sv, "ab cd"sv).score, 122); -} diff --git a/Tests/AK/TestMACAddress.cpp b/Tests/AK/TestMACAddress.cpp deleted file mode 100644 index dd1a347f52e..00000000000 --- a/Tests/AK/TestMACAddress.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2020, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#include -#include - -TEST_CASE(should_default_construct) -{ - constexpr MACAddress sut {}; - static_assert(sut.is_zero()); - EXPECT(sut.is_zero()); -} - -TEST_CASE(should_braces_construct) -{ - constexpr MACAddress sut { 1, 2, 3, 4, 5, 6 }; - static_assert(!sut.is_zero()); - EXPECT(!sut.is_zero()); -} - -TEST_CASE(should_construct_from_6_octets) -{ - constexpr MACAddress sut(1, 2, 3, 4, 5, 6); - static_assert(!sut.is_zero()); - EXPECT(!sut.is_zero()); -} - -TEST_CASE(should_provide_read_access_to_octet_by_index) -{ - constexpr auto is_all_expected = [](auto& sut) { - for (auto i = 0u; i < sizeof(MACAddress); ++i) { - if (sut[i] != i + 1) { - return false; - } - } - return true; - }; - - constexpr MACAddress sut(1, 2, 3, 4, 5, 6); - - static_assert(is_all_expected(sut)); - - for (auto i = 0u; i < sizeof(MACAddress); ++i) { - EXPECT_EQ(i + 1, sut[i]); - } -} - -TEST_CASE(should_provide_write_access_to_octet_by_index) -{ - constexpr auto sut = [] { - MACAddress m {}; - for (auto i = 0u; i < sizeof(MACAddress); ++i) { - m[i] = i + 1; - } - return m; - }(); - - constexpr MACAddress expected(1, 2, 3, 4, 5, 6); - - static_assert(expected == sut); -} - -TEST_CASE(should_equality_compare) -{ - constexpr MACAddress a(1, 2, 3, 4, 5, 6); - constexpr MACAddress b(1, 2, 3, 42, 5, 6); - - static_assert(a == a); - static_assert(a != b); - - EXPECT(a == a); - EXPECT(a != b); -} - -TEST_CASE(should_string_format) -{ - MACAddress sut(1, 2, 3, 4, 5, 6); - EXPECT_EQ("01:02:03:04:05:06", sut.to_byte_string()); -} - -TEST_CASE(should_make_mac_address_from_string_numbers) -{ - auto const sut = MACAddress::from_string("01:02:03:04:05:06"sv); - - EXPECT(sut.has_value()); - EXPECT_EQ(1, sut.value()[0]); - EXPECT_EQ(2, sut.value()[1]); - EXPECT_EQ(3, sut.value()[2]); - EXPECT_EQ(4, sut.value()[3]); - EXPECT_EQ(5, sut.value()[4]); - EXPECT_EQ(6, sut.value()[5]); -} - -TEST_CASE(should_make_mac_address_from_string_letters) -{ - auto const sut = MACAddress::from_string("de:ad:be:ee:ee:ef"sv); - - EXPECT(sut.has_value()); - EXPECT_EQ(u8 { 0xDE }, sut.value()[0]); - EXPECT_EQ(u8 { 0xAD }, sut.value()[1]); - EXPECT_EQ(u8 { 0xBE }, sut.value()[2]); - EXPECT_EQ(u8 { 0xEE }, sut.value()[3]); - EXPECT_EQ(u8 { 0xEE }, sut.value()[4]); - EXPECT_EQ(u8 { 0xEF }, sut.value()[5]); -} - -TEST_CASE(should_make_empty_optional_from_bad_string) -{ - auto const sut = MACAddress::from_string("bad string"sv); - - EXPECT(!sut.has_value()); -} - -TEST_CASE(should_make_empty_optional_from_out_of_range_values) -{ - auto const sut = MACAddress::from_string("de:ad:be:ee:ee:fz"sv); - - EXPECT(!sut.has_value()); -} diff --git a/Tests/AK/TestSlugify.cpp b/Tests/AK/TestSlugify.cpp deleted file mode 100644 index afa8db73eed..00000000000 --- a/Tests/AK/TestSlugify.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023, Gurkirat Singh - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include - -TEST_CASE(ignore_unicode_characters) -{ - EXPECT_EQ(MUST(slugify("Hello World!🎉"_string)), "hello-world"_string); -} - -TEST_CASE(all_whitespace_empty_string) -{ - EXPECT_EQ(MUST(slugify(" "_string)), ""_string); -} - -TEST_CASE(squeeze_multiple_whitespace) -{ - EXPECT_EQ(MUST(slugify("Hello World"_string)), "hello-world"_string); -} - -TEST_CASE(trim_trailing_whitelist) -{ - EXPECT_EQ(MUST(slugify("Hello World "_string)), "hello-world"_string); -} - -TEST_CASE(lowercase_all_result) -{ - EXPECT_EQ(MUST(slugify("HelloWorld"_string)), "helloworld"_string); -} - -TEST_CASE(slug_glue_change) -{ - EXPECT_EQ(MUST(slugify("Hello World"_string, '|')), "hello|world"_string); -} - -TEST_CASE(multiple_glue_squeeze) -{ - EXPECT_EQ(MUST(slugify("Hello_ World"_string, '_')), "hello_world"_string); -} diff --git a/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h b/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h index 14e9b20d65f..18164ee00a9 100644 --- a/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h +++ b/Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include