refactor: use options object for WASM function args, improve docs

- Add relevant links to all READMEs and source code
- Resolve clippy lints

czv:

- Add more docs for top-level items
- Add suggestion to use builder methods instead of functions
- Disable slice and slice tests until operation is complete

czv-wasm:

- Use tsify_next for allowing objects as parameters
- Add nodejs example and instructions
This commit is contained in:
rzmk 2024-06-20 16:28:53 -04:00
parent ce260e9491
commit e84c5bec8b
No known key found for this signature in database
20 changed files with 564 additions and 168 deletions

View file

@ -1,75 +1,100 @@
use czv;
use czv::Result;
// 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() -> Result<()> {
// let got = czv::Slice::new()
// .file_path("tests/resources/fruits.csv")
// .execute()?;
// let expected = "fruit,price\napple,2.50\nbanana,3.00\nstrawberry,1.50".to_string();
// 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_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_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()?;
// #[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(())
// }
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()?;
#[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(())
// }
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(())
// }
// #[test]
// fn test_slice_index_override() -> Result<()> {
// let got = czv::slice::Slice::new()
// .file_path("tests/resources/fruits.csv")
// .start(1)
// .end(3)
// .index(2)
// .include_header_row(false)
// .execute();
// // Error: CzvError(Cannot use index with start, end, or length.)
// assert!(got.is_err());
// Ok(())
// }