Skip to content

Commit

Permalink
Merge pull request AleoNet#1318 from AleoHQ/fix/struct-fmt
Browse files Browse the repository at this point in the history
Fix extra closing brace bug in formatter
  • Loading branch information
Collin Chin authored Jan 10, 2023
2 parents 8a9982c + f976791 commit dffd731
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion console/program/src/data/plaintext/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<N: Network> Plaintext<N> {
// Print the last member without a comma.
true => write!(f, "\n{:indent$}}}", "", indent = depth * INDENT),
// Print the member with a comma.
false => write!(f, "\n{:indent$}}},", "", indent = depth * INDENT),
false => write!(f, ","),
}
}
}
Expand Down Expand Up @@ -243,4 +243,49 @@ mod tests {
Plaintext::<CurrentNetwork>::parse("foo_bar_baz_qux_quux_quuz_corge_grault_garply_waldo_fred_plugh_xyzzy");
assert!(plaintext.is_err());
}

#[test]
fn test_nested_structs1() {
let expected = r"{
r1: {
c1: 1u8,
c2: 2u8,
c3: 1u8
},
r2: {
c1: 2u8,
c2: 2u8,
c3: 1u8
},
r3: {
c1: 1u8,
c2: 2u8,
c3: 1u8
}
}";

let (remainder, candidate) = Plaintext::<CurrentNetwork>::parse(expected).unwrap();
println!("\nExpected: {expected}\n\nFound: {candidate}\n");
assert_eq!(expected, candidate.to_string());
assert_eq!("", remainder);
}

#[test]
fn test_nested_structs2() {
let expected = r"{
foo: {
bar: {
baz: 1u8
},
qux: {
quux: 2u8
}
}
}";

let (remainder, candidate) = Plaintext::<CurrentNetwork>::parse(expected).unwrap();
println!("\nExpected: {expected}\n\nFound: {candidate}\n");
assert_eq!(expected, candidate.to_string());
assert_eq!("", remainder);
}
}

0 comments on commit dffd731

Please sign in to comment.