From be7a441205ad66b43d36054b845e1c4ba71257a0 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 19 Jul 2023 13:49:05 -0400 Subject: [PATCH] fix(uplc): pair type formatting closes #680 --- crates/aiken-project/src/config.rs | 2 +- crates/uplc/src/parser.rs | 1 + crates/uplc/src/pretty.rs | 30 ++++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/crates/aiken-project/src/config.rs b/crates/aiken-project/src/config.rs index 64606e3b..785bc517 100644 --- a/crates/aiken-project/src/config.rs +++ b/crates/aiken-project/src/config.rs @@ -99,7 +99,7 @@ impl Config { } pub fn insert(mut self, dependency: &Dependency, and_replace: bool) -> Option { - for mut existing in self.dependencies.iter_mut() { + for existing in self.dependencies.iter_mut() { if existing.name == dependency.name { return if and_replace { existing.version = dependency.version.clone(); diff --git a/crates/uplc/src/parser.rs b/crates/uplc/src/parser.rs index 5a52fd4d..0ff8e0ec 100644 --- a/crates/uplc/src/parser.rs +++ b/crates/uplc/src/parser.rs @@ -308,6 +308,7 @@ peg::parser! { #[cfg(test)] mod tests { use num_bigint::BigInt; + use pretty_assertions::assert_eq; use crate::ast::{Constant, Name, Program, Term, Type, Unique}; use crate::builtins::DefaultFunction; diff --git a/crates/uplc/src/pretty.rs b/crates/uplc/src/pretty.rs index 7b87d291..e06c5e7d 100644 --- a/crates/uplc/src/pretty.rs +++ b/crates/uplc/src/pretty.rs @@ -318,13 +318,35 @@ impl Type { .append(r#type.to_doc()) .append(RcDoc::line_()) .append(")"), - Type::Pair(l, r) => RcDoc::text("pair") - .append(RcDoc::text("<")) + Type::Pair(l, r) => RcDoc::text("(pair") + .append(RcDoc::line()) .append(l.to_doc()) - .append(RcDoc::text(", ")) + .append(RcDoc::line()) .append(r.to_doc()) - .append(RcDoc::text(">")), + .append(")"), Type::Data => RcDoc::text("data"), } } } + +#[cfg(test)] +mod tests { + use indoc::indoc; + use pretty_assertions::assert_eq; + + #[test] + fn format_pair_bool_pair_integer_bytestring() { + let uplc = "(program 0.0.0 (con (pair bool (pair integer bytestring)) (True, (14, #42))))"; + + assert_eq!( + crate::parser::program(uplc).unwrap().to_pretty(), + indoc! { + r#" + (program + 0.0.0 + (con (pair bool (pair integer bytestring)) (True, (14, #42))) + )"# + } + ) + } +}