Something went wrong. Try again.
Convert CSV banking statements to hledger journals
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445import assert from "assert";import { appended, clause, patternOf } from "./clause.js";
Deno.test("D12: a cell suggests its text as a case-insensitive regex on the alias", () => { assert.equal(clause("payee", patternOf("REWE Markt")), "payee ~= /REWE Markt/i");});
Deno.test("D12: whitespace around the text is not part of the pattern", () => { assert.equal(patternOf(" REWE Markt \t"), "REWE Markt");});
Deno.test("D12: a slash would end the regex literal, so it matches any character instead", () => { assert.equal(patternOf("Miete 10/2026"), "Miete 10.2026");});
Deno.test("D12: line breaks and tabs inside the text are written as escapes", () => { assert.equal(patternOf("a\r\nb\tc"), "a\\r\\nb\\tc");});
Deno.test("D12: other regex characters are left for the author to edit", () => { assert.equal(patternOf("AMAZON.DE*MKTP (EU)"), "AMAZON.DE*MKTP (EU)");});
Deno.test("D12: a cell of nothing but whitespace suggests no pattern", () => { assert.equal(patternOf(" \t "), null); assert.equal(patternOf(""), null);});
const payee = "payee ~= /REWE/i";const memo = "memo ~= /Markt/i";
Deno.test("D12: an empty condition becomes the selected cells' clauses, joined with and", () => { assert.equal(appended([payee, memo], ""), "payee ~= /REWE/i and memo ~= /Markt/i"); assert.equal(appended([payee], " \n"), "payee ~= /REWE/i");});
Deno.test("D12: after a condition, the clauses are an alternative to it, on a line of their own", () => { assert.equal(appended([payee, memo], "a"), "\nor (payee ~= /REWE/i and memo ~= /Markt/i)"); assert.equal(appended([payee, memo], "a\n"), "or (payee ~= /REWE/i and memo ~= /Markt/i)");});
Deno.test("D12: one clause after a condition needs no brackets", () => { assert.equal(appended([payee], "a"), "\nor payee ~= /REWE/i");});