Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow commodities that end with numbers #63

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))))
Expand Down
10 changes: 9 additions & 1 deletion tests/parser_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\"";
Expand Down Expand Up @@ -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",
Expand Down