这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ rayon = "1.10.0"
regex = "1.10.5"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"

[dev-dependencies]
tempfile = "3.20.0"
38 changes: 38 additions & 0 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,41 @@ impl Extractor {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

use std::fs::File;
use std::io::{Read, Write};

use tempfile::NamedTempFile;

#[test]
fn test_extract() -> Result<(), Box<dyn std::error::Error>> {
// Create a temporary file to simulate the corpus input
let mut corpus_file = NamedTempFile::new()?;
writeln!(corpus_file, "これ は テスト です 。")?;
writeln!(corpus_file, "別 の 文 も あり ます 。")?;
corpus_file.as_file().sync_all()?;

// Create a temporary file for the features output
let features_file = NamedTempFile::new()?;

// Create an instance of Extractor and extract features
let mut extractor = Extractor::new();
extractor.extract(corpus_file.path(), features_file.path())?;

// Read the output from the features file
let mut output = String::new();
File::open(features_file.path())?.read_to_string(&mut output)?;

// Check if the output is not empty
assert!(!output.is_empty(), "Extracted features should not be empty");

// Check if the output contains tab-separated values
assert!(output.contains("\t"), "Output should contain tab-separated values");

Ok(())
}
}