Commit Graph

960 Commits

Author SHA1 Message Date
Sam Atkins
d55f763fcd Tests: Replace uses of JsonObject::get_deprecated()/get_ptr() 2023-01-26 09:57:14 -05:00
Tim Schumacher
982ebbc304 LibWasm: Port the parser to Core::Stream 2023-01-25 17:10:05 +03:30
Timothy Flynn
427b82065c AK: Add a method to create a String with a repeated code point 2023-01-24 16:23:50 -05:00
Timothy Flynn
d50724956e AK: Add a method to find the byte offset of a code point 2023-01-24 16:23:50 -05:00
Nico Weber
8b5b767465 AK: Print leading zeroes after the dot for FixedPoint numbers
As a nearby comment says, "This is a terrible approximation".
This doesn't make things less terrible, but it does make things
more correct in the given framework of terribleness.

Fixes #17156.
2023-01-24 13:24:21 +01:00
Nico Weber
3423b54eb9 LibTextCodec: Make utf-16be and utf-16le codecs actually work
There were two problems:

1. They didn't handle surrogates
2. They used signed chars, leading to eg 0x00e4 being treated as 0xffe4

Also add a basic test that catches both issues.
There's some code duplication with Utf16CodePointIterator::operator*(),
but let's get things working first.
2023-01-22 21:30:44 +00:00
Timothy Flynn
12c8bc3e85 AK: Add a String factory to create a string from a single code point 2023-01-22 01:03:13 +00:00
Andrew Kaster
046c23f567 Kernel+LibC: Move LibC/signal_numbers.h to Kernel/API/POSIX
Make Userland and Tests users just include signal.h, and move Kernel
users to the new API file.
2023-01-21 10:43:59 -07:00
martinfalisse
aec2dadfdd AK: Add split() for String 2023-01-21 14:35:00 +01:00
Timothy Flynn
4f5353cbb8 AK: Rename double_hash to rehash_for_collision
The name is currently quite confusing as it indicates it hashes doubles.
2023-01-21 10:36:14 +01:00
Tim Schumacher
0245614a4f LibCore: Remove FileStream 2023-01-20 20:50:42 +00:00
Tim Schumacher
9eb040af32 Tests: Use Core::Stream to write output files in LibGL tests 2023-01-20 20:50:42 +00:00
Tim Schumacher
d7eead4f4c AK: Remove DuplexMemoryStream 2023-01-20 20:48:40 +00:00
Ali Mohammad Pur
7d4a30af56 LibCore: Avoid logical OOB read in AllocatingMemoryStream::offset_of()
The previous impl was trimming the last chunk to the free space instead
of the used space, which yielded an OOB read if the needle wasn't found.
2023-01-20 20:34:31 +00:00
Timothy Flynn
d48266a420 AK: Support creating known short string literals at compile time
In cases where we know a string literal will fit in the short string
storage, we can do so at compile time without needing to handle error
propagation. If the provided string literal is too long, a compilation
error will be emitted due to the failed VERIFY statement being a non-
constant expression.
2023-01-20 14:24:12 -05:00
Sam Atkins
93ca5d4772 Tests: Use AK::shuffle() for shuffling 2023-01-20 17:45:33 +00:00
Liav A
20033d06d8 Tests/LibGfx: Fix test_gif test case
We should expect the GIF image to be animated, therefore fix that
condition.
2023-01-20 17:05:09 +00:00
Liav A
da525ccc43 Tests/LibGfx: Fix test_not_ico test case
We should expect the sniffing method and the initialize method to fail
because this test case is testing that the ICO image decoder should not
decode random data within it.
2023-01-20 17:05:09 +00:00
Liav A
57e19a7e56 LibGfx: Re-structure the whole initialization pattern for image decoders
When trying to figure out the correct implementation, we now have a very
strong distinction on plugins that are well suited for sniffing, and
plugins that need a MIME type to be chosen.

Instead of having multiple calls to non-static virtual sniff methods for
each Image decoding plugin, we have 2 static methods for each
implementation:
1. The sniff method, which in contrast to the old method, gets a
    ReadonlyBytes parameter and ensures we can figure out the result
    with zero heap allocations for most implementations.
2. The create method, which just creates a new instance so we don't
    expose the constructor to everyone anymore.

In addition to that, we have a new virtual method called initialize,
which has a per-implementation initialization pattern to actually ensure
each implementation can construct a decoder object, and then have a
correct context being applied to it for the actual decoding.
2023-01-20 15:13:31 +00:00
Timothy Flynn
ca62aeb6bd LibLocale+LibJS: Port locale parsing and processing to String
In order to prevent this commit from having to refactor almost all of
Intl, the goal here is to update the internal parsing/canonicalization
of locales within LibLocale only. Call sites which are already equiped
to handle String and OOM errors do so, however.
2023-01-19 20:57:30 +00:00
Sam Atkins
73350b8492 Tests: Mark TestCommonmark as DISABLED
This has no effect right now, but will allow us to use this same cmake
file from Lagom.
2023-01-19 11:50:10 +00:00
Sam Atkins
7b82f37ba3 Tests: Add missing library dependency for LibTimeZone tests 2023-01-19 11:50:10 +00:00
Sam Atkins
c0c700ed11 Tests: Add missing library dependencies for LibGL tests
These are required for running on Lagom.
2023-01-19 11:50:10 +00:00
Sam Atkins
1910dc8976 Tests: Move test PDF files into Tests/LibPDF
Let's put test files with the tests themselves, instead of a random user
directory. (But still copy them so they appear in the user directory
for convenience.)
2023-01-19 11:50:10 +00:00
Sam Atkins
a4c8353472 Tests: Correct serenity_test() invocation for LibTTF
Putting the LibTTF tests into the LibGfx directory worked fine before,
but causes issues if we try and call this from Lagom. Also, it's tidier
to put LibTTF tests in a LibTTF directory. :^)
2023-01-19 11:50:10 +00:00
Timothy Flynn
8438c509e9 LibCore: Make the FileWatcher test resilient against outside events
The test currently watches /tmp, which the OS can create/modify files
under at any time outside of our control. So just ignore events that we
aren't interested in.

Also test removing an item from the FileWatcher.
2023-01-19 11:29:48 +00:00
Peter Elliott
b217045f8f AK: Don't write trailing zeros with %g 2023-01-19 12:22:24 +01:00
Tim Schumacher
daf181caa8 LibCore: Let offset-related Stream functions return an unsigned value
A negative return value doesn't make sense for any of those functions.
The return types were inherited from POSIX, where they also need to have
an indicator for an error (negative values).
2023-01-19 11:41:56 +01:00
Timothy Flynn
537fcaf59e AK+LibUnicode: Provide Unicode-aware caseless String matching
The Unicode spec defines much more complicated caseless matching
algorithms in its Collation spec. This implements the "basic" case
folding comparison.
2023-01-18 14:43:40 +00:00
Timothy Flynn
8f2589b3b0 LibUnicode: Parse and generate case folding code point data
Case folding rules have a similar mapping style as special casing rules,
where one code point may map to zero or more case folding rules. These
will be used for case-insensitive string comparisons. To see how case
folding can differ from other casing rules, consider "ß" (U+00DF):

    >>> "ß".lower()
    'ß'

    >>> "ß".upper()
    'SS'

    >>> "ß".title()
    'Ss'

    >>> "ß".casefold()
    'ss'
2023-01-18 14:43:40 +00:00
Timothy Flynn
8ca528217c LibCore: Implement FileWatcher for Linux
This implements FileWatcher using inotify filesystem events. Serenity's
InodeWatcher is remarkably similar to inotify, so this is almost an
identical implementation.

The existing TestLibCoreFileWatcher test is added to Lagom (currently
just for Linux).

This does not implement BlockingFileWatcher as that is currently not
used anywhere but on Serenity.
2023-01-18 06:46:12 -05:00
Sam Atkins
1dd6b7f5b7 AK+Everywhere: Rename JsonObject::get() to ::get_deprecated()
This is a preparatory step to making `get()` return `ErrorOr`.
2023-01-17 19:52:52 -05:00
Sam Atkins
efe4329f9f AK: Add JsonValue::{is,as}_integer() methods
The existing `is_i32()` and friends only check if `i32` is their
internal type, but a value such as `0` could be literally any integer
type internally. `is_integer<T>()` instead determines whether the
contained value is an integer and can fit inside T.
2023-01-17 19:52:52 -05:00
Tim Schumacher
add2e2c076 LibCore: Do short forward seeks by discarding bytes from the buffer
This saves us an actual seek and rereading already stored buffer data in
cases where the seek is entirely covered by the currently buffered data.
This is especially important since we implement `discard` using `seek`
for seekable streams.
2023-01-17 21:56:56 +01:00
Tim Schumacher
bdf991fe76 LibCore: Calculate the correct seek offset for buffered streams 2023-01-17 21:56:56 +01:00
Timothy Flynn
d6ddca0c0f AK+LibUnicode: Provide Unicode-aware String titlecase transformation 2023-01-16 18:33:44 -05:00
Timothy Flynn
bc51017a03 LibUnicode: Support full case folding for titlecasing a string
Unicode declares that to titlecase a string, the first cased code point
after each word boundary should be transformed to its titlecase mapping.
All other codepoints are transformed to their lowercase mapping.
2023-01-16 18:33:44 -05:00
Timothy Flynn
b562348d31 LibUnicode: Generate simple case folding mappings for titlecase
Note we already generate the special case foldings for titlecase.
2023-01-16 18:33:44 -05:00
Lucas CHOLLET
3b824ec8c9 AK+Test: Fix a logic error in CircularBuffer::offset_of()
This error was introduced by 9a7accdd and had a significant impact on
`BufferedFile` behavior. Hence, we started seeing crash in test262.

By itself, the issue was a wrong calculation of the internal reading
spans when using the `read` and `until` parameters. Which can lead to
at worse crash in VERIFY and at least weird behaviors as missed needles
or detections out of bounds.

It was also accompanied by an erroneous test.

This patch fixes the bug, the test and also provides more tests.
2023-01-15 23:23:24 +00:00
Liav A
71f275b5ad Tests/LibGfx: Add tests for compressed TGA images 2023-01-15 12:43:03 +01:00
Liav A
6bf2460231 Tests/LibGfx: Add tests for top-left and bottom-left TGA images 2023-01-15 12:43:03 +01:00
Timothy Flynn
afeb7273cc LibJS+Everywhere: Rename Value::to_string to to_deprecated_string 2023-01-15 01:00:20 +00:00
Timothy Flynn
3ad1f250e7 LibCrypto: Define *BigInteger::to_base to convert big integers to String 2023-01-15 01:00:20 +00:00
Timothy Flynn
0ddc2e1f50 LibCrypto+Everywhere: Rename *BigInteger::to_base to to_base_deprecated 2023-01-15 01:00:20 +00:00
Timothy Flynn
bd9b65e82f AK: Add String::is_one_of for variadic string comparison 2023-01-15 01:00:20 +00:00
Timothy Flynn
9db9b2f9be AK: Add a somewhat naive implementation of String::reverse
This will reverse the String's code points (i.e. not just its bytes),
but is not aware of grapheme clusters.
2023-01-15 01:00:20 +00:00
Lucas CHOLLET
9a7accddb7 AK: Add an optional starting offset to CircularBuffer::offset_of
This parameter allows to start searching after an offset. For example,
to resume a search.

It is unfortunately a breaking change in API so this patch also modifies
one user and one test.
2023-01-14 16:20:30 -07:00
Ben Wiederhake
b3d2fdceb1 LibWeb+Tests: Demonstrate slowness of CSS::value_id_from_string 2023-01-14 15:43:27 -07:00
Ben Wiederhake
0687a75eaa LibWeb: Run tests in lagom if ENABLE_LAGOM_LIBWEB is set 2023-01-14 15:43:27 -07:00
Ben Wiederhake
79b9dd6248 AK+Tests: Make CaseInsensitiveStringViewTraits work with HashMap again 2023-01-14 15:43:27 -07:00