summaryrefslogtreecommitdiff
path: root/AK/Tests
AgeCommit message (Collapse)Author
2020-11-14AK: Fix StringUtils::contains() case insensitive searchLinus Groh
It would incorrectly return false if needle was at the end the string.
2020-11-12AK: Prefer using instead of typedefLenny Maiorani
Problem: - `typedef` is a keyword which comes from C and carries with it old syntax that is hard to read. - Creating type aliases with the `using` keyword allows for easier future maintenance because it supports template syntax. - There is inconsistent use of `typedef` vs `using`. Solution: - Use `clang-tidy`'s checker called `modernize-use-using` to update the syntax to use the newer syntax. - Remove unused functions to make `clang-tidy` happy. - This results in consistency within the codebase.
2020-11-11IPv4Address: constexpr supportLenny Maiorani
Problem: - IPv4Address class cannot be used in a compile-time context. - A union is used by initializing one of the members and reading the non-active member. This is undefined behavior and not permitted in a `constexpr` context. Solution: - Eliminate undefined behavior by changing to a simple `u32` for storage instead of the union and performing mask/shift calculations for obtaining the individual octets. - Decorate functions with `constexpr` where possible. Currently string formatting and optionals are not `constexpr`-capable so functions using those are left out. - Modify tests to validate functionality in a `constexpr` context in addition to the run-time tests already being run. This ensures that functionality is the same in both contexts.
2020-11-10AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safeTom
This makes most operations thread safe, especially so that they can safely be used in the Kernel. This includes obtaining a strong reference from a weak reference, which now requires an explicit call to WeakPtr::strong_ref(). Another major change is that Weakable::make_weak_ref() may require the explicit target type. Previously we used reinterpret_cast in WeakPtr, assuming that it can be properly converted. But WeakPtr does not necessarily have the knowledge to be able to do this. Instead, we now ask the class itself to deliver a WeakPtr to the type that we want. Also, WeakLink is no longer specific to a target type. The reason for this is that we want to be able to safely convert e.g. WeakPtr<T> to WeakPtr<U>, and before this we just reinterpret_cast the internal WeakLink<T> to WeakLink<U>, which is a bold assumption that it would actually produce the correct code. Instead, WeakLink now operates on just a raw pointer and we only make those constructors/operators available if we can verify that it can be safely cast. In order to guarantee thread safety, we now use the least significant bit in the pointer for locking purposes. This also means that only properly aligned pointers can be used.
2020-11-10IPv4Address: Unit testsLenny Maiorani
Problem: - There is no direct unit testing of the IPv4Address functionality which makes refactoring difficult. Solution: - Add unit tests to cover the current functionality of IPv4Address. This will allow future refactorings with confidence.
2020-11-09AK: Add formatters for floating point numbers.asynts
2020-11-09AK: Rename new_out to out and new_warn to warn.asynts
2020-11-05AK: printf was not accounting for plus sign with "%+d"Andreas Kling
We have to include the plus sign in the number of characters written, otherwise sprintf() will put the null terminator too early.
2020-11-04AK::URL: Check if URL requires a port set to be considered a valid URLBrendan Coles
`AK::URL` will now check if the URL requires a port to be set using `AK::URL.protocol_requires_port(protocol)`. If the URL does not specify a port, and no default port for the URL protocol is found with `AK::URL.default_port_for_protocol(protocol)`, the URL is considered to be invalid.
2020-10-29AK: Make String::matches() capable of reporting match positions tooAnotherTest
Also, rewrite StringUtils::match(), because the old implementation was fairly broken, e.g. "acdcxb" would *not* match "a*?b".
2020-10-29CMake: Use CONFIGURE_DEPENDS in existing globs.asynts
2020-10-25AK: Eradicate calls to warn().asynts
2020-10-25AK: Remove a really slow unit test.asynts
2020-10-24AK: Introduce SourceGenerator::fork().asynts
Previously, I abused the copy constructor, this is a lot better.
2020-10-22AK: Enhance String::contains to allow case-insensitive searchesTom
2020-10-21TestArray: constexpr_sum using spanLenny Maiorani
Problem: - `constexpr_sum` is implemented using `Array` which means the function needs to be a function template so that the size can be deduced. Solution: - Change the `Array` function argument to a `Span` since `Span` now is `constexpr`.
2020-10-21HashFunctions: constexpr capabilityLenny Maiorani
Problem: - Hash functions can be `constexpr`, but are not. Solution: - Change `inline` keyword to `constexpr`. - Add `static_assert` tests to ensure the hash functions work in a `constexpr` context.
2020-10-21TestHashFunctions: Tests to bind hash functionalityLenny Maiorani
Problem: - The hash functions have no associated tests, so there is nothing binding their behavior. Solution: - Bind the hash function behavior by adding tests. - Use the existing behavior as "correct".
2020-10-20Checked: constexpr supportLenny Maiorani
Problem: - `Checked` is not `constexpr`-aware. Solution: - Decorate member functions with `constexpr` keyword. - Add tests to ensure the functionality where possible.
2020-10-17CircularQueue: Ensure constructor does not construct any valuesLenny Maiorani
Problem: - There is no test which guarantees the CircularQueue does not construct any objects of the value type. The goal is to have uninitialized memory which can be used. Solution: - Add a test requiring that the constructor of the value type is never called.
2020-10-17AK+Format: Add outln(FILE*, ...) overload.asynts
This commit also removes a few functions like raw_out and vwarn. If we want to write raw output, we can do this as follows: out("{}", "Hello, World!"); The vout stuff isn't really public API anyways, so no need for another vwarn.
2020-10-17BinarySearch: constexpr supportLenny Maiorani
Problem: - It is not possible to perform a binary search at compile-time because `binary_search` is not `constexpr`-aware. Solution: - Add `constexpr` support.
2020-10-16Span: constexpr supportLenny Maiorani
Problem: - `Span` is not `constexpr` aware. Solution: - Add `constexpr` support for all parts that do not require `reinterpret_cast`. - Modify tests which use the `constexpr` functions.
2020-10-16AK: Add some more checks to the HashMap testAndreas Kling
2020-10-15AK: Improve HashMap tests a little bitAndreas Kling
2020-10-13Base64: Pre-allocate size of input and outputLenny Maiorani
Problem: - Output of decode and encode grow as the decode and encode happen. This is inefficient because a large size will require many reallocations. - `const` qualifiers are missing on variables which are not intended to change. Solution: - Since the size of the decoded or encoded message is known prior to starting, calculate the size and set the output to that size immediately. All appends will not incur the reallocation overhead. - Add `const` qualifiers to show intent.
2020-10-12AK: Add SourceGenerator class.asynts
2020-10-08Endian: constexpr constructors and conversion operatorsLenny Maiorani
Problem: - Constructors and conversion operators are not `constexpr`, but they can be. - `constexpr` is needed here so that other classes can add `constexpr` evaluation. Solution: - Add the `constexpr` keyword to the constructors and conversion operators. - Add `static_assert` tests which ensure the capability works.
2020-10-08AK+Format: Add SFINAE wrapper 'FormatIfSupported'.asynts
2020-10-08AK+Format: Use pointer mode for pointers by default.asynts
2020-10-06IRCClient: Use new format functions.asynts
2020-10-06AK+Format: Make it possible to format string literals as pointers.asynts
String literals are just pointers to a constant character. It should be possible to format them as such. (The default is to print them as strings still.)
2020-10-06AK+Format: Exclude prefix from width calculation.asynts
When we write the format specifier '{:#08x}' we are asking for eight significant digits, zero padding and the prefix '0x'. However, previously we got only six significant digits because the prefix counted towards the width. (The number '8' here is the total width and not the number of significant digits.) Both fmtlib and printf shared this behaviour. However, I am introducing a special case here because when we do zero padding we really only care about the digits and not the width. Notice that zero padding is a special case anyways, because zero padding goes after the prefix as opposed to any other padding which goes before it.
2020-10-03Everywhere: Fix more typosLinus Groh
2020-10-02AK+Format: Do some housekeeping in the format implementation.asynts
2020-10-02AK: Add formatter for pointer types.asynts
2020-10-02AK: Add formatter for boolean values.asynts
2020-09-29AK+Format: Add support for integer to character casts.asynts
Now the following is possible: outf("{:c}", 75); // K
2020-09-29AK+Format: Support all format specifiers for strings.asynts
The following is now possible: outf("{:.4}", "abcdef"); // abcd outf("{:*<8}", "abcdef"); // abcdef**
2020-09-28AK+Format: Support default index in replacement field.asynts
The following does now work: outf("{:0{}}", 1, 3); // 001
2020-09-28AK+Format: Keep type information for integers in TypeErasedParameter.asynts
It's now save to pass a signed integer as parameter and then use it as replacement field (previously, this would just cast it to size_t which would be bad.)
2020-09-28AK+Format: Clean up format specifier parsing using GenericLexer.asynts
Also adds support for replacement fields.
2020-09-26AK+Format: Use the new format backend in the implementation.asynts
2020-09-26AK+Format: Add new integer to string backend.asynts
I put this into the <AK/PrintfImplementation.h> header in the hope that it could be re-used by the printf implementation. That would not be super trivial though, so I am not doing that now.
2020-09-25Meta+AK: Make clang-format-10 cleanBen Wiederhake
2020-09-23Applications+IRCClient: Use new format functions.asynts
2020-09-23AK: Resolve format related circular dependencies properly.asynts
With this commit, <AK/Format.h> has a more supportive role and isn't used directly. Essentially, there now is a public 'vformat' function ('v' for vector) which takes already type erased parameters. The name is choosen to indicate that this function behaves similar to C-style functions taking a va_list equivalent. The interface for frontend users are now 'String::formatted' and 'StringBuilder::appendff'.
2020-09-23AK: Allow calling format without arguments.asynts
2020-09-22AK: Add missing overload to format.asynts
I had this in #3580 but I must have lost it during rebasing.
2020-09-22AK: Consider long and unsigned long as integral types.asynts
Two things I hate about C++: 1. 'int', 'signed int' and 'unsigned int' are two distinct types while 'char, 'signed char' and 'unsigned char' are *three* distinct types. This is because 'signed int' is an alias for 'int' but 'signed char' can't be an alias for 'char' because on some weird systems 'char' is unsigned. One might think why not do it the other way around, make 'int' an alias for 'signed int' and 'char' an alias for whatever that is on the platform, or make 'char' signed on all platforms. But who am I to ask? 2. 'unsigned long' and 'unsigned long long' are always different types, even if both are 64 bit numbers. This commit fixes a few bugs that coming from this. See Also: 1b3169f405ac9250b65ee3608e2962f51d2d8e3c.