|
1 | 1 | import test from 'ava';
|
2 | 2 |
|
3 |
| -import { runLexerTests } from './utils'; |
| 3 | +import { macro } from './utils'; |
4 | 4 |
|
5 |
| -const tests = [ |
6 |
| - { |
7 |
| - pattern: 'account Assets:Chequing ', |
8 |
| - expected: [ |
9 |
| - 'AccountDirective', |
10 |
| - { AccountName: ['Assets', 'Chequing'] }, |
11 |
| - 'DOUBLE_WS' |
12 |
| - ], |
13 |
| - title: 'recognize account directive and name with double-space at end' |
14 |
| - }, |
15 |
| - { |
16 |
| - pattern: 'account Assets:Chequing\n', |
17 |
| - expected: [ |
18 |
| - 'AccountDirective', |
19 |
| - { AccountName: ['Assets', 'Chequing'] }, |
20 |
| - 'NEWLINE' |
21 |
| - ], |
22 |
| - title: 'recognize account directive and name with end of line at end' |
23 |
| - }, |
24 |
| - { |
25 |
| - pattern: 'account Assets:Chequing ; a comment\n', |
26 |
| - expected: [ |
27 |
| - 'AccountDirective', |
28 |
| - { AccountName: ['Assets', 'Chequing'] }, |
29 |
| - 'DOUBLE_WS', |
30 |
| - 'SemicolonComment', |
31 |
| - 'InlineCommentText', |
32 |
| - 'NEWLINE' |
33 |
| - ], |
34 |
| - title: 'recognize account directive and name with comment at end' |
35 |
| - }, |
36 |
| - { |
37 |
| - pattern: 'account Assets:Chequing ; a comment with: a tag\n', |
38 |
| - expected: [ |
39 |
| - 'AccountDirective', |
40 |
| - { AccountName: ['Assets', 'Chequing'] }, |
41 |
| - 'DOUBLE_WS', |
42 |
| - 'SemicolonComment', |
43 |
| - 'InlineCommentText', |
44 |
| - 'InlineCommentTagName', |
45 |
| - 'InlineCommentTagColon', |
46 |
| - 'InlineCommentTagValue', |
47 |
| - 'NEWLINE' |
48 |
| - ], |
49 |
| - title: 'recognize account directive and name with comment with a tag at end' |
50 |
| - }, |
51 |
| - { |
52 |
| - pattern: 'account Assets:Chequing\n ; a comment\n', |
53 |
| - expected: [ |
54 |
| - 'AccountDirective', |
55 |
| - { AccountName: ['Assets', 'Chequing'] }, |
56 |
| - 'NEWLINE', |
57 |
| - 'INDENT', |
58 |
| - 'SemicolonComment', |
59 |
| - 'InlineCommentText', |
60 |
| - 'NEWLINE' |
61 |
| - ], |
62 |
| - title: 'recognize account directive and name with comment on the next line' |
63 |
| - }, |
64 |
| - { |
65 |
| - pattern: 'account (Assets:Chequing) ', |
66 |
| - expected: [ |
67 |
| - 'AccountDirective', |
68 |
| - { AccountName: ['(Assets', 'Chequing)'] }, |
69 |
| - 'DOUBLE_WS' |
70 |
| - ], |
71 |
| - title: |
72 |
| - 'ignore ( and treat it as part of the account name of a real account (hledger bug)' |
73 |
| - }, |
74 |
| - { |
75 |
| - pattern: 'account [Assets:Chequing] ', |
76 |
| - expected: [ |
77 |
| - 'AccountDirective', |
78 |
| - { AccountName: ['[Assets', 'Chequing]'] }, |
79 |
| - 'DOUBLE_WS' |
80 |
| - ], |
81 |
| - title: |
82 |
| - 'ignore [ and treat it as part of the account name of a real account (hledger bug)' |
83 |
| - } |
84 |
| -]; |
| 5 | +test( |
| 6 | + 'recognize account directive and name with double-space at end', |
| 7 | + macro, |
| 8 | + 'account Assets:Chequing ', |
| 9 | + ['AccountDirective', { AccountName: ['Assets', 'Chequing'] }, 'DOUBLE_WS'] |
| 10 | +); |
85 | 11 |
|
86 |
| -runLexerTests(test, tests); |
| 12 | +test( |
| 13 | + 'recognize account directive and name with end of line at end', |
| 14 | + macro, |
| 15 | + 'account Assets:Chequing\n', |
| 16 | + ['AccountDirective', { AccountName: ['Assets', 'Chequing'] }, 'NEWLINE'] |
| 17 | +); |
| 18 | + |
| 19 | +test( |
| 20 | + 'recognize account directive and name with comment at end', |
| 21 | + macro, |
| 22 | + 'account Assets:Chequing ; a comment\n', |
| 23 | + [ |
| 24 | + 'AccountDirective', |
| 25 | + { AccountName: ['Assets', 'Chequing'] }, |
| 26 | + 'DOUBLE_WS', |
| 27 | + 'SemicolonComment', |
| 28 | + 'InlineCommentText', |
| 29 | + 'NEWLINE' |
| 30 | + ] |
| 31 | +); |
| 32 | + |
| 33 | +test( |
| 34 | + 'recognize account directive and name with comment with a tag at end', |
| 35 | + macro, |
| 36 | + 'account Assets:Chequing ; a comment with: a tag\n', |
| 37 | + [ |
| 38 | + 'AccountDirective', |
| 39 | + { AccountName: ['Assets', 'Chequing'] }, |
| 40 | + 'DOUBLE_WS', |
| 41 | + 'SemicolonComment', |
| 42 | + 'InlineCommentText', |
| 43 | + 'InlineCommentTagName', |
| 44 | + 'InlineCommentTagColon', |
| 45 | + 'InlineCommentTagValue', |
| 46 | + 'NEWLINE' |
| 47 | + ] |
| 48 | +); |
| 49 | + |
| 50 | +test( |
| 51 | + 'recognize account directive and name with comment on the next line', |
| 52 | + macro, |
| 53 | + 'account Assets:Chequing\n ; a comment\n', |
| 54 | + [ |
| 55 | + 'AccountDirective', |
| 56 | + { AccountName: ['Assets', 'Chequing'] }, |
| 57 | + 'NEWLINE', |
| 58 | + 'INDENT', |
| 59 | + 'SemicolonComment', |
| 60 | + 'InlineCommentText', |
| 61 | + 'NEWLINE' |
| 62 | + ] |
| 63 | +); |
| 64 | + |
| 65 | +test( |
| 66 | + 'ignore ( and treat it as part of the account name of a real account (hledger bug)', |
| 67 | + macro, |
| 68 | + 'account (Assets:Chequing) ', |
| 69 | + ['AccountDirective', { AccountName: ['(Assets', 'Chequing)'] }, 'DOUBLE_WS'] |
| 70 | +); |
| 71 | + |
| 72 | +test( |
| 73 | + 'ignore [ and treat it as part of the account name of a real account (hledger bug)', |
| 74 | + macro, |
| 75 | + 'account [Assets:Chequing] ', |
| 76 | + ['AccountDirective', { AccountName: ['[Assets', 'Chequing]'] }, 'DOUBLE_WS'] |
| 77 | +); |
0 commit comments