-
Notifications
You must be signed in to change notification settings - Fork 8
/
dokuwiki2wikijs_test.py
140 lines (109 loc) · 6.45 KB
/
dokuwiki2wikijs_test.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import unittest
from dokuwiki2wikijs import first_heading_or_filename, convert_filename_to_unicode, convert_wrap, unwrap_sentences, convert_links
IS_INFO = "{.is-info}"
class Dokuwiki2WikijsTest(unittest.TestCase):
def test_get_title(self):
lines = ["# Title"]
self.assertEqual(first_heading_or_filename(lines, ""), "Title")
lines = ["# Title with spaces"]
self.assertEqual(first_heading_or_filename(
lines, ""), "Title with spaces")
lines = ["some other text on the first line"]
self.assertEqual(first_heading_or_filename(
lines, "Some other title"), "Some other title")
def test_convert_to_unicode(self):
self.assertEqual(convert_filename_to_unicode(
"a%C3%96bcdef"), "aÖbcdef")
self.assertEqual(convert_filename_to_unicode(
"abc%C3%B6def"), "abcödef")
self.assertEqual(convert_filename_to_unicode(
"a%C3%B6bcdef"), "aöbcdef")
def test_convert_wrap_can_pass_through(self):
lines = ["no WRAP here"]
self.assertEqual(convert_wrap(lines), ["no WRAP here"])
def test_convert_simple_wrap_on_separate_first_lines(self):
lines = ["<WRAP>", "</WRAP>"]
self.assertEqual(convert_wrap(lines), ["> ", ""])
def test_converts_info_wrap_to_is_info(self):
lines = ["<WRAP info>", "</WRAP>"]
self.assertEqual(convert_wrap(lines), ["> ", IS_INFO])
def test_convert_simple_wrap_on_separate_lines(self):
lines = ["", "<WRAP>", "</WRAP>"]
self.assertEqual(convert_wrap(lines), ["", "> ", ""])
def test_convert_simple_alert_wrap_on_separate_lines(self):
lines = ["", "<WRAP alert>", "</WRAP>"]
self.assertEqual(convert_wrap(lines), ["", "> ", "{.is-danger}"])
def test_convert_wrap_on_separate_line(self):
lines = ["<WRAP>", "two line wrap", "</WRAP>"]
self.assertEqual(convert_wrap(lines), [
"> ", "> two line wrap", ""])
def test_convert_wrap_on_one_line(self):
lines = ["<WRAP>one line wrap</WRAP>"]
self.assertEqual(convert_wrap(lines), ["> one line wrap"])
def test_unwrap_single_line(self):
lines = ["A single line."]
self.assertEqual(unwrap_sentences(lines), ["A single line."])
def test_unwrap_empty_line(self):
lines = [""]
self.assertEqual(unwrap_sentences(lines), [""])
def test_unwrap_two_sentences_on_same_line(self):
lines = ["A sentence. And another."]
self.assertEqual(unwrap_sentences(lines), [
"A sentence.", "And another."])
def test_unwrap_incomplete_sentences_to_same_line(self):
lines = ["A sentence", "which continues on the next line."]
self.assertEqual(unwrap_sentences(lines), [
"A sentence which continues on the next line."])
def test_unwrap_multiple_incomplete_sentences_to_same_line(self):
lines = ["Another sentence",
"which continues. With another on the next", "line."]
self.assertEqual(unwrap_sentences(lines), [
"Another sentence which continues.", "With another on the next line."])
def test_does_not_unwrap_if_next_line_starts_with_non_alfa(self):
lines = ["Yet another sentence",
" which continues on the next line."]
self.assertEqual(unwrap_sentences(lines), [
"Yet another sentence", " which continues on the next line."])
def test_should_wrap_network_disk_correctly(self):
lines = ["", "Notera att du behöver ha en Samba-användare och att lösenordet behöver ändras med `smbpasswd` (och som sedan synkas till ditt",
'"vanliga" Linux-användarkonto. (Se [[it:server_users|]])', '']
self.assertEqual(unwrap_sentences(lines), [
'', 'Notera att du behöver ha en Samba-användare och att lösenordet behöver ändras med `smbpasswd` (och som sedan synkas till ditt "vanliga" Linux-användarkonto.',
"(Se [[it:server_users|]])", ''])
def disabled_test_should_not_wrap_consequtive_lines_with_lists(self):
lines = ["1. a list", "1. second bullet"]
self.assertEqual(unwrap_sentences(lines),
["1. a list", "1. second bullet"])
def test_should_convert_dokuwiki_link_without_text(self):
lines = [" [[somepage|]] ", "[[somepage]] "]
self.assertEqual(convert_links(lines),
[" [somepage](/somepage) ", "[somepage](/somepage) "])
def test_should_convert_dokuwiki_link_with_text(self):
lines = [" [[somepage|text]] "]
self.assertEqual(convert_links(lines),
[" [text](/somepage) "])
def test_should_convert_dokuwiki_link_with_non_ascii_text(self):
lines = [" [[kompetens:kompetensträd:processer|Processer]] "]
self.assertEqual(convert_links(lines),
[" [Processer](/kompetens/kompetensträd/processer) "])
def test_should_convert_multiple_dokuwiki_links_on_same_line(self):
lines = [" t.ex [[kompetens:kompetensträd:processer|Processer]], [[kompetens:kompetensträd:team|Team]], [[kompetens:kompetensträd:programmering|Programmering]] eller [[kompetens:kompetensträd:projekt|Projekt]] "]
self.assertEqual(convert_links(lines),
[" t.ex [Processer](/kompetens/kompetensträd/processer), [Team](/kompetens/kompetensträd/team), [Programmering](/kompetens/kompetensträd/programmering) eller [Projekt](/kompetens/kompetensträd/projekt) "])
def test_should_convert_multiple_dokuwiki_links_with_text(self):
lines = [" [[somepage|text]] ",
"line with normal text without links ...", " [[somepage2|text2]]"]
self.assertEqual(convert_links(lines),
[" [text](/somepage) ", "line with normal text without links ...", " [text2](/somepage2)"])
def test_should_convert_media_link(self):
lines = [" {{mediafile|alttext}} ", "{{mediafile}} "]
self.assertEqual(convert_links(lines),
[" [alttext](/mediafile) ", "[mediafile](/mediafile) "])
def test_should_convert_colons_to_slash_in_link(self):
lines = ["[[:path:path:path|text]]"]
self.assertEqual(convert_links(lines),
["[text](/path/path/path)"])
def test_should_not_convert_colons_to_slash_in_http_links(self):
lines = ["[[https://some.domain|text]]"]
self.assertEqual(convert_links(lines),
["[text](https://some.domain)"])