Pārlūkot izejas kodu

test(converter.makeHtml): refactor test to improve readability

Estevão Soares dos Santos 10 gadi atpakaļ
vecāks
revīzija
c6b60f12fa
1 mainītis faili ar 65 papildinājumiem un 68 dzēšanām
  1. 65 68
      test/node/showdown.Converter.makeHtml.js

+ 65 - 68
test/node/Container/testMakeHtml.js → test/node/showdown.Converter.makeHtml.js

@@ -2,67 +2,20 @@
  * Created by Estevao on 15-01-2015.
  */
 
-(function () {
+describe('showdown.Converter', function () {
   'use strict';
 
   require('source-map-support').install();
   require('chai').should();
 
   var fs = require('fs'),
-      showdown = require('../../../dist/showdown.js'),
-      cases = fs.readdirSync('test/cases/')
-        .filter(filter())
-        .map(map('test/cases/')),
-      issues = fs.readdirSync('test/issues/')
-        .filter(filter())
-        .map(map('test/issues/'));
-
-  //Tests
-  describe('Converter.makeHtml() simple testcases', function () {
-    var converter = new showdown.Converter();
-    for (var i = 0; i < cases.length; ++i) {
-      if (cases[i].name === 'github-style-at-start') {
-        console.log(showdown.getOptions());
-      }
-      it(cases[i].name, assertion(cases[i], converter));
-    }
-  });
-
-  describe('Converter.makeHtml() issues testcase', function () {
-    var converter = new showdown.Converter();
-    for (var i = 0; i < issues.length; ++i) {
-      it(issues[i].name, assertion(issues[i], converter));
-    }
-  });
-
-  describe('Converter.options omitExtraWLInCodeBlocks', function () {
-    var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
-        text = 'var foo = bar;',
-        html = converter.makeHtml('    ' + text);
-    it('should omit extra line after code tag', function () {
-      var expectedHtml = '<pre><code>' + text + '</code></pre>';
-      html.should.equal(expectedHtml);
-    });
-  });
-
-  describe('Converter.options prefixHeaderId', function () {
-    var converter = new showdown.Converter(),
-        text = 'foo header';
-
-    it('should prefix header id with "section"', function () {
-      converter.setOption('prefixHeaderId', true);
-      var html = converter.makeHtml('# ' + text),
-          expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
-      html.should.equal(expectedHtml);
-    });
-
-    it('should prefix header id with custom string', function () {
-      converter.setOption('prefixHeaderId', 'blabla');
-      var html = converter.makeHtml('# ' + text),
-          expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
-      html.should.equal(expectedHtml);
-    });
-  });
+    showdown = require('../../dist/showdown.js'),
+    cases = fs.readdirSync('test/cases/')
+      .filter(filter())
+      .map(map('test/cases/')),
+    issues = fs.readdirSync('test/issues/')
+      .filter(filter())
+      .map(map('test/issues/'));
 
   function filter() {
     return function (file) {
@@ -74,10 +27,10 @@
   function map(dir) {
     return function (file) {
       var name = file.replace('.md', ''),
-          htmlPath = dir + name + '.html',
-          html = fs.readFileSync(htmlPath, 'utf8'),
-          mdPath = dir + name + '.md',
-          md = fs.readFileSync(mdPath, 'utf8');
+        htmlPath = dir + name + '.html',
+        html = fs.readFileSync(htmlPath, 'utf8'),
+        mdPath = dir + name + '.md',
+        md = fs.readFileSync(mdPath, 'utf8');
 
       return {
         name:     name,
@@ -87,6 +40,16 @@
     };
   }
 
+  function assertion(testCase, converter) {
+    return function () {
+      testCase.actual = converter.makeHtml(testCase.input);
+      testCase = normalize(testCase);
+
+      // Compare
+      testCase.actual.should.equal(testCase.expected);
+    };
+  }
+
   //Normalize input/output
   function normalize(testCase) {
 
@@ -115,13 +78,47 @@
 
   }
 
-  function assertion(testCase, converter) {
-    return function () {
-      testCase.actual = converter.makeHtml(testCase.input);
-      testCase = normalize(testCase);
+  //Tests
+  describe('makeHtml() output testcase', function () {
+    var converter = new showdown.Converter();
+    for (var i = 0; i < cases.length; ++i) {
+      it(cases[i].name, assertion(cases[i], converter));
+    }
+  });
 
-      // Compare
-      testCase.actual.should.equal(testCase.expected);
-    };
-  }
-})();
+  describe('makeHtml() issues testcase', function () {
+    var converter = new showdown.Converter();
+    for (var i = 0; i < issues.length; ++i) {
+      it(issues[i].name, assertion(issues[i], converter));
+    }
+  });
+
+  describe('makeHtml() with option omitExtraWLInCodeBlocks', function () {
+    var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
+      text = 'var foo = bar;',
+      html = converter.makeHtml('    ' + text);
+    it('should omit extra line after code tag', function () {
+      var expectedHtml = '<pre><code>' + text + '</code></pre>';
+      html.should.equal(expectedHtml);
+    });
+  });
+
+  describe('makeHtml() with option prefixHeaderId', function () {
+    var converter = new showdown.Converter(),
+      text = 'foo header';
+
+    it('should prefix header id with "section"', function () {
+      converter.setOption('prefixHeaderId', true);
+      var html = converter.makeHtml('# ' + text),
+        expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
+      html.should.equal(expectedHtml);
+    });
+
+    it('should prefix header id with custom string', function () {
+      converter.setOption('prefixHeaderId', 'blabla');
+      var html = converter.makeHtml('# ' + text),
+        expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
+      html.should.equal(expectedHtml);
+    });
+  });
+});