Skip to content

Commit

Permalink
adding to price parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
alensiljak committed Sep 7, 2023
1 parent 290fc02 commit c0c09d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ impl Amount {
pub fn new(quantity: Quantity, commodity: Option<*const Commodity>) -> Self {
Self {
quantity,
commodity: if commodity.is_some() {
commodity.unwrap()
} else {
std::ptr::null()
},
commodity: match commodity {
Some(c) => c,
_ => std::ptr::null()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'j, T: Read> Parser<'j, T> {
todo!("handle other directives");
}
}
todo!("the rest")
// TODO: todo!("the rest")
}
}

Expand Down
1 change: 0 additions & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ impl CommodityPool {
is_per_unit: bool,
moment: NaiveDateTime,
) -> (CostBreakdown, Option<Price>) {
// amount.commodity_index

// annotations
let annotation_opt: Option<&Annotation> =
Expand Down
11 changes: 9 additions & 2 deletions tests/functional-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

use std::io::Cursor;

use ledger_rs_lib::journal::Journal;
use chrono::Local;
use ledger_rs_lib::{journal::Journal, amount::{Amount, Quantity}};

/// TODO: complete the functionality and the test
//#[test]
Expand All @@ -19,7 +20,13 @@ P 2022-03-03 13:00:00 EUR 1.12 USD
ledger_rs_lib::parse_text(text, &mut j);

// Assert
//j.
let eur = j.commodity_pool.find("EUR").unwrap();
let usd = j.commodity_pool.find("USD").unwrap();
let three_eur = Amount::new(Quantity::from(3), Some(eur));
let exch_rate = Amount::new(Quantity::from(1.5), Some(usd));

let (cost_breakdown, price) = j.commodity_pool.exchange(&three_eur, &exch_rate, true, Local::now().naive_local());
assert!(price.is_some());
todo!("check that the price was parsed")
}

Expand Down

0 comments on commit c0c09d2

Please sign in to comment.