-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_common.py
More file actions
166 lines (140 loc) · 4.93 KB
/
test_common.py
File metadata and controls
166 lines (140 loc) · 4.93 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# pylint: disable=missing-docstring,no-self-use
import arpeggio
from nose.tools import assert_raises
from SpokenCode import common
def parse(instruction, rule):
"""Parse vim instruction."""
def new_rule():
return (rule, arpeggio.EOF)
parser = arpeggio.ParserPython(new_rule, ignore_case=True)
parser.parse(instruction)
class TestSingleQuotedString(object):
def test_empty_string(self):
parse("''", common.single_quoted_string)
def test_valid_string(self):
for string in [
"'asdf'",
"""'"Hello," I said. "How are you?"'""",
r"'Say it isn\'t so.'",
r"'Say it really isn\\\'t so.'",
r"'Say it is not so.\\'",
r"'Say it \ is not so.'"]:
parse(string, common.single_quoted_string)
def test_invalid_string(self):
for string in [
"'Missing close quote",
"Missing opening quote'",
"No quotes",
"'Unescaped ' quote'",
r"\'Escaped opening quote'",
r"'Escaped final quote\'"]:
with assert_raises(arpeggio.NoMatch):
parse(string, common.single_quoted_string)
print(string)
class TestDoubleQuotedString(object):
def test_empty_string(self):
parse('""', common.double_quoted_string)
def test_valid_string(self):
for string in [
'"asdf"',
'''"'Hello,' I said. 'How are you?'"''',
r'"Say it isn\"t so."',
r'"Say it really isn\\\"t so."',
r'"Say it is not so.\\"',
r'"Say it \ is not so."']:
parse(string, common.double_quoted_string)
def test_invalid_string(self):
for string in [
'"Missing close quote',
'Missing opening quote"',
'No quotes',
'"Unescaped " quote"',
r'\"Escaped opening quote"',
r'"Escaped final quote\"']:
with assert_raises(arpeggio.NoMatch):
parse(string, common.double_quoted_string)
class TestNumbers():
def test_number_element(self):
test_cases = [
"one",
"fourteen",
"four",
"hundred",
"5"]
for test_case in test_cases:
parse(test_case, common.number_element)
def test_invalid_number_element(self):
with assert_raises(arpeggio.NoMatch):
parse("random", common.number_element)
def test_signed_integer(self):
test_cases = [
"-one",
"minus twohundred",
"two-thousand and five",
"fourteen hundred",
"386"]
for test_case in test_cases:
parse(test_case, common.signed_integer)
def test_invalid_signed_integer(self):
for test_case in [
"eleventyone",
"and four",
"14.5",
"random"]:
with assert_raises(arpeggio.NoMatch):
parse(test_case, common.signed_integer)
def test_unsigned_integer(self):
test_cases = [
"twentyfive",
"427",
"nineteen"]
for test_case in test_cases:
parse(test_case, common.unsigned_integer)
def test_invalid_unsigned_integer(self):
for test_case in [
"-five",
"eleventyone",
"and four",
"14.5",
"random"]:
with assert_raises(arpeggio.NoMatch):
parse(test_case, common.unsigned_integer)
def test_signed_float(self):
test_cases = [
"-one dot zero",
"minus twohundred point",
"dot two-thousand and five",
"fourteen hundred point two",
"twentyfive.6",
"fourtyfive dot nine",
"sixty-seven point threehundredseven4",
"386."]
for test_case in test_cases:
parse(test_case, common.signed_float)
def test_invalid_signed_float(self):
for test_case in [
"eleventyone",
"and four",
"14.7.8",
"random"]:
with assert_raises(arpeggio.NoMatch):
parse(test_case, common.signed_float)
def test_unsigned_float(self):
test_cases = [
"twentyfive.",
"427.",
"3.14",
"forty two point zero",
"point nineteen"]
for test_case in test_cases:
parse(test_case, common.unsigned_float)
def test_invalid_unsigned_float(self):
for test_case in [
"-five",
"eleventyone",
"and four",
"1,235.584",
"1,548,536.20",
"random"]:
with assert_raises(arpeggio.NoMatch):
parse(test_case, common.unsigned_float)