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

Non standard account name #76

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 5 additions & 9 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use std::{
};

use nom::{
branch::alt,
bytes::{complete::tag, complete::take_while},
bytes::complete::take_while,
character::complete::{char, satisfy, space0, space1},
combinator::{all_consuming, cut, iterator, opt, recognize},
multi::many1_count,
Expand Down Expand Up @@ -192,13 +191,10 @@ pub struct Pad {

pub(super) fn parse(input: Span<'_>) -> IResult<'_, Account> {
let (input, name) = recognize(preceded(
alt((
tag("Expenses"),
tag("Assets"),
tag("Liabilities"),
tag("Income"),
tag("Equity"),
)),
preceded(
satisfy(|c: char| c.is_uppercase() || c.is_ascii_digit()),
take_while(|c: char| c.is_alphanumeric() || c == '-'),
),
cut(many1_count(preceded(
char(':'),
preceded(
Expand Down
4 changes: 2 additions & 2 deletions tests/parse_from_file_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use beancount_parser::BeancountFile;

#[rstest]
#[case("comments.beancount", 0)]
#[case("simple.beancount", 13)]
#[case("official.beancount", 2151)]
#[case("simple.beancount", 16)]
#[case("official.beancount", 2154)]
fn can_parse_example_files(#[case] file_name: &str, #[case] expected_directive_count: usize) {
let mut path: PathBuf = "./tests/samples".into();
path.push(file_name);
Expand Down
2 changes: 1 addition & 1 deletion tests/parser_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn should_succeed_for_valid_input(#[values("", "\n", COMMENTS, SIMPLE, OFFICIAL)

#[rstest]
#[case("", 0)]
#[case(SIMPLE, 10)]
#[case(SIMPLE, 12)]
fn should_find_all_open_directives(#[case] input: &str, #[case] expected_count: usize) {
let actual_count = parse::<f64>(input)
.expect("parsing should succeed")
Expand Down
6 changes: 6 additions & 0 deletions tests/samples/simple.beancount
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
2000-01-01 open Assets:AccountsReceivable:Michael USD
2000-01-01 open Assets:MyBank:Checking USD
2000-01-01 open Assets:MyBank:Savings USD
2000-01-01 open Aktiva:MyBank:Checking USD
2000-01-01 open Liabilities:CreditCard:CapitalOne
2000-01-01 open Income:AcmeCorp:Salary
2000-01-01 open Expenses:Taxes:TY2014:Federal
2000-01-01 open Expenses:Taxes:TY2014:SocSec
2000-01-01 open Expenses:Taxes:TY2014:Medicare
2000-01-01 open Expenses:Taxes:TY2014:StateNY
2000-01-01 open Expenses:Taxes:TY2014:SDI
2000-01-01 open Ausgaben:Taxes:TY2014:SDI

2014-10-05 * "Costco" "Shopping for birthday"
Schulden:CreditCard:CapitalOne -45.00 USD
Aktiva:AccountsReceivable:Michael 40.00 USD
Ausgaben:Shopping

2014-10-05 * "Costco" "Shopping for birthday"
Liabilities:CreditCard:CapitalOne -45.00 USD
Expand Down
4 changes: 2 additions & 2 deletions tests/trx_parser_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const OFFICIAL: &str = include_str!("samples/official.beancount");
#[rstest]
#[case("", 0)]
#[case(COMMENTS, 0)]
#[case(SIMPLE, 3)]
#[case(SIMPLE, 4)]
#[case(OFFICIAL, 1096)]
fn should_find_all_transactions(#[case] input: &str, #[case] expected_count: usize) {
let actual_count = parse_iter::<f64>(input)
Expand All @@ -35,7 +35,7 @@ fn should_find_all_transactions(#[case] input: &str, #[case] expected_count: usi
#[rstest]
#[case("", 0)]
#[case(COMMENTS, 0)]
#[case(SIMPLE, 12)]
#[case(SIMPLE, 15)]
#[case(OFFICIAL, 3385)]
fn should_find_all_postings(#[case] input: &str, #[case] expected_count: usize) {
let actual_count: usize = parse::<f64>(input)
Expand Down