MCPcopy Index your code
hub / github.com/highlightjs/highlight.js / testAutoDetection

Function testAutoDetection

tools/checkAutoDetect.js:19–59  ·  view source on GitHub ↗
(language, index, languages)

Source from the content-addressed store, hash-verified

17});
18
19function testAutoDetection(language, index, languages) {
20 const languagePath = utility.buildPath('detect', language);
21 return fs.readdirSync(languagePath)
22 .map(function(example) {
23 const filename = path.join(languagePath, example);
24 return fs.readFileSync(filename, 'utf-8');
25 })
26 .forEach(function(content) {
27 const expected = language;
28 const actual = hljs.highlightAuto(content);
29 if (actual.language !== expected && actual.secondBest.language !== expected) {
30 return resultTable.push([
31 expected,
32 colors.red(actual.language),
33 actual.relevance ? actual.relevance : colors.grey('None'),
34 colors.red(actual.secondBest.language),
35 actual.secondBest.relevance ? actual.secondBest.relevance : colors.grey('None')
36 ]);
37 }
38 if (actual.language !== expected) {
39 return resultTable.push([
40 expected,
41 colors.yellow(actual.language),
42 actual.relevance ? actual.relevance : colors.grey('None'),
43 colors.yellow(actual.secondBest.language),
44 actual.secondBest.relevance ? actual.secondBest.relevance : colors.grey('None')
45 ]);
46 }
47 // equal relevance is flagged
48 if (actual.relevance === actual.secondBest.relevance) {
49 return resultTable.push([
50 expected,
51 actual.language,
52 actual.relevance ? colors.yellow(actual.relevance) : colors.grey('None'),
53 actual.secondBest.language,
54 actual.secondBest.relevance ? colors.yellow(actual.secondBest.relevance) : colors.grey('None'),
55 "Relevance match."
56 ]);
57 }
58 });
59}
60
61let languages = null;
62if (process.env.ONLY_LANGUAGES) {

Callers 1

checkAutoDetect.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…