Skip to content

Commit fe13943

Browse files
committed
Add tests
1 parent 112f51c commit fe13943

File tree

3 files changed

+100
-4
lines changed

3 files changed

+100
-4
lines changed

markdowntoc/markdowntoc_insert.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def get_toc_open_tag(self):
7474
return toc_open_tags
7575

7676
def get_toc_close_tag(self, start):
77-
close_tags = self.view.find_all("^<!-- /MarkdownTOC -->\n")
77+
close_tags = self.view.find_all(r'<!--[\s\n]+/MarkdownTOC[\s\n]+-->\n')
7878
close_tags = self.remove_items_in_codeblock(close_tags)
7979
for close_tag in close_tags:
8080
if start < close_tag.begin():

tests/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ def moveTo(self, pos):
3939
def getTOC_text(self):
4040
"""Find TOC in the document, and return the list texts in it."""
4141
toc_region = self.view.find(
42-
"<!-- MarkdownTOC .*-->(.|\n)+?<!-- /MarkdownTOC -->",
42+
r'<!--[\s\n]+MarkdownTOC[\s\n]+[^>]*-->\n(.|\n)+?<!--[\s\n]+/MarkdownTOC[\s\n]+-->',
4343
sublime.IGNORECASE)
4444
toc_all = self.view.substr(toc_region)
4545

4646
# pick toc contents
47-
toc_contents = re.sub(r'<!-- MarkdownTOC .* -->', '', toc_all)
48-
toc_contents = re.sub(r'<!-- /MarkdownTOC -->', '', toc_contents)
47+
toc_contents = re.sub(r'<!--[\s\n]+MarkdownTOC[\s\n]+[^>]*-->', '', toc_all)
48+
toc_contents = re.sub(r'<!--[\s\n]+/MarkdownTOC[\s\n]+-->', '', toc_contents)
4949
toc_contents = toc_contents.rstrip()
5050

5151
return toc_contents

tests/tag_variation.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# coding:utf-8
2+
from base import TestBase
3+
4+
class TagVariation(TestBase):
5+
"""Test for attributes 'style'"""
6+
7+
# for debug
8+
# def tearDown(self):
9+
# pass
10+
11+
def test_1(self):
12+
"""Tag Variation 1"""
13+
text = \
14+
"""
15+
16+
<!-- MarkdownTOC autolink="true" bracket="square" style="ordered" -->
17+
18+
<!-- /MarkdownTOC -->
19+
20+
# foo
21+
"""
22+
toc = self.init_update(text)['toc']
23+
self.assert_In('1. [foo][foo]', toc)
24+
25+
def test_2(self):
26+
"""Tag Variation 2"""
27+
text = \
28+
"""
29+
30+
<!-- MarkdownTOC
31+
autolink="true" bracket="square" style="ordered" -->
32+
33+
<!-- /MarkdownTOC -->
34+
35+
# foo
36+
"""
37+
toc = self.init_update(text)['toc']
38+
self.assert_In('1. [foo][foo]', toc)
39+
40+
def test_3(self):
41+
"""Tag Variation 3"""
42+
text = \
43+
"""
44+
45+
<!--
46+
MarkdownTOC
47+
autolink="true"
48+
bracket="square"
49+
style="ordered" -->
50+
51+
<!-- /MarkdownTOC -->
52+
53+
# foo
54+
"""
55+
toc = self.init_update(text)['toc']
56+
self.assert_In('1. [foo][foo]', toc)
57+
58+
def test_4(self):
59+
"""Tag Variation 4"""
60+
text = \
61+
"""
62+
63+
<!--
64+
MarkdownTOC
65+
autolink="true"
66+
bracket="square"
67+
style="ordered"
68+
-->
69+
70+
<!-- /MarkdownTOC -->
71+
72+
# foo
73+
"""
74+
toc = self.init_update(text)['toc']
75+
self.assert_In('1. [foo][foo]', toc)
76+
77+
def test_5(self):
78+
"""Tag Variation 5"""
79+
text = \
80+
"""
81+
82+
<!--
83+
MarkdownTOC
84+
autolink="true"
85+
bracket="square"
86+
style="ordered"
87+
-->
88+
89+
<!--
90+
/MarkdownTOC
91+
-->
92+
93+
# foo
94+
"""
95+
toc = self.init_update(text)['toc']
96+
self.assert_In('1. [foo][foo]', toc)

0 commit comments

Comments
 (0)