Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 6599960

Browse files
committed
add unit test
1 parent 457e5a3 commit 6599960

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "gtest/gtest.h"
2+
#include "utils/url_parser.h"
3+
4+
class UrlParserTestSuite : public ::testing::Test {
5+
protected:
6+
constexpr static auto kValidUrlWithOnlyPaths{"https://jan.ai/path1/path2"};
7+
};
8+
9+
TEST_F(UrlParserTestSuite, TestParseUrlCorrectly) {
10+
auto url = url_parser::FromUrlString(kValidUrlWithOnlyPaths);
11+
12+
EXPECT_EQ(url.host, "jan.ai");
13+
EXPECT_EQ(url.protocol, "https");
14+
EXPECT_EQ(url.pathParams.size(), 2);
15+
}
16+
17+
TEST_F(UrlParserTestSuite, ConstructUrlCorrectly) {
18+
auto url = url_parser::Url{
19+
.protocol = "https",
20+
.host = "jan.ai",
21+
.pathParams = {"path1", "path2"},
22+
};
23+
auto url_str = url_parser::FromUrl(url);
24+
25+
EXPECT_EQ(url_str, kValidUrlWithOnlyPaths);
26+
}

engine/utils/url_parser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <sstream>
33
#include <string>
44
#include <unordered_map>
5+
#include <variant>
56
#include <vector>
67
#include "exceptions/malformed_url_exception.h"
78

@@ -26,6 +27,9 @@ inline void SplitPathParams(const std::string& input,
2627
std::string token;
2728
std::istringstream tokenStream(input);
2829
while (std::getline(tokenStream, token, '/')) {
30+
if (token.empty()) {
31+
continue;
32+
}
2933
pathList.push_back(token);
3034
}
3135
}

0 commit comments

Comments
 (0)