Skip to content

Commit

Permalink
Return empty String if data is empty in into_field_array() and ad…
Browse files Browse the repository at this point in the history
…ded test
  • Loading branch information
Maik Simon Mikoszek authored and elrnv committed Aug 17, 2024
1 parent e3e44a0 commit 02d9100
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,11 @@ impl DataArray {
buf
}
DataArrayFormat::Ascii => {
let string = data[0].clone().into_string();
let string = if data.is_empty() {
"".to_string()
} else {
data[0].clone().into_string()
};
let slice = string.as_str();
fn parse_num_seq<E, T>(s: &str) -> std::result::Result<Vec<T>, ValidationError>
where
Expand Down Expand Up @@ -3797,4 +3801,41 @@ mod tests {
assert_eq!(xml_round_trip.clone(), vtk_round_trip.try_into()?);
Ok(())
}

#[test]
fn empty_polydata_topology() {
use super::Data::Data;
use super::DataArray as XMLDataArray;
use crate::IOBuffer;
let data = XMLDataArray {
name: "PolyData".to_string(),
scalar_type: ScalarType::Float32,
format: DataArrayFormat::Ascii,
offset: None,
num_comp: 1,
range_min: Some(0.1),
range_max: Some(0.3),
data: vec![Data("0.1 0.2 0.3".to_string())],
};
let data_empty = XMLDataArray {
name: "PolyData".to_string(),
scalar_type: ScalarType::Float32,
format: DataArrayFormat::Ascii,
offset: None,
num_comp: 1,
range_min: None,
range_max: None,
data: vec![],
};
let encoding_info = EncodingInfo {
byte_order: model::ByteOrder::BigEndian,
header_type: ScalarType::Float64,
compressor: Compressor::None,
compression_level: 0,
};
let data_fa = data.into_field_array(3, None, encoding_info);
let data_empty_fa = data_empty.into_field_array(0, None, encoding_info);
assert_eq!(data_fa.unwrap().data, IOBuffer::F32(vec![0.1, 0.2, 0.3]));
assert_eq!(data_empty_fa.unwrap().data, IOBuffer::F32(vec![]));
}
}

0 comments on commit 02d9100

Please sign in to comment.