Skip to content

Commit

Permalink
fix: allow commodities that end with numbers (#63)
Browse files Browse the repository at this point in the history
doriath authored Jan 7, 2024
1 parent be9f66f commit c49a685
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/amount.rs
Original file line number Diff line number Diff line change
@@ -173,7 +173,12 @@ pub(crate) fn currency(input: Span<'_>) -> IResult<'_, Currency> {
take_while(|c: char| {
c.is_uppercase() || c.is_numeric() || c == '-' || c == '_' || c == '.' || c == '\''
}),
|s: &Span<'_>| s.fragment().chars().last().map_or(true, char::is_uppercase),
|s: &Span<'_>| {
s.fragment()
.chars()
.last()
.map_or(true, |c| c.is_uppercase() || c.is_numeric())
},
),
)))(input)?;
Ok((input, Currency(Arc::from(*currency.fragment()))))
10 changes: 9 additions & 1 deletion tests/parser_spec.rs
Original file line number Diff line number Diff line change
@@ -239,6 +239,15 @@ fn should_parse_commodity() {
assert_eq!(commodity.as_str(), "USD");
}

#[rstest]
fn should_parse_commodity_that_ends_with_number() {
let input = "1792-01-01 commodity A1";
let DirectiveContent::Commodity(commodity) = parse_single_directive(input).content else {
panic!("was not an commodity directive");
};
assert_eq!(commodity.as_str(), "A1");
}

#[rstest]
fn should_parse_event() {
let input = "2020-12-09 event \"location\" \"New Metropolis\"";
@@ -377,7 +386,6 @@ fn should_reject_invalid_input(
"2014-05-01 open Assets:Checking Hello",
"2014-05-01 open Assets:Checking USD CHF",
"2014-05-01 open Assets:Checking 1SD",
"2014-05-01 open Assets:Checking US2",
"2014-05-01 open Assets:Checking US-",
"2014-05-01 open Assets:Checking -US",
"2014-05-01close Assets:Cash",

0 comments on commit c49a685

Please sign in to comment.