Add test module for update_lints

This commit is contained in:
Michael Wright 2021-09-18 06:43:39 +02:00
parent 3f804ca6d3
commit 20abbd93f9

View File

@ -526,8 +526,12 @@ declare_deprecated_lint! {
assert_eq!(expected, result);
}
#[test]
fn test_replace_region() {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_replace_region() {
let text = "\nabc\n123\n789\ndef\nghi";
let expected = FileChange {
changed: true,
@ -537,10 +541,10 @@ fn test_replace_region() {
vec!["hello world".to_string()]
});
assert_eq!(expected, result);
}
}
#[test]
fn test_replace_region_with_start() {
#[test]
fn test_replace_region_with_start() {
let text = "\nabc\n123\n789\ndef\nghi";
let expected = FileChange {
changed: true,
@ -550,10 +554,10 @@ fn test_replace_region_with_start() {
vec!["hello world".to_string()]
});
assert_eq!(expected, result);
}
}
#[test]
fn test_replace_region_no_changes() {
#[test]
fn test_replace_region_no_changes() {
let text = "123\n456\n789";
let expected = FileChange {
changed: false,
@ -561,10 +565,10 @@ fn test_replace_region_no_changes() {
};
let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, Vec::new);
assert_eq!(expected, result);
}
}
#[test]
fn test_usable_lints() {
#[test]
fn test_usable_lints() {
let lints = vec![
Lint::new("should_assert_eq", "Deprecated", "abc", Some("Reason"), "module_name"),
Lint::new("should_assert_eq2", "Not Deprecated", "abc", None, "module_name"),
@ -579,10 +583,10 @@ fn test_usable_lints() {
"module_name",
)];
assert_eq!(expected, Lint::usable_lints(&lints));
}
}
#[test]
fn test_by_lint_group() {
#[test]
fn test_by_lint_group() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
@ -601,10 +605,10 @@ fn test_by_lint_group() {
vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")],
);
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
}
}
#[test]
fn test_gen_changelog_lint_list() {
#[test]
fn test_gen_changelog_lint_list() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
@ -614,10 +618,10 @@ fn test_gen_changelog_lint_list() {
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()),
];
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
}
}
#[test]
fn test_gen_deprecated() {
#[test]
fn test_gen_deprecated() {
let lints = vec![
Lint::new(
"should_assert_eq",
@ -652,27 +656,28 @@ fn test_gen_deprecated() {
+ "\n";
assert_eq!(expected, gen_deprecated(lints.iter()));
}
}
#[test]
#[should_panic]
fn test_gen_deprecated_fail() {
#[test]
#[should_panic]
fn test_gen_deprecated_fail() {
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
let _deprecated_lints = gen_deprecated(lints.iter());
}
}
#[test]
fn test_gen_modules_list() {
#[test]
fn test_gen_modules_list() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
];
let expected = GENERATED_FILE_COMMENT.to_string() + &["mod another_module;", "mod module_name;"].join("\n") + "\n";
let expected =
GENERATED_FILE_COMMENT.to_string() + &["mod another_module;", "mod module_name;"].join("\n") + "\n";
assert_eq!(expected, gen_modules_list(lints.iter()));
}
}
#[test]
fn test_gen_lint_group_list() {
#[test]
fn test_gen_lint_group_list() {
let lints = vec![
Lint::new("abc", "group1", "abc", None, "module_name"),
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
@ -692,4 +697,5 @@ fn test_gen_lint_group_list() {
let result = gen_lint_group_list("group1", lints.iter());
assert_eq!(expected, result);
}
}