]> git.proxmox.com Git - rustc.git/blob - vendor/codespan-reporting/tests/support/mod.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / vendor / codespan-reporting / tests / support / mod.rs
1 use codespan::Files;
2 use codespan_reporting::diagnostic::Diagnostic;
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 {
11 pub files: Files,
12 pub diagnostics: Vec<Diagnostic>,
13 }
14
15 impl TestData {
16 fn emit<W: WriteColor>(&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
23 pub fn emit_color(&self, config: &Config) -> String {
24 self.emit(ColorBuffer::new(), &config).into_string()
25 }
26
27 pub fn emit_no_color(&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 }