1 use codespan_reporting::diagnostic::Diagnostic; 2 use codespan_reporting::files::Files; 3 use codespan_reporting::term::{emit, Config}; 4 use termcolor::{Buffer, WriteColor}; 5 6 mod color_buffer; 7 8 use self::color_buffer::ColorBuffer; 9 10 pub struct TestData<'files, F: Files<'files>> { 11 pub files: F, 12 pub diagnostics: Vec<Diagnostic<F::FileId>>, 13 } 14 15 impl<'files, F: Files<'files>> TestData<'files, F> { emit<W: WriteColor>(&'files self, mut writer: W, config: &Config) -> W16 fn emit<W: WriteColor>(&'files self, mut writer: W, config: &Config) -> W { 17 for diagnostic in &self.diagnostics { 18 emit(&mut writer, config, &self.files, &diagnostic).unwrap(); 19 } 20 writer 21 } 22 emit_color(&'files self, config: &Config) -> String23 pub fn emit_color(&'files self, config: &Config) -> String { 24 self.emit(ColorBuffer::new(), &config).into_string() 25 } 26 emit_no_color(&'files self, config: &Config) -> String27 pub fn emit_no_color(&'files self, config: &Config) -> String { 28 let buffer = self.emit(Buffer::no_color(), &config); 29 String::from_utf8_lossy(buffer.as_slice()).into_owned() 30 } 31 } 32