Support printing can decls in uitest

This commit is contained in:
Ayaz Hafiz 2023-03-31 14:34:06 -05:00
parent d891dd829f
commit a10ce77584
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
6 changed files with 193 additions and 89 deletions

View file

@ -19,6 +19,33 @@ pub struct Ctx<'a> {
pub fn pretty_print_declarations(c: &Ctx, declarations: &Declarations) -> String {
let f = Arena::new();
print_declarations_help(c, &f, declarations)
.1
.pretty(80)
.to_string()
}
pub fn pretty_write_declarations(
writer: &mut impl std::io::Write,
c: &Ctx,
declarations: &Declarations,
) -> std::io::Result<()> {
let f = Arena::new();
print_declarations_help(c, &f, declarations)
.1
.render(80, writer)
}
pub fn pretty_print_def(c: &Ctx, d: &Def) -> String {
let f = Arena::new();
def(c, &f, d).append(f.hardline()).1.pretty(80).to_string()
}
fn print_declarations_help<'a>(
c: &Ctx,
f: &'a Arena<'a>,
declarations: &'a Declarations,
) -> DocBuilder<'a, Arena<'a>> {
let mut defs = Vec::with_capacity(declarations.len());
for (index, tag) in declarations.iter_bottom_up() {
let symbol = declarations.symbols[index].value;
@ -45,14 +72,6 @@ pub fn pretty_print_declarations(c: &Ctx, declarations: &Declarations) -> String
}
f.intersperse(defs, f.hardline().append(f.hardline()))
.1
.pretty(80)
.to_string()
}
pub fn pretty_print_def(c: &Ctx, d: &Def) -> String {
let f = Arena::new();
def(c, &f, d).append(f.hardline()).1.pretty(80).to_string()
}
macro_rules! maybe_paren {