Skip to content

Commit

Permalink
tests: added transpose test
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Feb 27, 2024
1 parent 786af4a commit 3618fc6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
54 changes: 54 additions & 0 deletions tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
4 changes: 2 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ pub fn setup_example_7(n: usize) -> Result<AnnotationStore, StamError> {

pub fn setup_example_8() -> Result<AnnotationStore, StamError> {
//simple transposition
let mut store = AnnotationStore::default()
let store = AnnotationStore::default()
.with_id("example8")
.add(TextResource::from_string(
"humanrights",
Expand Down Expand Up @@ -598,7 +598,7 @@ pub fn setup_example_8() -> Result<AnnotationStore, StamError> {
pub fn setup_example_8b() -> Result<AnnotationStore, StamError> {
//complex transposition

let mut store = AnnotationStore::default()
let store = AnnotationStore::default()
.with_id("example8")
.add(TextResource::from_string(
"humanrights",
Expand Down

0 comments on commit 3618fc6

Please sign in to comment.