use super::{assert_reported, assert_silent_about, codes_of};
use crate::DiagnosticCode;
#[test]
fn a_member_the_class_does_not_declare_is_reported() {
let codes = codes_of("struct C { int n; };\nvoid g() { C x; x.m; }\n");
assert_reported(
&codes,
DiagnosticCode::UndefinedField,
"`C` declares `n` and no `m`",
);
}
#[test]
fn an_arrow_is_judged_against_the_class_it_reaches() {
let codes = codes_of(
"struct Session { void Run(); };\nvoid g(Session *session) { session->Missing(); }\n",
);
assert_reported(
&codes,
DiagnosticCode::UndefinedField,
"`Session` has no `Missing`",
);
}
#[test]
fn a_member_the_class_declares_is_silent() {
let dot = codes_of("struct C { int n; };\nvoid g() { C x; x.n; }\n");
assert_silent_about(&dot, DiagnosticCode::UndefinedField, "`C` declares `n`");
let arrow =
codes_of("struct Session { void Run(); };\nvoid g(Session *session) { session->Run(); }\n");
assert_silent_about(
&arrow,
DiagnosticCode::UndefinedField,
"`Run` is the pointee's own member",
);
}
#[test]
fn a_dependent_type_is_not_judged() {
let codes = codes_of("template <class C>\nvoid f() { C x; x.m; }\n");
assert_silent_about(
&codes,
DiagnosticCode::UndefinedField,
"`C` names a template parameter, so its members exist only at instantiation",
);
}
#[test]
fn a_member_list_this_file_cannot_complete_is_silent() {
let elsewhere = codes_of("void g(std::string full) { full.size(); }\n");
assert_silent_about(
&elsewhere,
DiagnosticCode::UndefinedField,
"`std::string`'s members are in a header this file does not write",
);
let partial =
codes_of("struct D : Missing { void f(); };\nvoid g(D d) { d.not_read_anywhere(); }\n");
assert_silent_about(
&partial,
DiagnosticCode::UndefinedField,
"`Missing` was never read, so `D`'s member list is partial",
);
}
#[test]
fn an_arrow_with_no_typed_pointee_is_silent() {
let codes = codes_of(
"struct Session { void Run(); };\n\
struct Pointer { Missing *operator->(); };\n\
void g(Pointer pointer) { pointer->Run(); }\n",
);
assert_silent_about(
&codes,
DiagnosticCode::UndefinedField,
"the pointee cannot be typed, so the member is not judged",
);
}