Skip to content

Commit

Permalink
test: refactored lexer tests for better executability
Browse files Browse the repository at this point in the history
Used a macro function as per Ava documentation instead of a utility function to encapsulate lexer
test implementation. This change makes it easier to run individual tests or suites to save time
during development.

closes #24
  • Loading branch information
darylwright committed Apr 20, 2024
1 parent 1414277 commit 6cfbf9a
Show file tree
Hide file tree
Showing 12 changed files with 1,231 additions and 1,245 deletions.
155 changes: 73 additions & 82 deletions src/__tests__/lexer/account_directives.test.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,77 @@
import test from 'ava';

import { runLexerTests } from './utils';
import { macro } from './utils';

const tests = [
{
pattern: 'account Assets:Chequing ',
expected: [
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'DOUBLE_WS'
],
title: 'recognize account directive and name with double-space at end'
},
{
pattern: 'account Assets:Chequing\n',
expected: [
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'NEWLINE'
],
title: 'recognize account directive and name with end of line at end'
},
{
pattern: 'account Assets:Chequing ; a comment\n',
expected: [
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'DOUBLE_WS',
'SemicolonComment',
'InlineCommentText',
'NEWLINE'
],
title: 'recognize account directive and name with comment at end'
},
{
pattern: 'account Assets:Chequing ; a comment with: a tag\n',
expected: [
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'DOUBLE_WS',
'SemicolonComment',
'InlineCommentText',
'InlineCommentTagName',
'InlineCommentTagColon',
'InlineCommentTagValue',
'NEWLINE'
],
title: 'recognize account directive and name with comment with a tag at end'
},
{
pattern: 'account Assets:Chequing\n ; a comment\n',
expected: [
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'NEWLINE',
'INDENT',
'SemicolonComment',
'InlineCommentText',
'NEWLINE'
],
title: 'recognize account directive and name with comment on the next line'
},
{
pattern: 'account (Assets:Chequing) ',
expected: [
'AccountDirective',
{ AccountName: ['(Assets', 'Chequing)'] },
'DOUBLE_WS'
],
title:
'ignore ( and treat it as part of the account name of a real account (hledger bug)'
},
{
pattern: 'account [Assets:Chequing] ',
expected: [
'AccountDirective',
{ AccountName: ['[Assets', 'Chequing]'] },
'DOUBLE_WS'
],
title:
'ignore [ and treat it as part of the account name of a real account (hledger bug)'
}
];
test(
'recognize account directive and name with double-space at end',
macro,
'account Assets:Chequing ',
['AccountDirective', { AccountName: ['Assets', 'Chequing'] }, 'DOUBLE_WS']
);

runLexerTests(test, tests);
test(
'recognize account directive and name with end of line at end',
macro,
'account Assets:Chequing\n',
['AccountDirective', { AccountName: ['Assets', 'Chequing'] }, 'NEWLINE']
);

test(
'recognize account directive and name with comment at end',
macro,
'account Assets:Chequing ; a comment\n',
[
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'DOUBLE_WS',
'SemicolonComment',
'InlineCommentText',
'NEWLINE'
]
);

test(
'recognize account directive and name with comment with a tag at end',
macro,
'account Assets:Chequing ; a comment with: a tag\n',
[
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'DOUBLE_WS',
'SemicolonComment',
'InlineCommentText',
'InlineCommentTagName',
'InlineCommentTagColon',
'InlineCommentTagValue',
'NEWLINE'
]
);

test(
'recognize account directive and name with comment on the next line',
macro,
'account Assets:Chequing\n ; a comment\n',
[
'AccountDirective',
{ AccountName: ['Assets', 'Chequing'] },
'NEWLINE',
'INDENT',
'SemicolonComment',
'InlineCommentText',
'NEWLINE'
]
);

test(
'ignore ( and treat it as part of the account name of a real account (hledger bug)',
macro,
'account (Assets:Chequing) ',
['AccountDirective', { AccountName: ['(Assets', 'Chequing)'] }, 'DOUBLE_WS']
);

test(
'ignore [ and treat it as part of the account name of a real account (hledger bug)',
macro,
'account [Assets:Chequing] ',
['AccountDirective', { AccountName: ['[Assets', 'Chequing]'] }, 'DOUBLE_WS']
);

0 comments on commit 6cfbf9a

Please sign in to comment.