Skip to content

Commit

Permalink
Add some TOC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n0rr7882 committed Jan 6, 2019
1 parent 21a00bb commit 9c70926
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Markdown-it plugin to add Wiki style Table Of Contents",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "./node_modules/mocha/bin/mocha test/*.js --reporter spec"
},
"repository": {
"type": "git",
Expand All @@ -23,7 +23,9 @@
"url": "https://github.com/n0rr7882/markdown-it-wiki-toc/issues"
},
"homepage": "https://github.com/n0rr7882/markdown-it-wiki-toc#readme",
"dependencies": {
"markdown-it": "^8.4.2"
"devDependencies": {
"markdown-it": "^8.4.2",
"markdown-it-testgen": "^0.1.4",
"mocha": "^5.2.0"
}
}
}
90 changes: 90 additions & 0 deletions test/fixtures/toc1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Test1
.
@[toc]
.
<p><div id="toc" class="toc"><h3>Table of Contents</h3></div></p>
.

Test2
.
@[toc]

# First H1

Some contents...

## First H2

Some contents...

# Second H1

## Second H2

### First H3
.
<p><div id="toc" class="toc"><h3>Table of Contents</h3><ul class="toc-level"><li><a href="#h-1">1.</a> First H1</li><ul class="toc-level"><li><a href="#h-1.1">1.1.</a> First H2</li></ul><li><a href="#h-2">2.</a> Second H1</li><ul class="toc-level"><li><a href="#h-2.1">2.1.</a> Second H2</li><ul class="toc-level"><li><a href="#h-2.1.1">2.1.1.</a> First H3</li></ul></ul></ul></div></p>
<h1><a href="#h-1" id="h-1">1.</a> First H1</h1>
<p>Some contents...</p>
<h2><a href="#h-1.1" id="h-1.1">1.1.</a> First H2</h2>
<p>Some contents...</p>
<h1><a href="#h-2" id="h-2">2.</a> Second H1</h1>
<h2><a href="#h-2.1" id="h-2.1">2.1.</a> Second H2</h2>
<h3><a href="#h-2.1.1" id="h-2.1.1">2.1.1.</a> First H3</h3>
.

Test3
.
@[toc]

First Title
===========

Some Content

SubTitle
--------

Some content

Second Title
============

### First H3
.
<p><div id="toc" class="toc"><h3>Table of Contents</h3><ul class="toc-level"><li><a href="#h-1">1.</a> First Title</li><ul class="toc-level"><li><a href="#h-1.1">1.1.</a> SubTitle</li></ul><li><a href="#h-2">2.</a> Second Title</li><ul class="toc-level"><ul class="toc-level"><li><a href="#h-2.0.1">2.0.1.</a> First H3</li></ul></ul></ul></div></p>
<h1><a href="#h-1" id="h-1">1.</a> First Title</h1>
<p>Some Content</p>
<h2><a href="#h-1.1" id="h-1.1">1.1.</a> SubTitle</h2>
<p>Some content</p>
<h1><a href="#h-2" id="h-2">2.</a> Second Title</h1>
<h3><a href="#h-2.0.1" id="h-2.0.1">2.0.1.</a> First H3</h3>
.

Test4
.
@[toc]

#### H4

### H3

## H2

# H1

## H2

### H3

#### H4
.
<p><div id="toc" class="toc"><h3>Table of Contents</h3><ul class="toc-level"><ul class="toc-level"><ul class="toc-level"><ul class="toc-level"><li><a href="#h-0.0.0.1">0.0.0.1.</a> H4</li></ul><li><a href="#h-0.0.1">0.0.1.</a> H3</li></ul><li><a href="#h-0.1">0.1.</a> H2</li></ul><li><a href="#h-1">1.</a> H1</li><ul class="toc-level"><li><a href="#h-1.1">1.1.</a> H2</li><ul class="toc-level"><li><a href="#h-1.1.1">1.1.1.</a> H3</li><ul class="toc-level"><li><a href="#h-1.1.1.1">1.1.1.1.</a> H4</li></ul></ul></ul></ul></div></p>
<h4><a href="#h-0.0.0.1" id="h-0.0.0.1">0.0.0.1.</a> H4</h4>
<h3><a href="#h-0.0.1" id="h-0.0.1">0.0.1.</a> H3</h3>
<h2><a href="#h-0.1" id="h-0.1">0.1.</a> H2</h2>
<h1><a href="#h-1" id="h-1">1.</a> H1</h1>
<h2><a href="#h-1.1" id="h-1.1">1.1.</a> H2</h2>
<h3><a href="#h-1.1.1" id="h-1.1.1">1.1.1.</a> H3</h3>
<h4><a href="#h-1.1.1.1" id="h-1.1.1.1">1.1.1.1.</a> H4</h4>
.
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var path = require('path');
var generate = require('markdown-it-testgen');
var md = require('markdown-it')({
html: true,
linkify: true,
typography: true
})
.use(require('../'));

describe('markdown-it-wiki-toc', function () {
generate(path.join(__dirname, 'fixtures/toc1.txt'), md);
});

0 comments on commit 9c70926

Please sign in to comment.