index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. let bluebird = require('bluebird');
  3. let fs = bluebird.promisifyAll(require('fs'));
  4. let hljs = require('../../build');
  5. let path = require('path');
  6. let utility = require('../utility');
  7. function testAutoDetection(language) {
  8. const languagePath = utility.buildPath('detect', language);
  9. it(`should have test for ${language}`, function() {
  10. return fs.statAsync(languagePath)
  11. .then(path => path.isDirectory().should.be.true);
  12. });
  13. it(`should be detected as ${language}`, function() {
  14. return fs.readdirAsync(languagePath)
  15. .map(function(example) {
  16. const filename = path.join(languagePath, example);
  17. return fs.readFileAsync(filename, 'utf-8');
  18. })
  19. .each(function(content) {
  20. const expected = language,
  21. actual = hljs.highlightAuto(content).language;
  22. actual.should.equal(expected);
  23. });
  24. });
  25. }
  26. describe('hljs.highlightAuto()', function() {
  27. const languages = hljs.listLanguages();
  28. languages.forEach(testAutoDetection);
  29. });