index.test.js 1017 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var fs = require('fs');
  3. var assert = require('assert');
  4. var lex = require('../');
  5. var dir = __dirname + '/cases/';
  6. fs.readdirSync(dir).forEach(function (testCase) {
  7. if (/\.pug$/.test(testCase)) {
  8. test(testCase, () => {
  9. var result = lex(fs.readFileSync(dir + testCase, 'utf8'), {filename: dir + testCase});
  10. expect(result).toMatchSnapshot();
  11. });
  12. }
  13. });
  14. var edir = __dirname + '/errors/';
  15. fs.readdirSync(edir).forEach(function (testCase) {
  16. if (/\.pug$/.test(testCase)) {
  17. test(testCase, () => {
  18. var actual;
  19. try {
  20. lex(fs.readFileSync(edir + testCase, 'utf8'), {filename: edir + testCase});
  21. throw new Error('Expected ' + testCase + ' to throw an exception.');
  22. } catch (ex) {
  23. if (!ex || !ex.code || ex.code.indexOf('PUG:') !== 0) throw ex;
  24. actual = {
  25. msg: ex.msg,
  26. code: ex.code,
  27. line: ex.line,
  28. column: ex.column
  29. };
  30. }
  31. expect(actual).toMatchSnapshot();
  32. });
  33. }
  34. });