rustdoc: Rename Tester to DoctestVisitor

The new name more accurately captures what it is.
This commit is contained in:
Noah Lev 2024-05-30 21:05:12 -07:00 committed by Guillaume Gomez
parent 1be24d70ce
commit 3ee4629446
3 changed files with 14 additions and 14 deletions

View File

@ -983,12 +983,12 @@ impl IndividualTestOptions {
}
}
pub(crate) trait Tester {
fn add_test(&mut self, test: String, config: LangString, line: usize);
pub(crate) trait DoctestVisitor {
fn visit_test(&mut self, test: String, config: LangString, line: usize);
fn get_line(&self) -> usize {
0
}
fn register_header(&mut self, _name: &str, _level: u32) {}
fn visit_header(&mut self, _name: &str, _level: u32) {}
}
pub(crate) struct Collector {
@ -1091,8 +1091,8 @@ impl Collector {
}
}
impl Tester for Collector {
fn add_test(&mut self, test: String, config: LangString, line: usize) {
impl DoctestVisitor for Collector {
fn visit_test(&mut self, test: String, config: LangString, line: usize) {
let filename = self.get_filename();
let name = self.generate_name(line, &filename);
let crate_name = self.crate_name.clone();
@ -1242,7 +1242,7 @@ impl Tester for Collector {
}
}
fn register_header(&mut self, name: &str, level: u32) {
fn visit_header(&mut self, name: &str, level: u32) {
if self.use_headers {
// We use these headings as test names, so it's good if
// they're valid identifiers.
@ -1287,8 +1287,8 @@ impl Tester for Collector {
}
#[cfg(test)] // used in tests
impl Tester for Vec<usize> {
fn add_test(&mut self, _test: String, _config: LangString, line: usize) {
impl DoctestVisitor for Vec<usize> {
fn visit_test(&mut self, _test: String, _config: LangString, line: usize) {
self.push(line);
}
}

View File

@ -710,7 +710,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> {
}
}
pub(crate) fn find_testable_code<T: doctest::Tester>(
pub(crate) fn find_testable_code<T: doctest::DoctestVisitor>(
doc: &str,
tests: &mut T,
error_codes: ErrorCodes,
@ -720,7 +720,7 @@ pub(crate) fn find_testable_code<T: doctest::Tester>(
find_codes(doc, tests, error_codes, enable_per_target_ignores, extra_info, false)
}
pub(crate) fn find_codes<T: doctest::Tester>(
pub(crate) fn find_codes<T: doctest::DoctestVisitor>(
doc: &str,
tests: &mut T,
error_codes: ErrorCodes,
@ -773,7 +773,7 @@ pub(crate) fn find_codes<T: doctest::Tester>(
nb_lines -= 1;
}
let line = tests.get_line() + nb_lines + 1;
tests.add_test(text, block_info, line);
tests.visit_test(text, block_info, line);
prev_offset = offset.start;
}
Event::Start(Tag::Heading(level, _, _)) => {
@ -781,7 +781,7 @@ pub(crate) fn find_codes<T: doctest::Tester>(
}
Event::Text(ref s) if register_header.is_some() => {
let level = register_header.unwrap();
tests.register_header(s, level);
tests.visit_header(s, level);
register_header = None;
}
_ => {}

View File

@ -44,8 +44,8 @@ pub(crate) struct Tests {
pub(crate) found_tests: usize,
}
impl crate::doctest::Tester for Tests {
fn add_test(&mut self, _: String, config: LangString, _: usize) {
impl crate::doctest::DoctestVisitor for Tests {
fn visit_test(&mut self, _: String, config: LangString, _: usize) {
if config.rust && config.ignore == Ignore::None {
self.found_tests += 1;
}