Skip to content

add more tests to yalantinglibs #7368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/y/yalantinglibs/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ package("yalantinglibs")
on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include "ylt/struct_pack.hpp"
#include "ylt/coro_http/coro_http_client.hpp"
#include "ylt/coro_io/coro_file.hpp"

struct person {
int64_t id;
std::string name;
Expand All @@ -88,5 +91,33 @@ package("yalantinglibs")
person person1{.id = 1, .name = "hello struct pack", .age = 20, .salary = 1024.42};
std::vector<char> buffer = struct_pack::serialize(person1);
}

async_simple::coro::Lazy<std::string> test2(std::string path) {
coro_io::coro_file file(path, std::ios::in | std::ios::binary);
if (!file.is_open()) {
throw std::runtime_error("Error opening file: " + path);
}

auto size = file.file_size();

if (size == 0) {
co_return "";
}

std::string content(size, '\0');
auto [ec, read_size] = co_await file.async_read(content.data(), size);
if (ec) {
throw std::runtime_error("Error reading file: " + path + " - " +
ec.message());
}

if (read_size != size) {
throw std::runtime_error("Error reading file: " + path +
" - Expected size: " + std::to_string(size) +
", Read size: " + std::to_string(read_size));
}

co_return content;
}
]]}, {configs = {languages = "c++20"}}))
end)
Loading