ladybird/Tests/LibWeb/test-web/Fuzzy.h
Sam Atkins 9b6c26e347 Tests: Include test URL in fuzzy mismatch reports
The test logs tend to get a bit mixed together, so this makes it
possible to identify which values correspond to which test when multiple
are failing at once.
2025-08-06 13:51:36 +02:00

47 lines
1.2 KiB
C++

/*
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <LibGfx/Forward.h>
#include <LibURL/URL.h>
namespace TestWeb {
struct FuzzyRange {
u64 minimum_value;
u64 maximum_value;
bool contains(u64 value) const { return value >= minimum_value && value <= maximum_value; }
};
struct FuzzyMatch {
Optional<URL::URL> reference;
FuzzyRange color_value_error;
FuzzyRange pixel_error_count;
};
bool fuzzy_screenshot_match(URL::URL const& test_url, URL::URL const& reference, Gfx::Bitmap const&, Gfx::Bitmap const&, Vector<FuzzyMatch> const&);
ErrorOr<FuzzyMatch> parse_fuzzy_match(Optional<URL::URL const&> reference, String const&);
ErrorOr<FuzzyRange> parse_fuzzy_range(String const&);
}
namespace AK {
template<>
struct Formatter<TestWeb::FuzzyRange> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, TestWeb::FuzzyRange const& value)
{
return Formatter<FormatString>::format(builder, "FuzzyRange [{}-{}]"sv, value.minimum_value, value.maximum_value);
}
};
}