/
detect-pragma.test.ts
42 lines (34 loc) · 1.16 KB
/
detect-pragma.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import type { Parser } from 'prettier';
import { parsers } from 'src/index';
import { describe, expect, it } from 'vitest';
/* eslint-disable @typescript-eslint/no-non-null-assertion */
// ts-jest needs the exclamation mark, so it does not have the impression that the variables are undefined
const pugParser: Parser = parsers!.pug!;
describe('Pragma', () => {
it('should detect pragma @prettier', () => {
const code: string = readFileSync(
resolve(__dirname, 'pragma-prettier.pug'),
'utf8',
);
const actual: boolean = pugParser.hasPragma!(code);
expect(actual).toBeTruthy();
});
it('should detect pragma @format', () => {
const code: string = readFileSync(
resolve(__dirname, 'pragma-format.pug'),
'utf8',
);
const actual: boolean = pugParser.hasPragma!(code);
expect(actual).toBeTruthy();
});
it('should detect no pragma ', () => {
const code: string = readFileSync(
resolve(__dirname, 'no-pragma.pug'),
'utf8',
);
const actual: boolean = pugParser.hasPragma!(code);
expect(actual).toBeFalsy();
});
});