use super::symbolic::SymbolicRepresentationCollection;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
impl SymbolicRepresentationCollection {
#[wasm_bindgen(getter, js_name = truncatedAt)]
pub fn truncated_at(&self) -> Option<usize> {
self.truncated.as_ref().map(|t| t.emitted)
}
#[wasm_bindgen(getter, js_name = truncatedReason)]
pub fn truncated_reason(&self) -> Option<String> {
self.truncated
.as_ref()
.map(|t| t.reason.as_wire_str().to_string())
}
#[wasm_bindgen(getter, js_name = truncatedLimit)]
pub fn truncated_limit(&self) -> Option<usize> {
self.truncated.as_ref().and_then(|t| t.limit)
}
}
#[cfg(test)]
mod tests {
use super::SymbolicRepresentationCollection;
use ifc_lite_processing::{
SymbolicData, SymbolicTruncation, SymbolicTruncationReason,
};
fn truncated_but_empty() -> SymbolicData {
SymbolicData {
truncated: Some(SymbolicTruncation {
reason: SymbolicTruncationReason::ItemRevisits,
emitted: 0,
limit: None,
}),
..SymbolicData::default()
}
}
#[test]
fn is_empty_agrees_with_the_processing_side_for_a_truncated_but_empty_result() {
let data = truncated_but_empty();
let expected = data.is_empty();
let collection = SymbolicRepresentationCollection::from_data(data);
assert!(
!expected,
"SymbolicData::is_empty must not call a truncated result empty"
);
assert_eq!(
collection.is_empty(),
expected,
"the WASM collection must agree with SymbolicData::is_empty, or a \
consumer that skips an empty collection silently discards the \
truncation diagnostic (geometry is client-side only, so this is \
the browser's only signal the drawing is clipped)"
);
assert_eq!(collection.truncated_reason().as_deref(), Some("item-revisits"));
}
#[test]
fn a_genuinely_complete_and_empty_result_is_still_empty() {
let data = SymbolicData::default();
assert!(data.is_empty());
let collection = SymbolicRepresentationCollection::from_data(data);
assert!(collection.is_empty());
assert_eq!(collection.truncated_reason(), None);
}
}