-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactored lexer tests for better executability
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
1 parent
1414277
commit 6cfbf9a
Showing
12 changed files
with
1,231 additions
and
1,245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
); |
Oops, something went wrong.