feat: add czv, czv-wasm, and czv-python (init release)

This commit is contained in:
rzmk 2024-06-19 22:37:33 -04:00
commit 9799ab694b
No known key found for this signature in database
40 changed files with 70383 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
fruit,price
apple,2.50
banana,3.00
strawberry,1.50
1 fruit price
2 apple 2.50
3 banana 3.00
4 strawberry 1.50

56
czv/tests/test_count.rs Normal file
View file

@ -0,0 +1,56 @@
use czv;
use czv::Result;
#[test]
fn test_row_count() -> Result<()> {
let cases = vec![
("tests/resources/fruits.csv", 3),
("tests/resources/constituents_altnames.csv", 33971),
];
for (file_name, expected) in cases {
let got = czv::count::row_count(Some(file_name.into()), None, false)?;
assert_eq!(expected, got);
}
Ok(())
}
#[test]
fn test_row_count_builder() -> Result<()> {
let cases = vec![
("tests/resources/fruits.csv", 3),
("tests/resources/constituents_altnames.csv", 33971),
];
for (file_name, expected) in cases {
let got = czv::count::RowCount::new().file_path(file_name).execute()?;
assert_eq!(expected, got);
}
Ok(())
}
#[test]
fn test_column_count() -> Result<()> {
let cases = vec![
("tests/resources/fruits.csv", 2),
("tests/resources/constituents_altnames.csv", 6),
];
for (file_name, expected) in cases {
let got = czv::count::column_count(Some(file_name.into()), None)?;
assert_eq!(expected, got);
}
Ok(())
}
#[test]
fn test_column_count_builder() -> Result<()> {
let cases = vec![
("tests/resources/fruits.csv", 2),
("tests/resources/constituents_altnames.csv", 6),
];
for (file_name, expected) in cases {
let got = czv::count::ColumnCount::new()
.file_path(file_name)
.execute()?;
assert_eq!(expected, got);
}
Ok(())
}

75
czv/tests/test_slice.rs Normal file
View file

@ -0,0 +1,75 @@
use czv;
use czv::Result;
#[test]
fn test_slice_start_end() -> Result<()> {
let cases = vec![(
"tests/resources/fruits.csv",
1,
3,
"banana,3.00\nstrawberry,1.50".to_string(),
)];
for (file_name, start, end, expected) in cases {
let got = czv::slice::slice(
Some(file_name.into()),
None,
Some(start),
Some(end),
None,
None,
false,
)?;
assert_eq!(expected, got);
}
Ok(())
}
#[test]
fn test_slice_start_end_data() -> Result<()> {
let cases = vec![(
"fruit,price\napple,2.50\nbanana,3.00\nstrawberry,1.50".to_string(),
1,
3,
"banana,3.00\nstrawberry,1.50".to_string(),
)];
for (file_data, start, end, expected) in cases {
let got = czv::slice::slice(
None,
Some(file_data),
Some(start),
Some(end),
None,
None,
false,
)?;
assert_eq!(expected, got);
}
Ok(())
}
#[test]
fn test_slice_start_0_end_3() -> Result<()> {
let expected = "apple,2.50\nbanana,3.00".to_string();
let got: String = czv::slice::Slice::new()
.file_path("tests/resources/fruits.csv")
.start(0)
.end(2) // exclusive
.include_header_row(false)
.execute()?;
assert_eq!(expected, got);
Ok(())
}
#[test]
fn test_slice_index_2() -> Result<()> {
let expected = "strawberry,1.50".to_string();
let got: String = czv::slice::Slice::new()
.file_path("tests/resources/fruits.csv")
.index(2)
.include_header_row(false)
.execute()?;
assert_eq!(expected, got);
Ok(())
}