Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
#include <Void/Data/Csv.hpp>
|
|
#include <Void/Testing/Assert.hpp>
|
|
#include <Void/Testing/Test.hpp>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// ── parse ─────────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test csv_parse_simple()
|
|
{
|
|
const auto t = Void::Csv::parse("a,b,c\n1,2,3\n");
|
|
Void::Testing::expect_eq(t.size(), std::size_t{2});
|
|
Void::Testing::expect_eq(t[0][0], std::string{"a"});
|
|
Void::Testing::expect_eq(t[1][2], std::string{"3"});
|
|
}
|
|
|
|
Void::Testing::Test csv_parse_quoted_field()
|
|
{
|
|
const auto t = Void::Csv::parse("\"hello, world\",42\n");
|
|
Void::Testing::expect_eq(t[0][0], std::string{"hello, world"});
|
|
Void::Testing::expect_eq(t[0][1], std::string{"42"});
|
|
}
|
|
|
|
Void::Testing::Test csv_parse_doubled_quote()
|
|
{
|
|
const auto t = Void::Csv::parse("\"say \"\"hi\"\"\"\n");
|
|
Void::Testing::expect_eq(t[0][0], std::string{"say \"hi\""});
|
|
}
|
|
|
|
Void::Testing::Test csv_parse_empty_fields()
|
|
{
|
|
const auto t = Void::Csv::parse(",b,\n");
|
|
Void::Testing::expect_eq(t[0].size(), std::size_t{3});
|
|
Void::Testing::expect(t[0][0].empty());
|
|
Void::Testing::expect(t[0][2].empty());
|
|
}
|
|
|
|
Void::Testing::Test csv_parse_custom_delimiter()
|
|
{
|
|
const auto t = Void::Csv::parse("a;b;c\n", ';');
|
|
Void::Testing::expect_eq(t[0].size(), std::size_t{3});
|
|
Void::Testing::expect_eq(t[0][1], std::string{"b"});
|
|
}
|
|
|
|
Void::Testing::Test csv_parse_crlf()
|
|
{
|
|
const auto t = Void::Csv::parse("a,b\r\n1,2\r\n");
|
|
Void::Testing::expect_eq(t.size(), std::size_t{2});
|
|
}
|
|
|
|
Void::Testing::Test csv_parse_empty_input()
|
|
{
|
|
const auto t = Void::Csv::parse("");
|
|
Void::Testing::expect(t.empty());
|
|
}
|
|
|
|
// ── serialize ─────────────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test csv_serialize_simple()
|
|
{
|
|
const Void::Csv::Table t = {{"a","b","c"},{"1","2","3"}};
|
|
const auto s = Void::Csv::serialize(t);
|
|
Void::Testing::expect(s.find("a,b,c") != std::string::npos);
|
|
Void::Testing::expect(s.find("1,2,3") != std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test csv_serialize_quotes_commas()
|
|
{
|
|
const Void::Csv::Table t = {{"hello, world"}};
|
|
const auto s = Void::Csv::serialize(t);
|
|
Void::Testing::expect(s.find('"') != std::string::npos);
|
|
}
|
|
|
|
Void::Testing::Test csv_round_trip()
|
|
{
|
|
const Void::Csv::Table original = {
|
|
{"Name","Score"},{"Alice","100"},{"Bob","90"}};
|
|
const auto serialized = Void::Csv::serialize(original);
|
|
const auto parsed = Void::Csv::parse(serialized);
|
|
Void::Testing::expect_eq(parsed.size(), original.size());
|
|
Void::Testing::expect_eq(parsed[0][0], original[0][0]);
|
|
}
|
|
|
|
// ── parse_with_header ─────────────────────────────────────────────────────────
|
|
|
|
Void::Testing::Test csv_with_header_get_column()
|
|
{
|
|
const auto csv = Void::Csv::parse_with_header("Name,Score\nAlice,100\n");
|
|
Void::Testing::expect(csv.has_value());
|
|
const auto score = csv->get(csv->rows[0], "Score");
|
|
Void::Testing::expect(score.has_value());
|
|
Void::Testing::expect_eq(*score, std::string_view{"100"});
|
|
}
|
|
|
|
Void::Testing::Test csv_with_header_unknown_col()
|
|
{
|
|
const auto csv = Void::Csv::parse_with_header("Name\nAlice\n");
|
|
Void::Testing::expect(csv.has_value());
|
|
Void::Testing::expect(!csv->get(csv->rows[0], "Missing").has_value());
|
|
}
|
|
|
|
Void::Testing::Test csv_with_header_col_index()
|
|
{
|
|
const auto csv = Void::Csv::parse_with_header("A,B,C\n1,2,3\n");
|
|
Void::Testing::expect(csv.has_value());
|
|
Void::Testing::expect_eq(*csv->col_index("B"), std::size_t{1});
|
|
}
|