Skip to content

Commit

Permalink
[sc-524] Change Display impl of Book and Net to include lines bet…
Browse files Browse the repository at this point in the history
…ween empty defs and indent redexes (HigherOrderCO#90)

Co-authored-by: tjjfvi <[email protected]>
  • Loading branch information
FranchuFranchu and tjjfvi authored Mar 19, 2024
1 parent e86e979 commit 09a3791
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,11 @@ impl FromStr for Tree {

impl fmt::Display for Book {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for (name, net) in self.iter() {
writeln!(f, "@{name} = {net}")?;
for (i, (name, net)) in self.iter().enumerate() {
if i != 0 {
f.write_str("\n\n")?;
}
write!(f, "@{name} = {net}")?;
}
Ok(())
}
Expand All @@ -469,7 +472,7 @@ impl fmt::Display for Net {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &self.root)?;
for (a, b) in &self.redexes {
write!(f, "\n& {a} ~ {b}")?;
write!(f, "\n & {a} ~ {b}")?;
}
Ok(())
}
Expand Down
19 changes: 13 additions & 6 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,16 @@ fn test_cli_transform() {
]).unwrap().1,
@r###"
@add = (<+ a b> (a b))
@div = (</ a b> (a b))
@main = ({3 </ a b> <% c d>} ({5 a c} [b d]))
@mod = (<% a b> (a b))
@mul = (<* a b> (a b))
@sub = (<- a b> (a b))
@sub = (<- a b> (a b))
"###
);

Expand All @@ -144,14 +148,18 @@ fn test_cli_transform() {
]).unwrap().1,
@r###"
@add = (<+ a b> (a b))
@div = (</ a b> (a b))
@main = ({3 a b} ({5 c d} [e f]))
& @mod ~ (b (d f))
& @div ~ (a (c e))
& @mod ~ (b (d f))
& @div ~ (a (c e))
@mod = (<% a b> (a b))
@mul = (<* a b> (a b))
@sub = (<- a b> (a b))
@sub = (<- a b> (a b))
"###
);

Expand All @@ -165,8 +173,7 @@ fn test_cli_transform() {
]).unwrap().1,
@r###"
@main = a
& @HVM.log ~ (#1 (#2 a))
& @HVM.log ~ (#1 (#2 a))
"###
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn test_eta() {
assert_display_snapshot!(parse_and_reduce("<+ (a b) (a b)>"), @"<+ a a>");
assert_display_snapshot!(parse_and_reduce("(a b) & ((a b) (c d)) ~ (c d) "), @r###"
a
& (a c) ~ c
& (a c) ~ c
"###);
assert_display_snapshot!(parse_and_reduce("((a b) [a b])"), @"((a b) [a b])");
assert_display_snapshot!(parse_and_reduce("((a b c) b c)"), @"((a b) b)");
Expand Down

0 comments on commit 09a3791

Please sign in to comment.