compiletest/directives/file.rs
1use camino::Utf8Path;
2
3use crate::directives::LineNumber;
4use crate::directives::line::{DirectiveLine, line_directive};
5
6pub(crate) struct FileDirectives<'a> {
7 pub(crate) path: &'a Utf8Path,
8 pub(crate) lines: Vec<DirectiveLine<'a>>,
9}
10
11impl<'a> FileDirectives<'a> {
12 pub(crate) fn from_file_contents(path: &'a Utf8Path, file_contents: &'a str) -> Self {
13 let mut lines = vec![];
14
15 for (line_number, ln) in LineNumber::enumerate().zip(file_contents.lines()) {
16 let ln = ln.trim();
17
18 if let Some(directive_line) = line_directive(path, line_number, ln) {
19 lines.push(directive_line);
20 }
21 }
22
23 Self { path, lines }
24 }
25}