csvpp/source_code/
display.rs1use super::SourceCode;
2use std::fmt;
3
4impl fmt::Display for SourceCode {
5 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6 write!(
7 f,
8 "{}: total_lines: {}, csv_section: {}, scope: {}",
9 self.filename.display(),
10 self.lines,
11 self.length_of_csv_section,
12 self.length_of_code_section,
13 )
14 }
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20 use std::path;
21
22 fn build_source_code() -> SourceCode {
23 SourceCode {
24 filename: path::PathBuf::from("test.csvpp".to_string()),
25 lines: 25,
26 length_of_code_section: 10,
27 length_of_csv_section: 15,
28 code_section: Some("\n".repeat(10)),
29 csv_section: "foo,bar,baz".to_string(),
30 original: "\n\n\n\n\n\n\n\n\n\n---\nfoo,bar,baz".to_string(),
31 }
32 }
33
34 #[test]
35 fn display() {
36 assert_eq!(
37 "test.csvpp: total_lines: 25, csv_section: 15, scope: 10",
38 build_source_code().to_string(),
39 );
40 }
41}