Add a Malformed trait, and assert that 'passing' tests don't produce a malformed result

This commit is contained in:
Joshua Warner 2023-01-25 20:57:12 -08:00
parent c60dcd763d
commit a1cd114198
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
26 changed files with 506 additions and 64 deletions

View file

@ -1,7 +1,7 @@
use bumpalo::Bump;
use roc_fmt::{annotation::Formattable, module::fmt_module};
use roc_parse::{
ast::{Defs, Expr, Module},
ast::{Defs, Expr, Malformed, Module},
module::module_defs,
parser::{Parser, SyntaxError},
state::State,
@ -104,6 +104,20 @@ impl<'a> Output<'a> {
}
}
impl<'a> Malformed for Output<'a> {
fn is_malformed(&self) -> bool {
match self {
Output::Header(header) => header.is_malformed(),
Output::ModuleDefs(defs) => defs.is_malformed(),
Output::Expr(expr) => expr.is_malformed(),
Output::Full {
header,
module_defs,
} => header.is_malformed() || module_defs.is_malformed(),
}
}
}
impl<'a> RemoveSpaces<'a> for Output<'a> {
fn remove_spaces(&self, arena: &'a Bump) -> Self {
match self {