forked from SublimeText/sublime-text-docset
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_docset.py
More file actions
119 lines (97 loc) · 3.53 KB
/
test_docset.py
File metadata and controls
119 lines (97 loc) · 3.53 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import unittest
import sqlite3
from abc import ABC
from collections import defaultdict
class DocsetTestCaseBase(ABC, unittest.TestCase):
NAME = None
SQLITE_PATH_FMT = '../out/{}/Contents/Resources/docSet.dsidx'
@classmethod
def setUpClass(cls):
cls.con = sqlite3.connect(cls.SQLITE_PATH_FMT.format(cls.NAME))
cls.cur = cls.con.cursor()
@classmethod
def tearDownClass(cls):
cls.con.close()
def test_no_empty_aliases(self):
"""The docset index must not contain empty entries"""
sql = '''
SELECT *
FROM searchIndex
WHERE name = ''
'''
res = self.cur.execute(sql)
self.assertFalse(res.fetchall())
def test_no_newline_aliases(self):
"""The docset index must not contain entries with newlines in them"""
sql = '''
SELECT *
FROM searchIndex
WHERE name LIKE '%\n%'
'''
res = self.cur.execute(sql)
self.assertFalse(res.fetchall())
@unittest.skip('Not implemented')
def test_no_broken_paths(self):
"""The docset index must not contain broken paths"""
pass
def test_paths_are_autolinks(self):
"""Sanity check dashing format"""
sql = '''
SELECT *
FROM searchIndex
WHERE path NOT LIKE 'docs/%.html#autolink-%'
'''
res = self.cur.execute(sql)
self.assertFalse(res.fetchall())
def _test_a_doc_page_index(
self, path: str,
contains_strict: list[tuple[str,str]],
contains_lenient: list[tuple[str,str]] | None = None,
):
sql = f'''
SELECT type, name
FROM searchIndex
WHERE path LIKE '{path}#%'
'''
res = self.cur.execute(sql)
items = res.fetchall()
for pair in contains_lenient or []:
self.assertIn(pair, items)
lookup = defaultdict(list)
for check in contains_strict:
lookup[check[1]].append(check[0])
for pair in contains_strict:
self.assertIn(pair, items)
ds_type, ds_term = pair
lookup_result = lookup[ds_term][:]
self.assertFalse(lookup_result.remove(ds_type))
class SublimeMergeDocsetTestCase(DocsetTestCaseBase):
NAME = 'sublime-merge.docset'
class SublimeTextDocsetTestCase(DocsetTestCaseBase):
NAME = 'sublime-text.docset'
def test_git_integration(self):
contains = [
('Guide', 'Git Integration'),
('Attribute', 'Staged Modification'),
('Section', 'Diff Markers'),
('Command', 'Open Git Repository…'),
('Command', 'Sublime Merge: Folder History'),
]
self._test_a_doc_page_index('docs/git_integration.html', contains)
def test_api_reference(self):
contains = [
('Guide', 'API Reference'),
('Module', 'sublime'),
('Module', 'sublime_plugin'),
('Class', 'sublime.Window'),
('Type', 'sublime.Kind'),
('Type', 'sublime.Event'),
('Class', 'sublime_plugin.EventListener'),
('Method', 'sublime_plugin.ViewEventListener.on_activated'),
('Function', 'sublime.cache_path'),
('Attribute', 'sublime.KindId.COLOR_YELLOWISH'),
('Attribute', 'sublime.RegionFlags.DRAW_EMPTY_AS_OVERWRITE'),
]
self._test_a_doc_page_index('docs/api_reference.html', contains)
# Don't test the base class directly
del DocsetTestCaseBase