add basic snapshot test for pretty printer

korrat
Sep 29, 2022, 4:30 PM
ONRIF4V72HMVLO4BWDHI7ZOWYWTLTVYNH5TXUN5HB7BQUMV22NVAC

Dependencies

  • [2] D6UTHZA4 add a simple writer for saving a set of directives to a tree of files
  • [3] YDK6X6PP add a library of important types for beancount
  • [4] I2P2FTLE add basic parser for german decimals
  • [5] MYQI5JID update dependencies
  • [6] QRIJE4AQ add a simple pretty printer for beancount directives

Change contents

  • file addition: tests (d--r------)
    [3.36]
  • file addition: snapshotting.rs (---r------)
    [0.17]
    use beancount_pretty_printer::PrettyPrinter;
    use beancount_types::Account;
    use beancount_types::Amount;
    use beancount_types::Commodity;
    use beancount_types::Posting;
    use beancount_types::Transaction;
    use beancount_types::TransactionFlag::Complete;
    use rust_decimal_macros::dec;
    #[test]
    fn pretty_printed_transaction() {
    let mut buffer = Vec::with_capacity(1_024);
    let mut printer = PrettyPrinter::<_, 2, 2, 100>::unbuffered(&mut buffer);
    printer
    .print_transaction(&Transaction {
    date: time::macros::date!(2022 - 03 - 07),
    flag: Complete,
    payee: None,
    narration: None,
    postings: vec![
    Posting {
    flag: None,
    account: Account::try_from("Assets:Checking").unwrap(),
    amount: Some(Amount {
    amount: dec!(-100.00),
    commodity: Commodity::try_from("EUR").unwrap(),
    }),
    cost: None,
    price: None,
    },
    Posting {
    flag: None,
    account: Account::try_from("Assets:Wallet").unwrap(),
    amount: Some(Amount {
    amount: dec!(100.00),
    commodity: Commodity::try_from("EUR").unwrap(),
    }),
    cost: None,
    price: None,
    },
    ],
    })
    .unwrap();
    let formatted = String::from_utf8(buffer).unwrap();
    insta::assert_display_snapshot!(formatted)
    }
  • file addition: snapshots (d--r------)
    [0.17]
  • file addition: snapshotting__pretty_printed_transaction.snap (---r------)
    [0.1703]
    ---
    source: common/beancount-pretty-printer/tests/snapshotting.rs
    expression: formatted
    ---
    2022-03-07 *
    Assets:Checking -100.00 EUR
    Assets:Wallet 100.00 EUR
  • replacement in common/beancount-pretty-printer/src/lib.rs at line 39
    [3.1051][3.1051:1117]()
    let inner = BufWriter::new(inner);
    Self { inner }
    [3.1051]
    [3.1117]
    Self::unbuffered(BufWriter::new(inner))
  • replacement in common/beancount-pretty-printer/Cargo.toml at line 9
    [3.5259][3.5259:5283]()
    rust_decimal = "1.26.1"
    [3.5259]
    [3.5283]
    rust_decimal.workspace = true
  • edit in common/beancount-pretty-printer/Cargo.toml at line 13
    [3.5343]
    [dev-dependencies]
    insta.workspace = true
    time.workspace = true
    rust_decimal_macros.workspace = true
  • edit in Cargo.toml at line 8
    [3.5456]
    [workspace.dependencies]
    insta = "1.21.0"
    rust_decimal = "1.26.1"
    rust_decimal_macros = "1.26.1"
    [workspace.dependencies.time]
    features = ["macros"]
    version = "0.3.14"
  • edit in Cargo.lock at line 61
    [3.5565]
    [3.5565]
    "insta",
  • edit in Cargo.lock at line 63
    [3.5582]
    [2.5677]
    "rust_decimal_macros",
    "time",
  • replacement in Cargo.lock at line 174
    [3.27781][3.27781:27800]()
    version = "0.15.1"
    [3.27781]
    [3.27800]
    version = "0.15.2"
  • replacement in Cargo.lock at line 176
    [3.27865][3.27865:27943]()
    checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847"
    [3.27865]
    [3.27943]
    checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c"
  • edit in Cargo.lock at line 179
    [3.27979]
    [3.27979]
    "lazy_static",
  • edit in Cargo.lock at line 181
    [3.27988][3.27988:28002]()
    "once_cell",
  • replacement in Cargo.lock at line 352
    [3.29541][3.133:152]()
    version = "1.20.0"
    [3.29541]
    [3.29560]
    version = "1.21.0"
  • replacement in Cargo.lock at line 354
    [3.29625][3.153:231]()
    checksum = "58a931b01c76064c5be919faa2ef0dc570e9a889dcd1e5fef08a8ca6eb4d6c0b"
    [3.29625]
    [3.29703]
    checksum = "581d4e3314cae4536e5d22ffd23189d4a374696c5ef733eadafae0ed273fd303"
  • edit in Cargo.lock at line 357
    [3.29732]
    [3.29732]
    "lazy_static",
  • edit in Cargo.lock at line 359
    [3.29752][3.29752:29766]()
    "once_cell",
  • edit in Cargo.lock at line 876
    [3.37845]
    [2.13122]
    "time-macros",
  • edit in Cargo.lock at line 880
    [2.13137]
    [2.13137]
    name = "time-macros"
    version = "0.2.4"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
    [[package]]