forked from highlightjs/highlight.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (32 loc) · 1.23 KB
/
index.js
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
'use strict';
delete require.cache[require.resolve('../../build')]
delete require.cache[require.resolve('../../build/lib/highlight')]
const fs = require('fs').promises;
const hljs = require('../../build');
hljs.debugMode(); // tests run in debug mode so errors are raised
const path = require('path');
const utility = require('../utility');
function testAutoDetection(language) {
const languagePath = utility.buildPath('detect', language);
it(`should have test for ${language}`, async () => {
const path = await fs.stat(languagePath);
return path.isDirectory().should.be.true;
});
it(`should be detected as ${language}`, async () => {
const dirs = await fs.readdir(languagePath)
const files = await Promise.all(dirs
.map(function(example) {
const filename = path.join(languagePath, example);
return fs.readFile(filename, 'utf-8');
}))
files.forEach(function(content) {
const expected = language,
actual = hljs.highlightAuto(content).language;
actual.should.equal(expected);
});
});
}
describe('hljs.highlightAuto()', () => {
const languages = hljs.listLanguages();
languages.filter(hljs.autoDetection).forEach(testAutoDetection);
});