mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
c70f45ff44
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
37 lines
1 KiB
C++
37 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
|
|
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
#include <AK/SourceLocation.h>
|
|
#include <AK/StringView.h>
|
|
|
|
TEST_CASE(basic_scenario)
|
|
{
|
|
auto location = SourceLocation::current();
|
|
EXPECT_EQ(__LINE__ - 1u, location.line_number());
|
|
|
|
// Obviously not the prettiest way.
|
|
StringView function { __FUNCTION__, strlen(__FUNCTION__) };
|
|
StringView file { __FILE__, strlen(__FILE__) };
|
|
|
|
EXPECT_EQ(function, location.function_name());
|
|
EXPECT_EQ(file, location.filename());
|
|
}
|
|
|
|
static StringView test_default_arg(SourceLocation const& loc = SourceLocation::current())
|
|
{
|
|
return loc.function_name();
|
|
}
|
|
|
|
TEST_CASE(default_arg_scenario)
|
|
{
|
|
auto actual_calling_function = test_default_arg();
|
|
auto expected_calling_function = StringView { __FUNCTION__, strlen(__FUNCTION__) };
|
|
|
|
EXPECT_EQ(expected_calling_function, actual_calling_function);
|
|
}
|