diff --git a/cpp/include/kvikio/defaults.hpp b/cpp/include/kvikio/defaults.hpp index 71773f23e0..1e06e90acc 100644 --- a/cpp/include/kvikio/defaults.hpp +++ b/cpp/include/kvikio/defaults.hpp @@ -57,6 +57,9 @@ namespace detail { */ CompatMode parse_compat_mode_str(std::string_view compat_mode_str); +std::vector parse_http_status_codes(std::string_view nev_var_name, + std::string const status_codes); + } // namespace detail template diff --git a/cpp/tests/test_defaults.cpp b/cpp/tests/test_defaults.cpp index c4a88775e4..3953cca28e 100644 --- a/cpp/tests/test_defaults.cpp +++ b/cpp/tests/test_defaults.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, NVIDIA CORPORATION. + * Copyright (c) 2024-2025, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,3 +51,25 @@ TEST(Defaults, parse_compat_mode_str) } } } + +TEST(Defaults, parse_http_status_codes) +{ + { + std::vector inputs{ + "429,500", "429, 500", " 429,500", "429, 500", "429 ,500", "429,500 "}; + std::vector expected = {429, 500}; + // std::string const input = "429,500,501,503"; + for (const auto& input : inputs) { + EXPECT_EQ(kvikio::detail::parse_http_status_codes("KVIKIO_HTTP_STATUS_CODES", input), + expected); + } + } + + { + std::vector inputs{"429,", ",429", "a,b", "429,,500", "429,1000"}; + for (const auto& input : inputs) { + EXPECT_THROW(kvikio::detail::parse_http_status_codes("KVIKIO_HTTP_STATUS_CODES", input), + std::invalid_argument); + } + } +}