2024-03-26 12:13:11 -04:00
|
|
|
/*
|
2025-11-26 14:13:23 -05:00
|
|
|
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
|
2024-03-26 12:13:11 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
|
|
|
|
|
|
#include <AK/GenericLexer.h>
|
|
|
|
|
#include <AK/String.h>
|
2025-11-26 14:13:23 -05:00
|
|
|
#include <LibHTTP/HTTP.h>
|
2024-03-26 12:13:11 -04:00
|
|
|
|
|
|
|
|
TEST_CASE(collect_an_http_quoted_string)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
auto test = "\"\""_string;
|
|
|
|
|
GenericLexer lexer { test };
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
auto result = HTTP::collect_an_http_quoted_string(lexer);
|
2024-03-26 12:13:11 -04:00
|
|
|
EXPECT_EQ(result, "\"\""_string);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto test = "\"abc\""_string;
|
|
|
|
|
GenericLexer lexer { test };
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
auto result = HTTP::collect_an_http_quoted_string(lexer);
|
2024-03-26 12:13:11 -04:00
|
|
|
EXPECT_EQ(result, "\"abc\""_string);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto test = "foo \"abc\""_string;
|
|
|
|
|
|
|
|
|
|
GenericLexer lexer { test };
|
|
|
|
|
lexer.ignore(4);
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
auto result = HTTP::collect_an_http_quoted_string(lexer);
|
2024-03-26 12:13:11 -04:00
|
|
|
EXPECT_EQ(result, "\"abc\""_string);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto test = "foo=\"abc\""_string;
|
|
|
|
|
|
|
|
|
|
GenericLexer lexer { test };
|
|
|
|
|
lexer.ignore(4);
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
auto result = HTTP::collect_an_http_quoted_string(lexer);
|
2024-03-26 12:13:11 -04:00
|
|
|
EXPECT_EQ(result, "\"abc\""_string);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto test = "foo=\"abc\" bar"_string;
|
|
|
|
|
|
|
|
|
|
GenericLexer lexer { test };
|
|
|
|
|
lexer.ignore(4);
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
auto result = HTTP::collect_an_http_quoted_string(lexer);
|
2024-03-26 12:13:11 -04:00
|
|
|
EXPECT_EQ(result, "\"abc\""_string);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
auto test = "\"abc\" bar"_string;
|
|
|
|
|
GenericLexer lexer { test };
|
|
|
|
|
|
2025-11-26 14:13:23 -05:00
|
|
|
auto result = HTTP::collect_an_http_quoted_string(lexer);
|
2024-03-26 12:13:11 -04:00
|
|
|
EXPECT_EQ(result, "\"abc\""_string);
|
|
|
|
|
}
|
|
|
|
|
}
|