TestFetchInfrastructure.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #include <AK/GenericLexer.h>
  8. #include <AK/String.h>
  9. #include <LibWeb/Fetch/Infrastructure/HTTP.h>
  10. TEST_CASE(collect_an_http_quoted_string)
  11. {
  12. {
  13. auto test = "\"\""_string;
  14. GenericLexer lexer { test };
  15. auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer));
  16. EXPECT_EQ(result, "\"\""_string);
  17. }
  18. {
  19. auto test = "\"abc\""_string;
  20. GenericLexer lexer { test };
  21. auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer));
  22. EXPECT_EQ(result, "\"abc\""_string);
  23. }
  24. {
  25. auto test = "foo \"abc\""_string;
  26. GenericLexer lexer { test };
  27. lexer.ignore(4);
  28. auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer));
  29. EXPECT_EQ(result, "\"abc\""_string);
  30. }
  31. {
  32. auto test = "foo=\"abc\""_string;
  33. GenericLexer lexer { test };
  34. lexer.ignore(4);
  35. auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer));
  36. EXPECT_EQ(result, "\"abc\""_string);
  37. }
  38. {
  39. auto test = "foo=\"abc\" bar"_string;
  40. GenericLexer lexer { test };
  41. lexer.ignore(4);
  42. auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer));
  43. EXPECT_EQ(result, "\"abc\""_string);
  44. }
  45. {
  46. auto test = "\"abc\" bar"_string;
  47. GenericLexer lexer { test };
  48. auto result = MUST(Web::Fetch::Infrastructure::collect_an_http_quoted_string(lexer));
  49. EXPECT_EQ(result, "\"abc\""_string);
  50. }
  51. }