forked from thlorenz/doctoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform-weird-headers.js
40 lines (32 loc) · 1.1 KB
/
transform-weird-headers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
/*jshint asi: true */
var test = require('tap').test
, transform = require('../lib/transform');
test('\ngiven a file with edge-case header names', function (t) {
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-weird-headers.md', 'utf8');
var headers = transform(content);
t.deepEqual(
headers.toc.split('\n')
, [ '## Table of Contents',
'',
'- [hasOwnProperty](#hasownproperty)',
'- [something else](#something-else)',
'' ]
, 'generates a correct toc when headers are weird'
)
t.end()
})
test('\nnameless table headers', function (t) {
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-nameless-table-headers.md', 'utf8');
var headers = transform(content);
t.deepEqual(
headers.toc.split('\n')
, [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*',
'',
'- [Heading One](#heading-one)',
' - [Subheading 2](#subheading-2)',
'' ]
, 'generates a correct toc when readme has nameless table headers'
)
t.end()
})