Skip to content

Commit

Permalink
Recovering TestDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
naokazuterada committed Sep 24, 2017
1 parent 8bbcd19 commit 7f2f71f
Showing 1 changed file with 288 additions and 0 deletions.
288 changes: 288 additions & 0 deletions tests/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
# coding:utf-8
from base import TestBase

class TestDefault(TestBase):
"""Default tests"""

# for debug
# def tearDown(self):
# pass

insert_position_text = \
"""
# Heading 0
# Heading 1
...
## Heading 2
...
## Heading 3
...
# Heading with anchor [with-anchor]
...
"""
def test_before_than_TOC_should_be_ignored(self):
toc_txt = self.commonSetup(self.insert_position_text, 13)
self.assert_NotIn('Heading 0', toc_txt)

def test_after_than_TOC_should_be_included(self):
toc_txt = self.commonSetup(self.insert_position_text, 13)
self.assert_In('Heading 1', toc_txt)
self.assert_In('Heading 2', toc_txt)
self.assert_In('Heading 3', toc_txt)
self.assert_In('Heading with anchor', toc_txt)

def test_ignore_inside_codeblock(self):
text = \
"""
# Outside1
```
# Inseide
```
# Outside2
```
# Inseide2
# Inseide3
```
"""
toc_txt = self.commonSetup(text)
self.assert_In('Outside1', toc_txt)
self.assert_In('Outside2', toc_txt)
self.assert_NotIn('Inside1', toc_txt)
self.assert_NotIn('Inside2', toc_txt)
self.assert_NotIn('Inside3', toc_txt)

def test_escape_link(self):
text = \
"""
# This [link](http://sample.com/) is cool
"""
toc_txt = self.commonSetup(text)
self.assert_In('This link is cool', toc_txt)

def test_escape_brackets(self):
"""Broken reference when header has square brackets
https://github.com/naokazuterada/MarkdownTOC/issues/57
"""
text = \
"""
# function(foo[, bar])
"""
toc_txt = self.commonSetup(text)
self.assert_In('function\(foo\[, bar\]\)', toc_txt)

def test_spaces_in_atx_heading(self):
text = \
"""
#Heading 0
# Heading 1
"""
toc_txt = self.commonSetup(text)
self.assert_In('- Heading 0', toc_txt)
self.assert_In('- Heading 1', toc_txt)

def test_remove_atx_closing_seq(self):
""" Remove closing sequence of # characters"""
text = \
"""
# Heading 0 #
## Heading 1 ###
# Heading 2 ##########
## Heading 3
"""
toc_txt = self.commonSetup(text)
self.assert_In('Heading 0\n', toc_txt)
self.assert_In('Heading 1\n', toc_txt)
self.assert_In('Heading 2\n', toc_txt)

def test_id_replacement(self):
""" Reoplace chars(or string) in id_replacements object in id string"""
text = \
"""
<!-- MarkdownTOC autolink=true -->
<!-- /MarkdownTOC -->
# Heading ! 0
# Heading # 1
# Heading !! 2
# Heading &and&and& 3
# &lt;element1>
# &#60;element2>
"""
toc_txt = self.commonSetup(text)
self.assert_In('- [Heading ! 0][heading--0]', toc_txt)
self.assert_In('- [Heading # 1][heading--1]', toc_txt)
self.assert_In('- [Heading !! 2][heading--2]', toc_txt)
self.assert_In('- [Heading &and&and& 3][heading-andand-3]', toc_txt)
self.assert_In('- [&lt;element1>][element1]', toc_txt)
self.assert_In('- [&#60;element2>][element2]', toc_txt)


def test_no_escape_in_code(self):
""" No escape in codeblock"""
text = \
"""
<!-- MarkdownTOC -->
<!-- /MarkdownTOC -->
# `function(param, [optional])`
# (a static function) `greet([name])` (original, right?)
# `add(keys, command[, args][, context])`
# `get_context(key[, operator][, operand][, match_all])`
"""
toc_txt = self.commonSetup(text)
self.assert_In('- `function(param, [optional])`', toc_txt)
self.assert_In('- \\(a static function\\) `greet([name])` \\(original, right?\\)', toc_txt)
self.assert_In('- `add(keys, command[, args][, context])`', toc_txt)
self.assert_In('- `get_context(key[, operator][, operand][, match_all])`', toc_txt)

def test_no_escape_in_code_with_link(self):
""" No escape in codeblock (with link)"""
text = \
"""
<!-- MarkdownTOC autolink=true -->
<!-- /MarkdownTOC -->
# `function(param, [optional])`
# (a static function) `greet([name])` (original, right?)
# `add(keys, command[, args][, context])`
# `get_context(key[, operator][, operand][, match_all])`
"""
toc_txt = self.commonSetup(text)
self.assert_In('- [`function(param, [optional])`][functionparam-optional]', toc_txt)
self.assert_In('- [\\(a static function\\) `greet([name])` \\(original, right?\\)][a-static-function-greetname-original-right]', toc_txt)
self.assert_In('- [`add(keys, command[, args][, context])`][addkeys-command-args-context]', toc_txt)
self.assert_In('- [`get_context(key[, operator][, operand][, match_all])`][getcontextkey-operator-operand-matchall]', toc_txt)

def test_no_headings(self):
""" No headings there"""
text = \
"""
<!-- MarkdownTOC autolink=true -->
<!-- /MarkdownTOC -->
# `function(param, [optional])`
# (a static function) `greet([name])` (original, right?)
# `add(keys, command[, args][, context])`
# `get_context(key[, operator][, operand][, match_all])`
"""
toc_txt = self.commonSetup(text)
self.assert_NotIn('^- ', toc_txt)

def test_uniquify_id(self):
""" uniquify id if there are same text headings"""
text = \
"""
<!-- MarkdownTOC autolink=true -->
<!-- /MarkdownTOC -->
# Heading
# Heading
# Heading
"""
toc_txt = self.commonSetup(text)
self.assert_In('- [Heading][heading]', toc_txt)
self.assert_In('- [Heading][heading-1]', toc_txt)
self.assert_In('- [Heading][heading-2]', toc_txt)

def test_uniquify_id(self):
""" handle = or - headings"""
text = \
"""
<!-- MarkdownTOC autolink=true indent=" " -->
<!-- /MarkdownTOC -->
Heading 1
=======
Heading 2
-------
"""
toc_txt = self.commonSetup(text)
self.assert_In('- [Heading 1][heading-1]', toc_txt)
self.assert_In(' - [Heading 2][heading-2]', toc_txt)

def test_whitespace_in_begining(self):
"""Ignore images in heading"""
text = \
"""
<!-- MarkdownTOC -->
<!-- /MarkdownTOC -->
# Heading
# Heading
# Heading
"""
toc_txt = self.commonSetup(text)
self.assert_In('- Heading', toc_txt)
self.assert_NotIn('- Heading', toc_txt)
self.assert_NotIn('- Heading', toc_txt)

def test_image_in_heading(self):
"""Ignore images in heading"""
text = \
"""
<!-- MarkdownTOC -->
<!-- /MarkdownTOC -->
# ![icon](images/icon.png) Heading
# Image in ![icon](images/icon.png)sentence
"""
toc_txt = self.commonSetup(text)
self.assert_In('- Heading', toc_txt)
self.assert_In('- Image in sentence', toc_txt)

0 comments on commit 7f2f71f

Please sign in to comment.