Skip to content

Commit

Permalink
style: fixed code formatting with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
darylwright committed Mar 13, 2024
1 parent d415f2f commit 280bfbf
Show file tree
Hide file tree
Showing 41 changed files with 731 additions and 501 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"generate:diagram": "ts-node ./tools/generate_diagram.ts",
"test": "run-s build:dev test:*",
"test:lint": "eslint src --ext .ts",
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
"test:prettier": "prettier \"src/**/*.ts\" --check",
"test:unit": "nyc ava",
"check-cli": "run-s test diff-integration-tests check-integration-tests",
"check-integration-tests": "run-s check-integration-test:*",
Expand Down
5 changes: 1 addition & 4 deletions src/__tests__/cst_to_raw_ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { cstToRawLedger, parseLedgerToCST } from '../index';

import { assertNoLexingOrParsingErrors } from './utils';


test('converts from concrete syntax tree to raw journal', (t) => {
const cstResult = parseLedgerToCST(`1900/01/01 A transaction ; a comment
Assets:Chequing -$1.00 = $99.00
Expand Down Expand Up @@ -34,9 +33,7 @@ commodity 1000.00 USD ; comment

assertNoLexingOrParsingErrors(t, cstResult);

const result = cstToRawLedger(
cstResult.cstJournal
);
const result = cstToRawLedger(cstResult.cstJournal);
t.is(result.length, 9, 'should have 9 items in the parsed object');
t.is(
result[0].type,
Expand Down
188 changes: 105 additions & 83 deletions src/__tests__/cst_to_raw_visitor/amount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import CstToRawVisitor from '../../lib/visitors/cst_to_raw';
import * as Raw from '../../lib/visitors/raw_types';
import { assertNoLexingOrParsingErrors } from '../utils';

function assertIsValidTransactionObject(t: ExecutionContext, result: Raw.Journal, message: string) {
function assertIsValidTransactionObject(
t: ExecutionContext,
result: Raw.Journal,
message: string
) {
t.is(result.length, 1, message);
t.is(result[0].type, 'transaction', 'should be a transaction object');
t.is(
Expand All @@ -20,11 +24,13 @@ test('returns a transaction object containing a posting with a positive amount a

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -44,11 +50,13 @@ test('returns a transaction object containing a posting with a negative amount a

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a dash in front of the commodity');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a dash in front of the commodity'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -68,9 +76,7 @@ test('returns a transaction object containing a posting with a positive amount a

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);
t.is(
result.length,
1,
Expand Down Expand Up @@ -100,11 +106,13 @@ test('returns a transaction posting with an explicitly positive amount', (t) =>

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a plus sign');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a plus sign'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -124,11 +132,13 @@ test('returns a transaction posting with an explicitly positive amount and commo

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a plus sign and commodity');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a plus sign and commodity'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -148,11 +158,13 @@ test('returns a transaction posting with a dash and number space-delimited', (t)

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a space-delimited dash');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a space-delimited dash'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -172,11 +184,13 @@ test('returns a transaction posting with a plus and number space-delimited', (t)

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a space-delimited plus');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a space-delimited plus'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -196,9 +210,7 @@ test('returns a transaction posting with a dash and space before a commodity and

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(
t,
Expand All @@ -224,9 +236,7 @@ test('returns a transaction posting with a plus and space before a commodity and

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(
t,
Expand All @@ -252,9 +262,7 @@ test('returns a transaction posting with spaces between dash, commodity, and num

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(
t,
Expand All @@ -280,9 +288,7 @@ test('returns a transaction posting with spaces between Plus, commodity, and num

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(
t,
Expand All @@ -308,9 +314,7 @@ test('returns a transaction posting with a dash and commodity before a space and

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(
t,
Expand All @@ -336,9 +340,7 @@ test('returns a transaction posting with a plus and commodity before a space and

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(
t,
Expand All @@ -364,11 +366,13 @@ test('returns a transaction posting with a commodity and dash in reverse order',

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a commodity and dash in reverse order');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a commodity and dash in reverse order'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -388,11 +392,13 @@ test('returns a transaction posting with a commodity and plus in reverse order',

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a commodity and plus in reverse order');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a commodity and plus in reverse order'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -412,11 +418,13 @@ test('returns a transaction posting with a space-delimited commodity and dash in

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a space-delimited commodity and dash in reverse order');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a space-delimited commodity and dash in reverse order'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -436,11 +444,13 @@ test('returns a transaction posting with a space-delimited commodity and plus in

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a space-delimited commodity and plus in reverse order');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a space-delimited commodity and plus in reverse order'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -460,11 +470,13 @@ test('returns a transaction posting with a reversed order commodity and dash bef

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a reversed order commodity and dash before a space and number');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a reversed order commodity and dash before a space and number'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -484,11 +496,13 @@ test('returns a transaction posting with a reversed order commodity and plus bef

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with a reversed order commodity and plus before a space and number');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with a reversed order commodity and plus before a space and number'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -508,11 +522,13 @@ test('returns a transaction posting with spaces between reversed order commodity

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with spaces between reversed order commodity and dash, and number');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with spaces between reversed order commodity and dash, and number'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -532,11 +548,13 @@ test('returns a transaction posting with spaces between reversed order commodity

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount with spaces between reversed order commodity and plus, and number');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount with spaces between reversed order commodity and plus, and number'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand All @@ -552,15 +570,19 @@ test('returns a transaction posting with spaces between reversed order commodity
});

test('returns a transaction posting that removes unnecessary whitespace', (t) => {
const cstResult = parseLedgerToCST(`1900/01/01\n Account:Test - $ 1\n`);
const cstResult = parseLedgerToCST(
`1900/01/01\n Account:Test - $ 1\n`
);

assertNoLexingOrParsingErrors(t, cstResult);

const result = CstToRawVisitor.journal(
cstResult.cstJournal.children
);
const result = CstToRawVisitor.journal(cstResult.cstJournal.children);

assertIsValidTransactionObject(t, result, 'should modify a transaction posting amount containing multiple whitespace');
assertIsValidTransactionObject(
t,
result,
'should modify a transaction posting amount containing multiple whitespace'
);

t.deepEqual(
((result[0] as Raw.Transaction).value.contentLines[0] as Raw.Posting).value
Expand Down
Loading

0 comments on commit 280bfbf

Please sign in to comment.