mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Use human readable forms of ansi codes in reporting tests
This commit is contained in:
parent
86c1ec27a9
commit
ab61d3d357
2 changed files with 19 additions and 11 deletions
|
@ -103,12 +103,15 @@ fn newline() -> ReportText {
|
|||
plain_text("\n")
|
||||
}
|
||||
|
||||
pub const RED_CODE: &str = "\u{001b}[31m";
|
||||
pub const WHITE_CODE: &str = "\u{001b}[31m";
|
||||
|
||||
fn red(str: &str) -> String {
|
||||
let mut buf = String::new();
|
||||
|
||||
buf.push_str("\u{001b}[31m");
|
||||
buf.push_str(RED_CODE);
|
||||
buf.push_str(str);
|
||||
buf.push_str("\u{001b}[0m");
|
||||
buf.push_str(RESET_CODE);
|
||||
|
||||
buf
|
||||
}
|
||||
|
@ -116,14 +119,14 @@ fn red(str: &str) -> String {
|
|||
fn white(str: &str) -> String {
|
||||
let mut buf = String::new();
|
||||
|
||||
buf.push_str("\u{001b}[31m");
|
||||
buf.push_str(WHITE_CODE);
|
||||
buf.push_str(str);
|
||||
buf.push_str(RESET);
|
||||
buf.push_str(RESET_CODE);
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
const RESET: &str = "\u{001b}[0m";
|
||||
pub const RESET_CODE: &str = "\u{001b}[0m";
|
||||
|
||||
impl ReportText {
|
||||
/// Render to CI console output, where no colors are available.
|
||||
|
|
|
@ -11,7 +11,9 @@ mod helpers;
|
|||
mod test_report {
|
||||
use crate::helpers::test_home;
|
||||
use roc_module::symbol::{Interns, ModuleId};
|
||||
use roc_reporting::report::{can_problem, plain_text, Report, ReportText, DEFAULT_PALETTE};
|
||||
use roc_reporting::report::{
|
||||
can_problem, plain_text, Report, ReportText, DEFAULT_PALETTE, RED_CODE, RESET_CODE,
|
||||
};
|
||||
use roc_types::pretty_print::name_all_type_vars;
|
||||
use roc_types::subs::Subs;
|
||||
use roc_types::types;
|
||||
|
@ -82,6 +84,12 @@ mod test_report {
|
|||
assert_eq!(buf, expected_rendering);
|
||||
}
|
||||
|
||||
fn human_readable(str: &str) -> String {
|
||||
return str
|
||||
.replace(RED_CODE, "<red>")
|
||||
.replace(RESET_CODE, "<reset>");
|
||||
}
|
||||
|
||||
fn report_renders_in_color_from_src(src: &str, report: Report, expected_rendering: &str) {
|
||||
let (_type_problems, _can_problems, mut subs, home, interns) = infer_expr_help(src);
|
||||
let mut buf: String = String::new();
|
||||
|
@ -96,7 +104,7 @@ mod test_report {
|
|||
DEFAULT_PALETTE,
|
||||
);
|
||||
|
||||
assert_eq!(buf, expected_rendering);
|
||||
assert_eq!(human_readable(&buf), expected_rendering);
|
||||
}
|
||||
|
||||
fn report_renders_in_color(report: Report, expected_rendering: &str) {
|
||||
|
@ -245,10 +253,7 @@ mod test_report {
|
|||
|
||||
#[test]
|
||||
fn report_in_color() {
|
||||
report_renders_in_color(
|
||||
to_simple_report(plain_text("y")),
|
||||
"\u{001b}[31my\u{001b}[0m",
|
||||
);
|
||||
report_renders_in_color(to_simple_report(plain_text("y")), "<red>y<reset>");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue