Skip to content

Commit

Permalink
* support of all variations of linebreaks (CR) (LF) (CR LF)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadym Kurachevskyi committed Jan 31, 2023
1 parent 5189fb6 commit 7d8504c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ABA {
parse(content: string): Batch[] {
// split ABA into lines
const batches = [];
const lines = content.split(/\r?\n/);
const lines = content.split(/\r\n|\r|\n/);
let header;
let transactions = [];

Expand Down
1 change: 1 addition & 0 deletions test/ABA-files/aba_second.file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0502027034.96.47 01CPU SAMPLE PTY LTD 123456SWEEP 230522027034.96.47 UUUUUU-NNE1123-456123456789 500000000009SAMPLE SAMPLE 987-654123456789CBA 000000001123-456123456789 500002525755SAMPLE SAMPLE 987-654123456789CBA 000000001123-456123456789 500086002588SAMPLE SAMPLE 987-654123456789CBA 000000001123-456123456789 500000000004SAMPLE SAMPLE 987-654123456789CBA 000000001123-456123456789 500000697722SAMPLE SAMPLE 987-654123456789CBA 000000001123-456123456789 500000053951SAMPLE SAMPLE 987-654123456789CBA 000000007999-999 008928002900892800290000000000 000006 0132027034.96.45 01CPU SAMPLE PTY LTD 123456SWEEP 230522027034.96.45 UUUUUU-NNE1123-456123456789 130000000004SAMPLE SAMPLE 987-654123456789WBC 000000001123-456123456789 130000000188SAMPLE SAMPLE 987-654123456789WBC 000000001123-456123456789 130514197950SAMPLE SAMPLE 987-654123456789WBC 000000001123-456123456789 130000000363SAMPLE SAMPLE 987-654123456789WBC 000000007999-999 051419850500000000000514198505 000004 End-Of-File
Expand Down
15 changes: 15 additions & 0 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ test("index tests", async (t) => {
}
});

await t.test("should parse CR linebreaks file correctly", function () {
const sourceFile = fs.readFileSync("./test/ABA-files/aba_second.file").toString();

const aba = new ABA();

const batches = aba.parse(sourceFile);
assert.strictEqual(batches.length, 2, "Two batches")
assert.strictEqual(batches[0].transactions.length, 6, "6 transaction in 1st batch")
assert.strictEqual(batches[1].transactions.length, 4, "4 transaction in 2nd batch")
for (const batch of batches) {
const validationResult = aba.validateBatch(batch);
assert.strictEqual(validationResult.success, true);
}
});

await t.test("should open file, read it and don't throw error", function () {
const sourceFile = fs.readFileSync("./test/ABA-files/aba_test.file", "utf8");

Expand Down

0 comments on commit 7d8504c

Please sign in to comment.