Add test module for update_lints
This commit is contained in:
@@ -526,170 +526,176 @@ declare_deprecated_lint! {
|
|||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_replace_region() {
|
mod tests {
|
||||||
let text = "\nabc\n123\n789\ndef\nghi";
|
use super::*;
|
||||||
let expected = FileChange {
|
|
||||||
changed: true,
|
|
||||||
new_lines: "\nabc\nhello world\ndef\nghi".to_string(),
|
|
||||||
};
|
|
||||||
let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, false, || {
|
|
||||||
vec!["hello world".to_string()]
|
|
||||||
});
|
|
||||||
assert_eq!(expected, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_replace_region_with_start() {
|
fn test_replace_region() {
|
||||||
let text = "\nabc\n123\n789\ndef\nghi";
|
let text = "\nabc\n123\n789\ndef\nghi";
|
||||||
let expected = FileChange {
|
let expected = FileChange {
|
||||||
changed: true,
|
changed: true,
|
||||||
new_lines: "\nhello world\ndef\nghi".to_string(),
|
new_lines: "\nabc\nhello world\ndef\nghi".to_string(),
|
||||||
};
|
};
|
||||||
let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, true, || {
|
let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, false, || {
|
||||||
vec!["hello world".to_string()]
|
vec!["hello world".to_string()]
|
||||||
});
|
});
|
||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_replace_region_no_changes() {
|
fn test_replace_region_with_start() {
|
||||||
let text = "123\n456\n789";
|
let text = "\nabc\n123\n789\ndef\nghi";
|
||||||
let expected = FileChange {
|
let expected = FileChange {
|
||||||
changed: false,
|
changed: true,
|
||||||
new_lines: "123\n456\n789".to_string(),
|
new_lines: "\nhello world\ndef\nghi".to_string(),
|
||||||
};
|
};
|
||||||
let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, Vec::new);
|
let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, true, || {
|
||||||
assert_eq!(expected, result);
|
vec!["hello world".to_string()]
|
||||||
}
|
});
|
||||||
|
assert_eq!(expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_usable_lints() {
|
fn test_replace_region_no_changes() {
|
||||||
let lints = vec![
|
let text = "123\n456\n789";
|
||||||
Lint::new("should_assert_eq", "Deprecated", "abc", Some("Reason"), "module_name"),
|
let expected = FileChange {
|
||||||
Lint::new("should_assert_eq2", "Not Deprecated", "abc", None, "module_name"),
|
changed: false,
|
||||||
Lint::new("should_assert_eq2", "internal", "abc", None, "module_name"),
|
new_lines: "123\n456\n789".to_string(),
|
||||||
Lint::new("should_assert_eq2", "internal_style", "abc", None, "module_name"),
|
};
|
||||||
];
|
let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, Vec::new);
|
||||||
let expected = vec![Lint::new(
|
assert_eq!(expected, result);
|
||||||
"should_assert_eq2",
|
}
|
||||||
"Not Deprecated",
|
|
||||||
"abc",
|
|
||||||
None,
|
|
||||||
"module_name",
|
|
||||||
)];
|
|
||||||
assert_eq!(expected, Lint::usable_lints(&lints));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_by_lint_group() {
|
fn test_usable_lints() {
|
||||||
let lints = vec![
|
let lints = vec![
|
||||||
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
Lint::new("should_assert_eq", "Deprecated", "abc", Some("Reason"), "module_name"),
|
||||||
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
|
Lint::new("should_assert_eq2", "Not Deprecated", "abc", None, "module_name"),
|
||||||
Lint::new("incorrect_match", "group1", "abc", None, "module_name"),
|
Lint::new("should_assert_eq2", "internal", "abc", None, "module_name"),
|
||||||
];
|
Lint::new("should_assert_eq2", "internal_style", "abc", None, "module_name"),
|
||||||
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
|
];
|
||||||
expected.insert(
|
let expected = vec![Lint::new(
|
||||||
"group1".to_string(),
|
"should_assert_eq2",
|
||||||
vec![
|
"Not Deprecated",
|
||||||
|
"abc",
|
||||||
|
None,
|
||||||
|
"module_name",
|
||||||
|
)];
|
||||||
|
assert_eq!(expected, Lint::usable_lints(&lints));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_by_lint_group() {
|
||||||
|
let lints = vec![
|
||||||
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
||||||
|
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
|
||||||
Lint::new("incorrect_match", "group1", "abc", None, "module_name"),
|
Lint::new("incorrect_match", "group1", "abc", None, "module_name"),
|
||||||
],
|
];
|
||||||
);
|
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
|
||||||
expected.insert(
|
expected.insert(
|
||||||
"group2".to_string(),
|
"group1".to_string(),
|
||||||
vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")],
|
vec![
|
||||||
);
|
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
||||||
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
|
Lint::new("incorrect_match", "group1", "abc", None, "module_name"),
|
||||||
}
|
],
|
||||||
|
);
|
||||||
#[test]
|
expected.insert(
|
||||||
fn test_gen_changelog_lint_list() {
|
"group2".to_string(),
|
||||||
let lints = vec![
|
vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")],
|
||||||
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
);
|
||||||
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
|
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
|
||||||
];
|
}
|
||||||
let expected = vec![
|
|
||||||
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
|
#[test]
|
||||||
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()),
|
fn test_gen_changelog_lint_list() {
|
||||||
];
|
let lints = vec![
|
||||||
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
|
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
||||||
}
|
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
|
||||||
|
];
|
||||||
#[test]
|
let expected = vec![
|
||||||
fn test_gen_deprecated() {
|
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
|
||||||
let lints = vec![
|
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()),
|
||||||
Lint::new(
|
];
|
||||||
"should_assert_eq",
|
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
|
||||||
"group1",
|
}
|
||||||
"abc",
|
|
||||||
Some("has been superseded by should_assert_eq2"),
|
#[test]
|
||||||
"module_name",
|
fn test_gen_deprecated() {
|
||||||
),
|
let lints = vec![
|
||||||
Lint::new(
|
Lint::new(
|
||||||
"another_deprecated",
|
"should_assert_eq",
|
||||||
"group2",
|
"group1",
|
||||||
"abc",
|
"abc",
|
||||||
Some("will be removed"),
|
Some("has been superseded by should_assert_eq2"),
|
||||||
"module_name",
|
"module_name",
|
||||||
),
|
),
|
||||||
];
|
Lint::new(
|
||||||
|
"another_deprecated",
|
||||||
let expected = GENERATED_FILE_COMMENT.to_string()
|
"group2",
|
||||||
+ &[
|
"abc",
|
||||||
"{",
|
Some("will be removed"),
|
||||||
" store.register_removed(",
|
"module_name",
|
||||||
" \"clippy::should_assert_eq\",",
|
),
|
||||||
" \"has been superseded by should_assert_eq2\",",
|
];
|
||||||
" );",
|
|
||||||
" store.register_removed(",
|
let expected = GENERATED_FILE_COMMENT.to_string()
|
||||||
" \"clippy::another_deprecated\",",
|
+ &[
|
||||||
" \"will be removed\",",
|
"{",
|
||||||
" );",
|
" store.register_removed(",
|
||||||
"}",
|
" \"clippy::should_assert_eq\",",
|
||||||
]
|
" \"has been superseded by should_assert_eq2\",",
|
||||||
.join("\n")
|
" );",
|
||||||
+ "\n";
|
" store.register_removed(",
|
||||||
|
" \"clippy::another_deprecated\",",
|
||||||
assert_eq!(expected, gen_deprecated(lints.iter()));
|
" \"will be removed\",",
|
||||||
}
|
" );",
|
||||||
|
"}",
|
||||||
#[test]
|
]
|
||||||
#[should_panic]
|
.join("\n")
|
||||||
fn test_gen_deprecated_fail() {
|
+ "\n";
|
||||||
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
|
|
||||||
let _deprecated_lints = gen_deprecated(lints.iter());
|
assert_eq!(expected, gen_deprecated(lints.iter()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gen_modules_list() {
|
#[should_panic]
|
||||||
let lints = vec![
|
fn test_gen_deprecated_fail() {
|
||||||
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
|
||||||
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
|
let _deprecated_lints = gen_deprecated(lints.iter());
|
||||||
];
|
}
|
||||||
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_modules_list() {
|
||||||
|
let lints = vec![
|
||||||
#[test]
|
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
||||||
fn test_gen_lint_group_list() {
|
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
|
||||||
let lints = vec![
|
];
|
||||||
Lint::new("abc", "group1", "abc", None, "module_name"),
|
let expected =
|
||||||
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
GENERATED_FILE_COMMENT.to_string() + &["mod another_module;", "mod module_name;"].join("\n") + "\n";
|
||||||
Lint::new("internal", "internal_style", "abc", None, "module_name"),
|
assert_eq!(expected, gen_modules_list(lints.iter()));
|
||||||
];
|
}
|
||||||
let expected = GENERATED_FILE_COMMENT.to_string()
|
|
||||||
+ &[
|
#[test]
|
||||||
"store.register_group(true, \"clippy::group1\", Some(\"clippy_group1\"), vec![",
|
fn test_gen_lint_group_list() {
|
||||||
" LintId::of(module_name::ABC),",
|
let lints = vec![
|
||||||
" LintId::of(module_name::INTERNAL),",
|
Lint::new("abc", "group1", "abc", None, "module_name"),
|
||||||
" LintId::of(module_name::SHOULD_ASSERT_EQ),",
|
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
|
||||||
"])",
|
Lint::new("internal", "internal_style", "abc", None, "module_name"),
|
||||||
]
|
];
|
||||||
.join("\n")
|
let expected = GENERATED_FILE_COMMENT.to_string()
|
||||||
+ "\n";
|
+ &[
|
||||||
|
"store.register_group(true, \"clippy::group1\", Some(\"clippy_group1\"), vec![",
|
||||||
let result = gen_lint_group_list("group1", lints.iter());
|
" LintId::of(module_name::ABC),",
|
||||||
|
" LintId::of(module_name::INTERNAL),",
|
||||||
assert_eq!(expected, result);
|
" LintId::of(module_name::SHOULD_ASSERT_EQ),",
|
||||||
|
"])",
|
||||||
|
]
|
||||||
|
.join("\n")
|
||||||
|
+ "\n";
|
||||||
|
|
||||||
|
let result = gen_lint_group_list("group1", lints.iter());
|
||||||
|
|
||||||
|
assert_eq!(expected, result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user