-
Notifications
You must be signed in to change notification settings - Fork 1
/
areader_test.py
107 lines (82 loc) · 3.58 KB
/
areader_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
import unittest
from areader import Database, Node
class DatabaseTests(unittest.TestCase):
def test_pseudo_tags_simple1(self):
database = Database()
node = Node(database)
node.text = "<fg back>test<fg text>"
database.nodes.append(node)
self.assertEqual(database.replace_pseudo_tags(
node.text), '<span class="fg-back">test</span>')
def test_pseudo_tags_simple2(self):
database = Database()
node = Node(database)
node.text = "<fg back><fg highlight><fg text>"
database.nodes.append(node)
self.assertEqual(database.replace_pseudo_tags(
node.text), '<span class="fg-back"></span><span class="fg-highlight"></span>')
def test_pseudo_tags_simple3(self):
database = Database()
node = Node(database)
node.text = "<fg back><fg highlight><fg text><bg shine><bg back>"
database.nodes.append(node)
self.assertEqual(database.replace_pseudo_tags(
node.text), '<span class="fg-back"></span><span class="fg-highlight"></span><span class="bg-shine"></span>')
def test_pseudo_tags_nested1(self):
database = Database()
node = Node(database)
node.text = "<fg back><bg text><fg text><bg back>"
database.nodes.append(node)
self.assertEqual(database.replace_pseudo_tags(
node.text), '<span class="fg-back"></span><span class="bg-text fg-back"></span><span class="bg-text"></span>')
def test_pseudo_tags_nested2(self):
database = Database()
node = Node(database)
node.text = "bla<fg back>test<bg text>background<fg text>test<bg back>"
database.nodes.append(node)
self.assertEqual(database.replace_pseudo_tags(
node.text), 'bla<span class="fg-back">test</span><span class="bg-text fg-back">background</span><span class="bg-text">test</span>')
def test_pseudo_tags_nested3(self):
database = Database()
node = Node(database)
node.text = "<fg back><bg text>background<fg text><bg back>"
database.nodes.append(node)
self.assertEqual(database.replace_pseudo_tags(
node.text), '<span class="fg-back"></span><span class="bg-text fg-back">background</span><span class="bg-text"></span>')
def test_find_command(self):
self.maxDiff = None
input = '''\@{b} Turns @{b}bold@{ub} on.
\@{ub} Turns @{b}bold@{ub} off.
@{" Index " beep 0}
x@{i}italic@{ui}x
x@{u}underline@{uu}x'''
output = '''@{b} Turns <b>bold</b> on.
@{ub} Turns <b>bold</b> off.
<a href="javascript:beep()"> Index </a>
x<i>italic</i>x
x<span class="u">underline</span>x'''
database = Database()
self.assertEqual(database.find_command(input), output)
# print(database.find_command(input))
def test_breakup_command_empty(self):
database = Database()
output = []
self.assertEqual(database.breakup_command(
''), output)
def test_breakup_command_simple(self):
database = Database()
output = ['test']
self.assertEqual(database.breakup_command(
'test'), output)
def test_breakup_command(self):
database = Database()
output = ['test', 'is', 'a', 'is a', 'test']
self.assertEqual(database.breakup_command(
'test "is" a "is a" test'), output)
def test_inline_commands(self):
# TODO: Add more tests
database = Database()
output = '<b>Amigaguide(R)</b>'
self.assertEqual(database.process_inline_command('amigaguide'), output)
if __name__ == '__main__':
unittest.main()