Skip to content

Commit

Permalink
fix: added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Kimbrell committed Oct 5, 2023
1 parent ffbc216 commit cf3e16b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/examples/freemarker-tags/document.html
@@ -0,0 +1 @@
<#if a>
15 changes: 15 additions & 0 deletions __tests__/examples/freemarker-tags/errors.js
@@ -0,0 +1,15 @@
module.exports = [
{
"col": 1,
"evidence": "<#if a>",
"line": 1,
"message": "Conditional [<#if a>] is missing a closing tag: [</#if>]",
"raw": "<#if a>",
"rule": {
"description": "Validate Freemarker tags.",
"id": "freemarker-tags",
"link": "https://thecapsule.email/docs/codes/freemarker-tags",
},
"type": "error",
}
]
45 changes: 45 additions & 0 deletions __tests__/freemarker.spec.ts
@@ -0,0 +1,45 @@
import { parse } from '../src/parser';

test('that the following freemarker syntax will parse', () => {
expect(parse('before<#if a></#if>after')).toEqual([
'before',
'<#if a>',
'</#if>',
'after'
]);

expect(parse('<#if a>b></#if>')).toEqual([
'<#if a>',
'b>',
'</#if>'
]);

expect(parse('<#if (a>b)></#if>')).toEqual([
'<#if (a>b)>',
'</#if>'
]);

expect(parse('<#if (a>b)><#if (b>d)>inner</#if></#if>')).toEqual([
'<#if (a>b)>',
'<#if (b>d)>',
'inner',
'</#if>',
'</#if>'
]);

expect(parse('before${Recipient.unsubscribe()}after')).toEqual([
'before',
'${Recipient.unsubscribe()}',
'after'
]);

expect(parse('${foo.bar() + Recipient.unsubscribe()}')).toEqual([
'${foo.bar() + Recipient.unsubscribe()}'
]);

expect(parse('<#if a + b == c < 3 + d()>inner</#if>')).toEqual([
'<#if a + b == c < 3 + d()>',
'inner',
'</#if>'
]);
})
6 changes: 6 additions & 0 deletions __tests__/rules.spec.ts
Expand Up @@ -93,4 +93,10 @@ describe('Rule: "valid-path-format"', () => {
it('Throws errors for relative paths.', () => {
rule('valid-path-format');
});
});

describe('Rule: "freemarker-tags"', () => {
it('Throws errors for invalid freemarker tags.', () => {
rule('freemarker-tags');
});
});

0 comments on commit cf3e16b

Please sign in to comment.