Add @each_row for the csv module.

This commit is contained in:
Christoffer Lerno
2025-03-26 18:19:19 +01:00
parent 4538a1f50d
commit 5c46b0c2a0
2 changed files with 36 additions and 13 deletions

View File

@@ -2,7 +2,8 @@ module csv_test @test;
import std::encoding::csv;
import std::io;
struct TestCase {
struct TestCase
{
String input;
String[] want;
String sep;
@@ -32,17 +33,33 @@ fn void csv_each_row()
","
},
};
foreach (t : tests) {
foreach (t : tests)
{
String[] want = t.want;
CsvReader r;
r.init((ByteReader){}.init(t.input), t.sep);
r.@each_row(; String[] row) {
foreach (i, s : row) {
assert(want.len > 0,
"more records than we want");
assert(s == want[0], "columns do not match; "
"got: '%s', want: '%s'", s, want[0]);
foreach (i, s : row)
{
assert(want.len > 0, "more records than we want");
assert(s == want[0], "columns do not match; got: '%s', want: '%s'", s, want[0]);
want = want[1..];
}
};
assert(want.len == 0, "not enough records found");
}
foreach (t : tests)
{
String[] want = t.want;
CsvReader r;
csv::@each_row((ByteReader){}.init(t.input), t.sep; String[] row)
{
foreach (i, s : row)
{
assert(want.len > 0, "more records than we want");
assert(s == want[0], "columns do not match; got: '%s', want: '%s'", s, want[0]);
want = want[1..];
}
};