diff --git a/tests/api.rs b/tests/api.rs index c93cec3..333e71b 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -2093,3 +2093,57 @@ fn transposition_complex() -> Result<(), StamError> { ); Ok(()) } + +#[test] +#[cfg(feature = "transpose")] +fn transpose_over_simple_transposition() -> Result<(), StamError> { + let mut store = setup_example_8()?; + store.annotate( + AnnotationBuilder::new() + .with_id("A3") + .with_data("mydataset", "species", "homo sapiens") + .with_target(SelectorBuilder::textselector( + "humanrights", + Offset::simple(4, 9), + )), + )?; + let transposition = store.annotation("SimpleTransposition1").or_fail()?; + let source = store.annotation("A3").or_fail()?; + assert_eq!( + source.text_simple(), + Some("human"), + "sanity check for source annotation" + ); + let config = TransposeConfig { + transposition_id: Some("NewTransposition".to_string()), + target_side_ids: vec!["A3t".to_string()], + ..Default::default() + }; + let targets = + store.annotate_from_iter(source.transpose(&transposition, config)?.into_iter())?; + assert_eq!(targets.len(), 2); + let new_transposition = store.annotation("NewTransposition").or_fail()?; + assert_eq!( + new_transposition + .annotations_in_targets(AnnotationDepth::One) + .count(), + 2, + "new transposition must have two target annotations (source annotation and transposed annotation)" + ); + let source = store.annotation("A3").or_fail()?; //reobtain (otherwise borrow checker complains after mutation) + let transposed = store.annotation("A3t").or_fail()?; + assert_eq!( + transposed.text_simple(), + source.text_simple(), + "transposed annotation must reference same text as source" + ); + let tsel = transposed.textselections().next().unwrap(); + assert_eq!( + tsel.resource().id(), + Some("warhol"), + "transposed annotation must reference the target resource" + ); + assert_eq!(tsel.begin(), 0, "transposed offset check"); + assert_eq!(tsel.end(), 5, "transposed offset check"); + Ok(()) +} diff --git a/tests/common/mod.rs b/tests/common/mod.rs index bf2eb59..117a45b 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -567,7 +567,7 @@ pub fn setup_example_7(n: usize) -> Result { pub fn setup_example_8() -> Result { //simple transposition - let mut store = AnnotationStore::default() + let store = AnnotationStore::default() .with_id("example8") .add(TextResource::from_string( "humanrights", @@ -598,7 +598,7 @@ pub fn setup_example_8() -> Result { pub fn setup_example_8b() -> Result { //complex transposition - let mut store = AnnotationStore::default() + let store = AnnotationStore::default() .with_id("example8") .add(TextResource::from_string( "humanrights",