use super::{assert_reported, assert_silent_about, codes_of};
use crate::DiagnosticCode;
#[test]
fn a_full_iterator_spelling_is_reported() {
let codes = codes_of("void f() {\n std::vector<int>::iterator it;\n (void)it;\n}\n");
assert_reported(
&codes,
DiagnosticCode::UseAuto,
"`it` is declared by its full iterator spelling",
);
}
#[test]
fn a_full_const_iterator_spelling_is_reported() {
let codes =
codes_of("void f() {\n std::vector<int>::const_iterator it;\n (void)it;\n}\n");
assert_reported(
&codes,
DiagnosticCode::UseAuto,
"`it` is declared by its full `::const_iterator` spelling",
);
}
#[test]
fn another_member_type_and_auto_are_silent() {
let value_type =
codes_of("void f() {\n std::vector<int>::value_type value;\n (void)value;\n}\n");
assert_silent_about(
&value_type,
DiagnosticCode::UseAuto,
"`value_type` is not an iterator",
);
let deduced = codes_of("void f() {\n auto it = 0;\n (void)it;\n}\n");
assert_silent_about(
&deduced,
DiagnosticCode::UseAuto,
"`auto` is the answer, not the question",
);
}
#[test]
fn a_declarator_that_is_not_one_name_is_silent() {
let array = codes_of("void f() {\n std::vector<int>::iterator items[4];\n}\n");
assert_silent_about(
&array,
DiagnosticCode::UseAuto,
"`items[4]` is an array, not one name",
);
let parameter = codes_of("void g(std::vector<int>::iterator);\n");
assert_silent_about(
¶meter,
DiagnosticCode::UseAuto,
"the parameter declares no name to rewrite",
);
}
#[test]
fn prose_and_data_are_not_declarations() {
let commented = codes_of("// std::vector<int>::iterator it;\nvoid f() { }\n");
assert_silent_about(
&commented,
DiagnosticCode::UseAuto,
"a comment is not a declaration",
);
let quoted = codes_of(
"void g(const char*);\nvoid f() {\n g(\"std::vector<int>::iterator it;\");\n}\n",
);
assert_silent_about(
"ed,
DiagnosticCode::UseAuto,
"a string literal is not a declaration",
);
}