diff --git a/hledger/test/import/match.csv b/hledger/test/import/match.csv new file mode 100644 index 000000000..c9c45b9f4 --- /dev/null +++ b/hledger/test/import/match.csv @@ -0,0 +1 @@ +"62","2022-12-15","","Zettle_*Robert W. Bell","liabilities:jon:expenses:snacks","£ 7.90","£ 8.90" diff --git a/hledger/test/import/match.rules b/hledger/test/import/match.rules new file mode 100644 index 000000000..db087e2f6 --- /dev/null +++ b/hledger/test/import/match.rules @@ -0,0 +1,16 @@ +fields _, date, _, description, account1, amount, _ +# checking brackets in a field matcher are captured... +if %account1 liabilities:jon:(.*) +# ...and interpolated into field assignments (real-life use-case #2) + account1 \1 +# checking brackets in a record matcher are captured, including +# nesting... +if Zettle.*(Robert W. (Bell)).*£ +# ... and the interpolation token numerical offset is local to +# this match group; and the token is interpolated into surrounding +# text + comment1 Bell=\2. +# Match the YYY-MM of a date field and warp the posting date, useful +# for credit cards (real-life use-case #1)) +if %date (....-..)-.. + comment2 date:\1-01 diff --git a/hledger/test/import/match.test b/hledger/test/import/match.test new file mode 100644 index 000000000..728c9b982 --- /dev/null +++ b/hledger/test/import/match.test @@ -0,0 +1,10 @@ +# Various match group interpolation tests. See the comments +# in match.rules for specifics. +$ hledger -f a.j import --rules-file match.rules --dry-run match.csv +; would import 1 new transactions from match.csv: + +2022-12-15 Zettle_*Robert W. Bell + expenses:snacks £ 7.90 ; Bell=Bell. + income:unknown £ -7.90 ; date:2022-12-01 + +>=