use super::{assert_reported, assert_silent_about, codes_of};
use crate::DiagnosticCode;
#[test]
fn a_receiver_that_nothing_declares_is_reported() {
let codes = codes_of("struct Widget { int size; };\nvoid f() {\n missing.size;\n}\n");
assert_reported(
&codes,
DiagnosticCode::UndefinedName,
"nothing declares `missing`",
);
}
#[test]
fn a_callee_that_nothing_declares_is_reported() {
let codes = codes_of("void f() {\n printh(\"x\", 12);\n}\n");
assert_reported(
&codes,
DiagnosticCode::UndefinedName,
"nothing declares `printh`",
);
}
#[test]
fn a_name_the_file_declares_is_silent() {
let codes =
codes_of("struct Widget { int size; };\nvoid f() {\n Widget w;\n w.size;\n}\n");
assert_silent_about(
&codes,
DiagnosticCode::UndefinedName,
"`w` is declared on the line above",
);
}
#[test]
fn a_keyword_and_an_expression_are_not_names() {
let keyword = codes_of("struct Widget { int size; void f() { this->size = 1; } };\n");
assert_silent_about(
&keyword,
DiagnosticCode::UndefinedName,
"`this` is a keyword, not a name",
);
let expression = codes_of("struct Widget { int size; };\nvoid f(Widget* p) { (*p).size; }\n");
assert_silent_about(
&expression,
DiagnosticCode::UndefinedName,
"the object is an expression, not one bare name",
);
}
#[test]
fn a_template_body_and_a_macro_are_silent() {
let templated =
codes_of("template <class T>\nstruct Derived : T {\n void f() { count.size; }\n};\n");
assert_silent_about(
&templated,
DiagnosticCode::UndefinedName,
"a template body is dependent",
);
let macro_defined = codes_of(
"struct Widget { int size; };\n\
#define receiver w\n\
void f() {\n Widget w;\n receiver.size;\n}\n",
);
assert_silent_about(
¯o_defined,
DiagnosticCode::UndefinedName,
"`receiver` is a macro, and the expanded name is declared",
);
}
#[test]
fn a_lambda_body_and_an_adl_call_are_silent() {
let lambda = codes_of(
"struct Widget { int size; };\n\
void f() {\n Widget w;\n auto g = [&w]() { w.size; };\n}\n",
);
assert_silent_about(
&lambda,
DiagnosticCode::UndefinedName,
"a capture is not a name the scope tree holds",
);
let adl = codes_of("struct Widget { int size; };\nvoid f(Widget w) {\n swap(w, w);\n}\n");
assert_silent_about(
&adl,
DiagnosticCode::UndefinedName,
"`swap` may be found through `Widget`'s namespace",
);
}