index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. let _ = require('lodash');
  3. let bluebird = require('bluebird');
  4. let fs = bluebird.promisifyAll(require('fs'));
  5. let glob = require('glob');
  6. let hljs = require('../../build');
  7. let path = require('path');
  8. let utility = require('../utility');
  9. function testLanguage(language) {
  10. describe(language, function() {
  11. const filePath = utility.buildPath('markup', language, '*.expect.txt'),
  12. filenames = glob.sync(filePath);
  13. _.each(filenames, function(filename) {
  14. const testName = path.basename(filename, '.expect.txt'),
  15. sourceName = filename.replace(/\.expect/, '');
  16. it(`should markup ${testName}`, function(done) {
  17. const sourceFile = fs.readFileAsync(sourceName, 'utf-8'),
  18. expectedFile = fs.readFileAsync(filename, 'utf-8');
  19. bluebird.join(sourceFile, expectedFile, function(source, expected) {
  20. const actual = hljs.highlight(language, source).value;
  21. actual.trim().should.equal(expected.trim());
  22. done();
  23. });
  24. });
  25. });
  26. });
  27. }
  28. describe('hljs.highlight()', function() {
  29. let markupPath = utility.buildPath('markup');
  30. return fs.readdirAsync(markupPath).each(testLanguage);
  31. });