use super::{assert_reported, assert_silent_about, codes_of};
use crate::DiagnosticCode;
#[test]
fn null_in_a_call_argument_is_reported() {
let codes = codes_of("void f(int*);\nvoid g() {\n f(NULL);\n}\n");
assert_reported(
&codes,
DiagnosticCode::UseNullptr,
"`NULL` is `0` in every standard header",
);
}
#[test]
fn null_in_an_initialiser_is_reported() {
let codes = codes_of("void g() {\n int *p = NULL;\n (void)p;\n}\n");
assert_reported(
&codes,
DiagnosticCode::UseNullptr,
"the pointer is initialised with the macro",
);
}
#[test]
fn nullptr_and_zero_are_silent() {
let nullptr = codes_of("void g() {\n int *p = nullptr;\n (void)p;\n}\n");
assert_silent_about(
&nullptr,
DiagnosticCode::UseNullptr,
"`nullptr` has the pointer type",
);
let zero = codes_of("void g() {\n int *p = 0;\n (void)p;\n}\n");
assert_silent_about(
&zero,
DiagnosticCode::UseNullptr,
"the rule is about the spelling `NULL`",
);
}
#[test]
fn prose_and_data_are_not_expressions() {
let commented = codes_of("// NULL is what we used to write\nint f() { return 0; }\n");
assert_silent_about(
&commented,
DiagnosticCode::UseNullptr,
"a comment is not a use",
);
let quoted = codes_of("void f();\nvoid g() { f(\"NULL\"); }\n");
assert_silent_about(
"ed,
DiagnosticCode::UseNullptr,
"a string literal is not a use",
);
}