use sql_cli::data::csv_datasource::CsvDataSource;
use sql_cli::data::datatable::DataValue;
use std::env;
use std::path::PathBuf;
#[test]
fn test_null_vs_empty_string() {
let csv_content = r#"id,name,value,notes
1,Alice,,empty_field
2,Bob,"",quoted_empty
3,,100,null_name
4,"",200,quoted_empty_name
5,Charlie,,"double_null""#;
let mut temp_path = env::temp_dir();
temp_path.push("test_null_empty.csv");
let temp_file = temp_path.to_str().unwrap();
std::fs::write(&temp_path, csv_content).unwrap();
let datasource = CsvDataSource::load_from_file(temp_file, "test").unwrap();
let data_table = datasource.to_datatable();
let rows = &data_table.rows;
let row1 = &rows[0];
assert_eq!(
row1.values[2],
DataValue::Null,
"Row 1 value should be NULL (unquoted empty)"
);
let row2 = &rows[1];
assert_eq!(row2.values[1], DataValue::String("Bob".to_string()));
assert_eq!(
row2.values[2],
DataValue::String("".to_string()),
"Row 2 value should be empty string (quoted empty)"
);
let row3 = &rows[2];
assert_eq!(
row3.values[1],
DataValue::Null,
"Row 3 name should be NULL (unquoted empty)"
);
let row4 = &rows[3];
assert_eq!(
row4.values[1],
DataValue::String("".to_string()),
"Row 4 name should be empty string (quoted empty)"
);
let row5 = &rows[4];
assert_eq!(
row5.values[2],
DataValue::Null,
"Row 5 value should be NULL (unquoted empty)"
);
std::fs::remove_file(&temp_path).ok();
}