run.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var showdown = new require('../src/showdown'),
  2. convertor = new showdown.converter(),
  3. fs = require('fs'),
  4. path = require('path'),
  5. should = require('should');
  6. // Load test cases from disk
  7. var cases = fs.readdirSync('test/cases').filter(function(file){
  8. return ~file.indexOf('.md');
  9. }).map(function(file){
  10. return file.replace('.md', '');
  11. });
  12. // Run each test case
  13. cases.forEach(function(test){
  14. var name = test.replace(/[-.]/g, ' ');
  15. it (name, function(){
  16. var mdpath = path.join('test/cases', test + '.md'),
  17. htmlpath = path.join('test/cases', test + '.html'),
  18. md = fs.readFileSync(mdpath, 'utf8'),
  19. expected = fs.readFileSync(htmlpath, 'utf8').trim(),
  20. actual = convertor.makeHtml(md).trim();
  21. // Normalize line returns
  22. expected = expected.replace(/\r/g, '');
  23. // Ignore all leading/trailing whitespace
  24. expected = expected.split('\n').map(function(x){
  25. return x.trim();
  26. }).join('\n');
  27. actual = actual.split('\n').map(function(x){
  28. return x.trim();
  29. }).join('\n');
  30. // Convert whitespace to a visible character so that it shows up on error reports
  31. expected = expected.replace(/ /g, '·');
  32. expected = expected.replace(/\n/g, '•\n');
  33. actual = actual.replace(/ /g, '·');
  34. actual = actual.replace(/\n/g, '•\n');
  35. // Compare
  36. actual.should.equal(expected);
  37. });
  38. });