Skip to content

Commit

Permalink
chore(transformers): improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
timonv committed Jun 23, 2024
1 parent 4d5c68e commit 7767588
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions swiftide/src/transformers/metadata_qa_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,29 @@ impl Transformer for MetadataQACode {
self.concurrency
}
}

#[cfg(test)]
mod test {
use crate::MockSimplePrompt;

use super::*;

#[tokio::test]
async fn test_metadata_qacode() {
let mut client = MockSimplePrompt::new();

client
.expect_prompt()
.returning(|_| Ok("Q1: Hello\nA1: World".to_string()));

let transformer = MetadataQACode::builder().client(client).build().unwrap();
let node = IngestionNode::new("Some text");

let result = transformer.transform_node(node).await.unwrap();

assert_eq!(
result.metadata.get("Questions and Answers").unwrap(),
"Q1: Hello\nA1: World"
);
}
}
26 changes: 26 additions & 0 deletions swiftide/src/transformers/metadata_qa_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,29 @@ impl Transformer for MetadataQAText {
self.concurrency
}
}

#[cfg(test)]
mod test {
use crate::MockSimplePrompt;

use super::*;

#[tokio::test]
async fn test_metadata_qacode() {
let mut client = MockSimplePrompt::new();

client
.expect_prompt()
.returning(|_| Ok("Q1: Hello\nA1: World".to_string()));

let transformer = MetadataQAText::builder().client(client).build().unwrap();
let node = IngestionNode::new("Some text");

let result = transformer.transform_node(node).await.unwrap();

assert_eq!(
result.metadata.get("Questions and Answers").unwrap(),
"Q1: Hello\nA1: World"
);
}
}

0 comments on commit 7767588

Please sign in to comment.