Files
yepper ddcd3fb9c8 chore(format): align python and c++ file formatting (#2001)
* chore(format): align python and c++ file formatting

* chore: update urllib3 to 2.7.0 and clean test imports

1. bump urllib3 dependency from 2.6.3 to 2.7.0
2. remove unused pytest import and RoleScope import from test file

* style: format list comprehensions and lambda function for readability

Adjust the line breaks in the list comprehension in the VikingSearchTool class to follow standard Python formatting conventions, and rewrap the lambda assignment in the test case to improve code readability without changing functionality.

* style: fix line wrapping and remove extra blank line

- remove stray blank line in ov_server.py
- wrap long logger.info line in memory.py for better readability

* style: fix targeted ruff lint violations

* chore: clean up unused imports and reorder code

This commit removes unused imports, reorders import statements for better consistency,
and simplifies some test file imports. Changes include:
- Remove redundant blank lines and unused imports across multiple test files and core modules
- Reorder imports in openviking hooks module to follow standard layout
- Fix import ordering in memory isolation handler
- Simplify php parser type imports
- Move volcengine mock import to correct position in test file

* refactor(uri utils): remove extra blank lines in uri.py

clean up redundant whitespace to improve code readability
2026-05-13 17:53:09 +08:00

141 lines
4.3 KiB
C++

// Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
// SPDX-License-Identifier: AGPL-3.0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cassert>
#include <cmath>
#include "common/string_utils.h"
#include "common/zip_sort.h"
#include "common/log_utils.h"
#include "spdlog/spdlog.h"
// Simple Assertion Macro
#define ASSERT_EQ(a, b) \
if ((a) != (b)) { \
SPDLOG_ERROR("Assertion failed: {} != {} ({} != {}) at {}:{}", #a, #b, \
(a), (b), __FILE__, __LINE__); \
std::exit(1); \
}
#define ASSERT_TRUE(a) \
if (!(a)) { \
SPDLOG_ERROR("Assertion failed: {} at {}:{}", #a, __FILE__, __LINE__); \
std::exit(1); \
}
using namespace vectordb;
void test_string_split() {
SPDLOG_INFO("[Running] test_string_split");
std::vector<std::string> tokens;
// Case 1: Normal split
split(tokens, "apple,banana,orange", ",");
ASSERT_EQ(tokens.size(), 3);
ASSERT_EQ(tokens[0], "apple");
ASSERT_EQ(tokens[1], "banana");
ASSERT_EQ(tokens[2], "orange");
tokens.clear();
// Case 2: Empty string
split(tokens, "", ",");
ASSERT_EQ(tokens.size(), 0);
tokens.clear();
// Case 3: No delimiter
split(tokens, "helloworld", ",");
ASSERT_EQ(tokens.size(), 1);
ASSERT_EQ(tokens[0], "helloworld");
tokens.clear();
// Case 4: Continuous delimiters
// According to split impl: if (end > start) tokens.push_back(...)
// This means empty strings between continuous delimiters are skipped.
split(tokens, "a,,b", ",");
ASSERT_EQ(tokens.size(), 2);
ASSERT_EQ(tokens[0], "a");
ASSERT_EQ(tokens[1], "b");
tokens.clear();
SPDLOG_INFO("[Passed] test_string_split");
}
void test_string_format() {
SPDLOG_INFO("[Running] test_string_format");
// Case 1: Basic format
std::string s1 = sformat("Hello {}", "World");
ASSERT_EQ(s1, "Hello World");
// Case 2: Multiple arguments
std::string s2 = sformat("{} + {} = {}", 1, 2, 3);
ASSERT_EQ(s2, "1 + 2 = 3");
// Case 3: Float number (Check prefix only due to to_string precision)
std::string s3 = sformat("Value: {}", 3.14);
ASSERT_TRUE(s3.find("Value: 3.14") == 0);
// Case 4: Fewer arguments than placeholders (Should preserve {})
std::string s4 = sformat("{} {}", "OnlyOne");
ASSERT_EQ(s4, "OnlyOne {}");
// Case 5: More arguments than placeholders (Extra args ignored)
std::string s5 = sformat("{}", "First", "Second");
ASSERT_EQ(s5, "First");
SPDLOG_INFO("[Passed] test_string_format");
}
void test_zip_sort() {
SPDLOG_INFO("[Running] test_zip_sort");
// Case 1: Basic sort
std::vector<int> keys = {3, 1, 4, 2};
std::vector<std::string> values = {"C", "A", "D", "B"};
// Sort ascending by key
ZipSortBranchOptimized([](int a, int b) { return a < b; }, keys.begin(),
keys.end(), values.begin(), values.end());
ASSERT_EQ(keys[0], 1);
ASSERT_EQ(values[0], "A");
ASSERT_EQ(keys[1], 2);
ASSERT_EQ(values[1], "B");
ASSERT_EQ(keys[2], 3);
ASSERT_EQ(values[2], "C");
ASSERT_EQ(keys[3], 4);
ASSERT_EQ(values[3], "D");
// Case 2: Empty array
std::vector<int> empty_keys;
std::vector<int> empty_vals;
ZipSortBranchOptimized([](int a, int b) { return a < b; }, empty_keys.begin(),
empty_keys.end(), empty_vals.begin(),
empty_vals.end());
ASSERT_TRUE(empty_keys.empty());
// Case 3: Single element
std::vector<int> single_key = {1};
std::vector<int> single_val = {100};
ZipSortBranchOptimized([](int a, int b) { return a < b; }, single_key.begin(),
single_key.end(), single_val.begin(),
single_val.end());
ASSERT_EQ(single_key[0], 1);
ASSERT_EQ(single_val[0], 100);
SPDLOG_INFO("[Passed] test_zip_sort");
}
int main() {
init_logging("INFO", "stdout", "[%Y-%m-%d %H:%M:%S.%e] [%l] %v");
SPDLOG_INFO("Starting Common Tests...");
test_string_split();
test_string_format();
test_zip_sort();
SPDLOG_INFO("All Common Tests Passed!");
return 0;
}