Skip to content

Commit

Permalink
style: remove redundant comments in test modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ekkolon committed Mar 28, 2024
1 parent d3bd7ae commit 546c95d
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 130 deletions.
8 changes: 1 addition & 7 deletions src/ops/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ mod tests {

#[test]
fn test_scan_with_license_candidates() {
// Create a temporary directory and files
let temp_dir = create_temp_dir();
let root_path = temp_dir.path();

Expand All @@ -239,7 +238,6 @@ mod tests {
.write_all(b"ignored.txt")
.expect("Failed to write to .licensaignore file");

// Run the scan function
let scan_config = ScanConfig {
limit: 100,
exclude: None,
Expand All @@ -257,11 +255,8 @@ mod tests {

#[test]
fn test_scan_without_license_candidates() {
// Create a temporary directory without license candidates
let temp_dir = create_temp_dir();
let root_path = temp_dir.path();

// Run the scan function
let scan_config = ScanConfig {
limit: 100,
exclude: None,
Expand All @@ -270,8 +265,7 @@ mod tests {
let scan = Scan::new(scan_config);
let result = scan.run();

// Assert that the result is Ok and the candidates list is empty
// TODO implement
// TODO: Assert that the result is Ok and the candidates list is empty
}

#[test]
Expand Down
7 changes: 1 addition & 6 deletions src/ops/work_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,21 @@ mod tests {
content: "example test content".into(),
path: PathBuf::new(),
};

// Process file contents with the cloned processor
cloned_processor.execute(response);
assert!(!cloned_processor.completed);

// Check if the sender sends a result
assert_eq!(receiver.try_recv(), Ok(42));
}

#[test]
fn test_work_tree_processor() {
let mut work_tree_processor = WorkTree { tasks: vec![] };

let receiver = work_tree_processor.add_task(MockContext, mock_function);

let (tmp_dir, tmp_file) = create_temp_file("work_tree_processor.txt");

// Run with an empty work tree path vector
work_tree_processor.run(vec![tmp_file]);

// Check if the receiver receives the result
assert_eq!(
receiver.try_recv(),
Ok(42),
Expand Down
14 changes: 1 addition & 13 deletions src/ops/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,9 @@ mod tests {

#[test]
fn test_find_config_file_multiple_files_exist() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");

// Define the target directory
let target_dir = temp_dir.path();

// Create sample config files in the temporary directory
for &filename in POSSIBLE_CONFIG_FILENAMES {
let config_path = target_dir.join(filename);
File::create(&config_path).expect("Failed to create sample config file");
Expand All @@ -373,27 +369,19 @@ mod tests {
drop(config_path);
}

// Test finding the config file (use the first one in the list)
let result: Result<Value> = resolve_workspace_config(target_dir);
assert!(result.is_err());

// Verify the content of the config file
// let expected_content = String::new(); // Adjust with actual content
// assert_eq!(result.unwrap(), expected_content);
// TODO: Verify the content of the config file

// Cleanup
temp_dir.close().expect("Failed to close temp directory");
}

#[test]
fn test_find_config_file_no_file_exists() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");

// Define the target directory
let target_dir = temp_dir.path();

// Test finding the config file when none exist
let result: Result<Value> = resolve_workspace_config(target_dir);
// assert!(result.is_err());
}
Expand Down
1 change: 0 additions & 1 deletion src/spdx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ fn is_single_expr(expr: &str) -> bool {
expr.split(' ').collect::<Vec<&str>>().len() == 1
}

/// NOTE:
pub fn list_spdx_license_names() -> Vec<String> {
LICENSES
.iter()
Expand Down
53 changes: 0 additions & 53 deletions src/template/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,6 @@ where
cache.len()
}

// /// Provides an iterator over the items in the cache.
// ///
// /// # Returns
// ///
// /// An iterator over cloned `Arc<T>` items in the cache.
// pub fn iter(&self) -> CacheIter<T> {
// CacheIter { cache: &self.inner }
// }

/// Checks if a specific item exists in the cache.
///
/// # Arguments
Expand All @@ -158,26 +149,6 @@ where
}
}

// /// Iterator over items in the cache.
// pub struct CacheIter<'a, T>
// where
// T: 'a,
// {
// cache: &'a Mutex<HashMap<String, Arc<T>>>,
// }

// impl<'a, T> Iterator for CacheIter<'a, T>
// where
// T: 'a,
// {
// type Item = &'a Arc<T>;

// fn next(&mut self) -> Option<Self::Item> {
// let cache = self.cache.lock().unwrap();
// cache.values().next()
// }
// }

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -293,30 +264,6 @@ mod tests {
assert_eq!(size, 2);
}

// #[test]
// fn test_cache_iter() {
// let cache = Cache::<TemplateItem>::new();
// let ext1 = ".rs";
// let ext2 = ".toml";
// let template1 = "Your license template for Rust";
// let template2 = "Your license template for TOML";

// cache.add(TemplateItem {
// extension: ext1.into(),
// template: template1.into(),
// });

// cache.add(TemplateItem {
// extension: ext2.into(),
// template: template2.into(),
// });

// let mut iter = cache.iter();
// assert_eq!(iter.next().unwrap().template, template1);
// assert_eq!(iter.next().unwrap().template, template2);
// assert!(iter.next().is_none());
// }

#[test]
fn test_cache_contains() {
let cache = Cache::<TemplateItem>::new();
Expand Down
2 changes: 1 addition & 1 deletion src/template/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
"#;
assert_eq!(&result, expected);

// Test case 2: Empty template and prefix
// Empty template and prefix
let empty_template = "";
let result = rs_header_prefix.apply(empty_template).unwrap();
let expected = "\n";
Expand Down
33 changes: 0 additions & 33 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,17 @@ mod tests {

#[test]
fn test_write_json_successful() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");

// Define the file path in the temporary directory
let file_path = temp_dir.path().join("output.json");

// Create a sample JSON value
let json_data = serde_json::json!({
"name": "John Doe",
"age": 30,
"city": "Example City"
});

// Test writing the JSON data to the file
write_json(&file_path, &json_data).expect("Failed to write JSON to file");

// Verify that the file exists
assert!(file_path.exists());

// Verify the content of the file
let mut file = File::open(&file_path).expect("Failed to open file");
let mut file_content = String::new();
file.read_to_string(&mut file_content)
Expand All @@ -206,43 +197,29 @@ mod tests {

#[test]
fn test_write_json_invalid_file_path() {
// Define an invalid file path (nonexistent directory)
let invalid_file_path = "/nonexistent_directory/output.json";

// Create a sample JSON value
let json_data = serde_json::json!({
"name": "John Doe",
"age": 30,
"city": "Example City"
});

// Test writing JSON to an invalid file path
let result = write_json(invalid_file_path, &json_data);
assert!(result.is_err());
}

#[test]
fn test_write_json_with_seek() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");

// Define the file path in the temporary directory
let file_path = temp_dir.path().join("output.json");

// Create a sample JSON value
let json_data = serde_json::json!({
"name": "John Doe",
"age": 30,
"city": "Example City"
});

// Test writing the JSON data to the file with seeking back
write_json(&file_path, &json_data).expect("Failed to write JSON to file");

// Verify that the file exists
assert!(file_path.exists());

// Verify the content of the file after seeking back
let mut file = File::open(&file_path).expect("Failed to open file");
let mut file_content = String::new();
file.read_to_string(&mut file_content)
Expand All @@ -269,16 +246,12 @@ mod tests {

#[test]
fn test_check_any_file_exists_single_file_exists() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");
let base_path = temp_dir.path();

// Create a sample file in the temporary directory
let sample_filename = "file1.txt";
let sample_file_path = base_path.join(sample_filename);
File::create(&sample_file_path).expect("Failed to create sample file");

// Test when the single file exists
let result = resolve_any_path(base_path, &[sample_filename]);
assert_eq!(result, Some(sample_file_path.clone()));

Expand All @@ -289,11 +262,9 @@ mod tests {

#[test]
fn test_check_any_file_exists_multiple_files_exist() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");
let base_path = temp_dir.path();

// Create sample files in the temporary directory
let filenames = ["file1.txt", "file2.txt", "file3.txt"];
for &filename in &filenames {
let file_path = base_path.join(filename);
Expand All @@ -303,7 +274,6 @@ mod tests {
drop(file_path);
}

// Test when multiple files exist
let result = resolve_any_path(base_path, &filenames);
assert!(result.is_some());
assert!(filenames.iter().any(|&filename| {
Expand All @@ -318,11 +288,8 @@ mod tests {

#[test]
fn test_check_any_file_exists_no_file_exists() {
// Create a temporary directory for testing
let temp_dir = tempdir().expect("Failed to create temporary directory");
let base_path = temp_dir.path();

// Test when none of the files exist
let result = resolve_any_path(base_path, &["nonexistent_file.txt"]);
assert_eq!(result, None);
}
Expand Down
1 change: 0 additions & 1 deletion src/workspace/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ mod tests {
let root_path = root_dir.as_ref();
let file_name = "test_file.txt";

// Create a temporary file in a parent directory
let mut parent_dir = root_path.to_path_buf();
parent_dir.push("sub1");
let sub1_dir = &parent_dir.clone();
Expand Down
Loading

0 comments on commit 546c95d

Please sign in to comment.