My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /src/lepl/regexp/_test/unicode.py
6528097caf75 vs. cd38df9517bf Compare: vs.  Format:
Revision cd38df9517bf
Go to: 
Project members, sign in to write a code review
/src/lepl/regexp/_test/unicode.py   6528097caf75 /src/lepl/regexp/_test/unicode.py   cd38df9517bf
1 from lepl.stream.simple import StringHelper
1 2
2 # The contents of this file are subject to the Mozilla Public License 3 # The contents of this file are subject to the Mozilla Public License
3 # (MPL) Version 1.1 (the "License"); you may not use this file except 4 # (MPL) Version 1.1 (the "License"); you may not use this file except
4 # in compliance with the License. You may obtain a copy of the License 5 # in compliance with the License. You may obtain a copy of the License
5 # at http://www.mozilla.org/MPL/ 6 # at http://www.mozilla.org/MPL/
6 # 7 #
7 # Software distributed under the License is distributed on an "AS IS" 8 # Software distributed under the License is distributed on an "AS IS"
8 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 9 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 # the License for the specific language governing rights and 10 # the License for the specific language governing rights and
10 # limitations under the License. 11 # limitations under the License.
11 # 12 #
12 # The Original Code is LEPL (http://www.acooke.org/lepl) 13 # The Original Code is LEPL (http://www.acooke.org/lepl)
13 # The Initial Developer of the Original Code is Andrew Cooke. 14 # The Initial Developer of the Original Code is Andrew Cooke.
14 # Portions created by the Initial Developer are Copyright (C) 2009-2010 15 # Portions created by the Initial Developer are Copyright (C) 2009-2010
15 # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 16 # Andrew Cooke (andrew@acooke.org). All Rights Reserved.
16 # 17 #
17 # Alternatively, the contents of this file may be used under the terms 18 # Alternatively, the contents of this file may be used under the terms
18 # of the LGPL license (the GNU Lesser General Public License, 19 # of the LGPL license (the GNU Lesser General Public License,
19 # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 20 # http://www.gnu.org/licenses/lgpl.html), in which case the provisions
20 # of the LGPL License are applicable instead of those above. 21 # of the LGPL License are applicable instead of those above.
21 # 22 #
22 # If you wish to allow use of your version of this file only under the 23 # If you wish to allow use of your version of this file only under the
23 # terms of the LGPL License and not to allow others to use your version 24 # terms of the LGPL License and not to allow others to use your version
24 # of this file under the MPL, indicate your decision by deleting the 25 # of this file under the MPL, indicate your decision by deleting the
25 # provisions above and replace them with the notice and other provisions 26 # provisions above and replace them with the notice and other provisions
26 # required by the LGPL License. If you do not delete the provisions 27 # required by the LGPL License. If you do not delete the provisions
27 # above, a recipient may use your version of this file under either the 28 # above, a recipient may use your version of this file under either the
28 # MPL or the LGPL License. 29 # MPL or the LGPL License.
29 30
30 ''' 31 '''
31 Tests for the lepl.regexp.unicode module. 32 Tests for the lepl.regexp.unicode module.
32 ''' 33 '''
33 34
34 from unittest import TestCase 35 from unittest import TestCase
35 36
36 #from logging import basicConfig, DEBUG 37 #from logging import basicConfig, DEBUG
37 from lepl import RegexpError, DEFAULT_STREAM_FACTORY 38 from lepl import RegexpError, DEFAULT_STREAM_FACTORY
38 from lepl.regexp.core import NfaGraph, NfaToDfa, Compiler 39 from lepl.regexp.core import NfaGraph, NfaToDfa, Compiler
39 from lepl.regexp.unicode import UnicodeAlphabet 40 from lepl.regexp.unicode import UnicodeAlphabet
40 from lepl.support.lib import format 41 from lepl.support.lib import format
41 42
42 # pylint: disable-msg=C0103, C0111, C0301, R0201, R0904 43 # pylint: disable-msg=C0103, C0111, C0301, R0201, R0904
43 # (dude this is just a test) 44 # (dude this is just a test)
44 45
45 46
46 UNICODE = UnicodeAlphabet.instance() 47 UNICODE = UnicodeAlphabet.instance()
47 48
48 49
49 def _test_parser(regexp): 50 def _test_parser(regexp):
50 return Compiler.single(UNICODE, regexp, 'label') 51 return Compiler.single(UNICODE, regexp, 'label')
51 52
52 def label(text): 53 def label(text):
53 return format('(?P<label>{0!s})', text) 54 return format('(?P<label>{0!s})', text)
54 55
55 class CharactersTest(TestCase): 56 class CharactersTest(TestCase):
56 57
57 def test_unicode_dot(self): 58 def test_unicode_dot(self):
58 #basicConfig(level=DEBUG) 59 #basicConfig(level=DEBUG)
59 c = _test_parser('.') 60 c = _test_parser('.')
60 assert label('.') == str(c), str(c) 61 assert label('.') == str(c), str(c)
61 c = _test_parser('.\\.') 62 c = _test_parser('.\\.')
62 assert label('.\\.') == str(c), str(c) 63 assert label('.\\.') == str(c), str(c)
63 64
64 def test_brackets(self): 65 def test_brackets(self):
65 #basicConfig(level=DEBUG) 66 #basicConfig(level=DEBUG)
66 c = _test_parser('a') 67 c = _test_parser('a')
67 assert label('a') == str(c), str(c) 68 assert label('a') == str(c), str(c)
68 c = _test_parser('[ac]') 69 c = _test_parser('[ac]')
69 assert label('[ac]') == str(c), str(c) 70 assert label('[ac]') == str(c), str(c)
70 c = _test_parser('[a-c]') 71 c = _test_parser('[a-c]')
71 assert label('[a-c]') == str(c), str(c) 72 assert label('[a-c]') == str(c), str(c)
72 c = _test_parser('[a-cp-q]') 73 c = _test_parser('[a-cp-q]')
73 assert label('[a-cp-q]') == str(c), str(c) 74 assert label('[a-cp-q]') == str(c), str(c)
74 c = _test_parser(r'\\') 75 c = _test_parser(r'\\')
75 assert label(r'\\') == str(c), str(c) 76 assert label(r'\\') == str(c), str(c)
76 c = _test_parser(r'\-') 77 c = _test_parser(r'\-')
77 assert label(r'\-') == str(c), str(c) 78 assert label(r'\-') == str(c), str(c)
78 c = _test_parser(r'[\\-x]') 79 c = _test_parser(r'[\\-x]')
79 assert label(r'[\\-x]') == str(c), str(c) 80 assert label(r'[\\-x]') == str(c), str(c)
80 c = _test_parser('[a-bq,]') 81 c = _test_parser('[a-bq,]')
81 assert label('[,a-bq]') == str(c), str(c) 82 assert label('[,a-bq]') == str(c), str(c)
82 c = _test_parser('[a-b,q]') 83 c = _test_parser('[a-b,q]')
83 assert label('[,a-bq]') == str(c), str(c) 84 assert label('[,a-bq]') == str(c), str(c)
84 c = _test_parser('[,a-bq]') 85 c = _test_parser('[,a-bq]')
85 assert label('[,a-bq]') == str(c), str(c) 86 assert label('[,a-bq]') == str(c), str(c)
86 c = _test_parser('[^a]') 87 c = _test_parser('[^a]')
87 assert r'(?P<label>[\x00-`b-\uffff])' == str(c), str(c) 88 assert r'(?P<label>[\x00-`b-\uffff])' == str(c), str(c)
88 89
89 def test_merge(self): 90 def test_merge(self):
90 c = _test_parser('[a-ce-g]') 91 c = _test_parser('[a-ce-g]')
91 assert label('[a-ce-g]') == str(c), str(c) 92 assert label('[a-ce-g]') == str(c), str(c)
92 c = _test_parser('[a-cd-f]') 93 c = _test_parser('[a-cd-f]')
93 assert label('[a-f]') == str(c), str(c) 94 assert label('[a-f]') == str(c), str(c)
94 c = _test_parser('[a-cc-e]') 95 c = _test_parser('[a-cc-e]')
95 assert label('[a-e]') == str(c), str(c) 96 assert label('[a-e]') == str(c), str(c)
96 c = _test_parser('[a-cb-d]') 97 c = _test_parser('[a-cb-d]')
97 assert label('[a-d]') == str(c), str(c) 98 assert label('[a-d]') == str(c), str(c)
98 c = _test_parser('[a-ca-c]') 99 c = _test_parser('[a-ca-c]')
99 assert label('[a-c]') == str(c), str(c) 100 assert label('[a-c]') == str(c), str(c)
100 c = _test_parser('[a-a]') 101 c = _test_parser('[a-a]')
101 assert label('a') == str(c), str(c) 102 assert label('a') == str(c), str(c)
102 c = _test_parser('[e-ga-c]') 103 c = _test_parser('[e-ga-c]')
103 assert label('[a-ce-g]') == str(c), str(c) 104 assert label('[a-ce-g]') == str(c), str(c)
104 c = _test_parser('[d-fa-c]') 105 c = _test_parser('[d-fa-c]')
105 assert label('[a-f]') == str(c), str(c) 106 assert label('[a-f]') == str(c), str(c)
106 c = _test_parser('[c-ea-c]') 107 c = _test_parser('[c-ea-c]')
107 assert label('[a-e]') == str(c), str(c) 108 assert label('[a-e]') == str(c), str(c)
108 c = _test_parser('[b-da-c]') 109 c = _test_parser('[b-da-c]')
109 assert label('[a-d]') == str(c), str(c) 110 assert label('[a-d]') == str(c), str(c)
110 c = _test_parser('[a-gc-e]') 111 c = _test_parser('[a-gc-e]')
111 assert label('[a-g]') == str(c), str(c) 112 assert label('[a-g]') == str(c), str(c)
112 c = _test_parser('[c-ea-g]') 113 c = _test_parser('[c-ea-g]')
113 assert label('[a-g]') == str(c), str(c) 114 assert label('[a-g]') == str(c), str(c)
114 c = _test_parser('[a-eg]') 115 c = _test_parser('[a-eg]')
115 assert label('[a-eg]') == str(c), str(c) 116 assert label('[a-eg]') == str(c), str(c)
116 c = _test_parser('[ga-e]') 117 c = _test_parser('[ga-e]')
117 assert label('[a-eg]') == str(c), str(c) 118 assert label('[a-eg]') == str(c), str(c)
118 119
119 def test_star(self): 120 def test_star(self):
120 c = _test_parser('a*') 121 c = _test_parser('a*')
121 assert label('a*') == str(c), str(c) 122 assert label('a*') == str(c), str(c)
122 c = _test_parser('a(?:bc)*d') 123 c = _test_parser('a(?:bc)*d')
123 assert label('a(?:bc)*d') == str(c), str(c) 124 assert label('a(?:bc)*d') == str(c), str(c)
124 c = _test_parser('a(?:bc)*d[e-g]*') 125 c = _test_parser('a(?:bc)*d[e-g]*')
125 assert label('a(?:bc)*d[e-g]*') == str(c), str(c) 126 assert label('a(?:bc)*d[e-g]*') == str(c), str(c)
126 c = _test_parser('a[a-cx]*') 127 c = _test_parser('a[a-cx]*')
127 assert label('a[a-cx]*') == str(c), str(c) 128 assert label('a[a-cx]*') == str(c), str(c)
128 129
129 def test_option(self): 130 def test_option(self):
130 c = _test_parser('a?') 131 c = _test_parser('a?')
131 assert label('a?') == str(c), str(c) 132 assert label('a?') == str(c), str(c)
132 c = _test_parser('a(?:bc)?d') 133 c = _test_parser('a(?:bc)?d')
133 assert label('a(?:bc)?d') == str(c), str(c) 134 assert label('a(?:bc)?d') == str(c), str(c)
134 c = _test_parser('a(?:bc)?d[e-g]?') 135 c = _test_parser('a(?:bc)?d[e-g]?')
135 assert label('a(?:bc)?d[e-g]?') == str(c), str(c) 136 assert label('a(?:bc)?d[e-g]?') == str(c), str(c)
136 c = _test_parser('ab?c') 137 c = _test_parser('ab?c')
137 assert label('ab?c') == str(c), str(c) 138 assert label('ab?c') == str(c), str(c)
138 139
139 def test_choice(self): 140 def test_choice(self):
140 #basicConfig(level=DEBUG) 141 #basicConfig(level=DEBUG)
141 c = _test_parser('(?:a*|b|[c-d])') 142 c = _test_parser('(?:a*|b|[c-d])')
142 assert label('(?:a*|b|[c-d])') == str(c), str(c) 143 assert label('(?:a*|b|[c-d])') == str(c), str(c)
143 c = _test_parser('a(?:a|b)*') 144 c = _test_parser('a(?:a|b)*')
144 assert label('a(?:a|b)*') == str(c), str(c) 145 assert label('a(?:a|b)*') == str(c), str(c)
145 c = _test_parser('a(?:[a-c]x|axb)*') 146 c = _test_parser('a(?:[a-c]x|axb)*')
146 assert label('a(?:[a-c]x|axb)*') == str(c), str(c) 147 assert label('a(?:[a-c]x|axb)*') == str(c), str(c)
147 148
148 def test_bad_escape(self): 149 def test_bad_escape(self):
149 #basicConfig(level=DEBUG) 150 #basicConfig(level=DEBUG)
150 c = _test_parser(r'\+') 151 c = _test_parser(r'\+')
151 assert label('\\+') == str(c), str(c) 152 assert label('\\+') == str(c), str(c)
152 try: 153 try:
153 c = _test_parser('+') 154 c = _test_parser('+')
154 assert False, 'Expected error' 155 assert False, 'Expected error'
155 except RegexpError: 156 except RegexpError:
156 pass 157 pass
157 158
158 def test_bad_group(self): 159 def test_bad_group(self):
159 #basicConfig(level=DEBUG) 160 #basicConfig(level=DEBUG)
160 try: 161 try:
161 _test_parser('(a)') 162 _test_parser('(a)')
162 assert False, 'Expected error' 163 assert False, 'Expected error'
163 except SyntaxError as e: 164 except SyntaxError as e:
164 assert 'do not currently support matched groups' in str(e), e 165 assert 'do not currently support matched groups' in str(e), e
165 166
166 def test_escape(self): 167 def test_escape(self):
167 c = _test_parser('\\x40') 168 c = _test_parser('\\x40')
168 assert label('@') == str(c), str(c) 169 assert label('@') == str(c), str(c)
169 c = _test_parser('\\u0040') 170 c = _test_parser('\\u0040')
170 assert label('@') == str(c), str(c) 171 assert label('@') == str(c), str(c)
171 c = _test_parser('\\U00000040') 172 c = _test_parser('\\U00000040')
172 assert label('@') == str(c), str(c) 173 assert label('@') == str(c), str(c)
173 174
174 175
175 class NfaTest(TestCase): 176 class NfaTest(TestCase):
176 177
177 def assert_matches(self, pattern, text, results): 178 def assert_matches(self, pattern, text, results):
178 r = _test_parser(pattern) 179 r = _test_parser(pattern)
179 m = r.nfa().match 180 m = r.nfa().match
180 s = list(m(DEFAULT_STREAM_FACTORY.from_string(text))) 181 s = list(m(DEFAULT_STREAM_FACTORY.from_string(text)))
181 assert len(s) == len(results), s 182 assert len(s) == len(results), s
182 for (a, b) in zip(s, results): 183 for (a, b) in zip(s, results):
183 assert a[1] == b, a[1] + ' != ' + b 184 assert a[1] == b, a[1] + ' != ' + b
184 185
185 def test_simple(self): 186 def test_simple(self):
186 #basicConfig(level=DEBUG) 187 #basicConfig(level=DEBUG)
187 self.assert_matches('ab', 'abc', ['ab']) 188 self.assert_matches('ab', 'abc', ['ab'])
188 189
189 def test_star(self): 190 def test_star(self):
190 self.assert_matches('a*b', 'aaabc', ['aaab']) 191 self.assert_matches('a*b', 'aaabc', ['aaab'])
191 192
192 def test_plus(self): 193 def test_plus(self):
193 self.assert_matches('[a-z]+', 'abc', ['abc', 'ab', 'a']) 194 self.assert_matches('[a-z]+', 'abc', ['abc', 'ab', 'a'])
194 195
195 def test_choice(self): 196 def test_choice(self):
196 self.assert_matches('(?:a|b)', 'ac', ['a']) 197 self.assert_matches('(?:a|b)', 'ac', ['a'])
197 198
198 def test_star_choice(self): 199 def test_star_choice(self):
199 self.assert_matches('(?:a|b)*', 'aababbac', 200 self.assert_matches('(?:a|b)*', 'aababbac',
200 ['aababba', 'aababb', 'aabab', 'aaba', 'aab', 'aa', 'a', '']) 201 ['aababba', 'aababb', 'aabab', 'aaba', 'aab', 'aa', 'a', ''])
201 202
202 def test_multiple_choice(self): 203 def test_multiple_choice(self):
203 #basicConfig(level=DEBUG) 204 #basicConfig(level=DEBUG)
204 self.assert_matches('(?:a|ab)b', 'abb', ['ab', 'abb']) 205 self.assert_matches('(?:a|ab)b', 'abb', ['ab', 'abb'])
205 206
206 def test_range(self): 207 def test_range(self):
207 self.assert_matches('[abc]*', 'bbcx', ['bbc', 'bb', 'b', '']) 208 self.assert_matches('[abc]*', 'bbcx', ['bbc', 'bb', 'b', ''])
208 self.assert_matches('[A-Z][a-z]*', 'Abc', ['Abc', 'Ab', 'A']) 209 self.assert_matches('[A-Z][a-z]*', 'Abc', ['Abc', 'Ab', 'A'])
209 210
210 def test_range_overlap(self): 211 def test_range_overlap(self):
211 ''' 212 '''
212 Matches with 'b' are duplicated, since it appears in both ranges. 213 Matches with 'b' are duplicated, since it appears in both ranges.
213 ''' 214 '''
214 self.assert_matches('(?:[ab]|[bc])*', 'abc', 215 self.assert_matches('(?:[ab]|[bc])*', 'abc',
215 ['abc', 'ab', 'abc', 'ab', 'a', '']) 216 ['abc', 'ab', 'abc', 'ab', 'a', ''])
216 217
217 def test_complex(self): 218 def test_complex(self):
218 #basicConfig(level=DEBUG) 219 #basicConfig(level=DEBUG)
219 self.assert_matches('a(?:[x-z]|a(?:g|b))*(?:u|v)p', 220 self.assert_matches('a(?:[x-z]|a(?:g|b))*(?:u|v)p',
220 'ayagxabvp', ['ayagxabvp']) 221 'ayagxabvp', ['ayagxabvp'])
221 222
222 223
223 class DfaGraphTest(TestCase): 224 class DfaGraphTest(TestCase):
224 225
225 def assert_dfa_graph(self, regexp, desc): 226 def assert_dfa_graph(self, regexp, desc):
226 r = _test_parser(regexp) 227 r = _test_parser(regexp)
227 nfa = NfaGraph(UNICODE) 228 nfa = NfaGraph(UNICODE)
228 r.expression.build(nfa, nfa.new_node(), nfa.new_node()) 229 r.expression.build(nfa, nfa.new_node(), nfa.new_node())
229 dfa = NfaToDfa(nfa, UNICODE).dfa 230 dfa = NfaToDfa(nfa, UNICODE).dfa
230 assert str(dfa) == desc, str(dfa) 231 assert str(dfa) == desc, str(dfa)
231 232
232 def test_dfa_no_empty(self): 233 def test_dfa_no_empty(self):
233 self.assert_dfa_graph('abc', 234 self.assert_dfa_graph('abc',
234 '0: [0] a->1; 1: [3] b->2; 2: [4] c->3; 3(label): [1, 2]') 235 '0: [0] a->1; 1: [3] b->2; 2: [4] c->3; 3(label): [1, 2]')
235 236
236 def test_dfa_simple_repeat(self): 237 def test_dfa_simple_repeat(self):
237 self.assert_dfa_graph('ab*c', 238 self.assert_dfa_graph('ab*c',
238 '0: [0] a->1; 1: [3, 4, 5] c->2,b->3; 2(label): [1, 2]; 3: [4, 5] c->2,b->3') 239 '0: [0] a->1; 1: [3, 4, 5] c->2,b->3; 2(label): [1, 2]; 3: [4, 5] c->2,b->3')
239 240
240 def test_dfa_simple_choice(self): 241 def test_dfa_simple_choice(self):
241 self.assert_dfa_graph('a(?:b|c)', 242 self.assert_dfa_graph('a(?:b|c)',
242 '0: [0] a->1; 1: [3, 4] [b-c]->2; 2(label): [1, 2]') 243 '0: [0] a->1; 1: [3, 4] [b-c]->2; 2(label): [1, 2]')
243 244
244 def test_dfa_repeated_choice(self): 245 def test_dfa_repeated_choice(self):
245 self.assert_dfa_graph('a(?:b|cd)*e', 246 self.assert_dfa_graph('a(?:b|cd)*e',
246 '0: [0] a->1; 1: [3, 4, 5, 6] e->2,c->3,b->4; 2(label): [1, 2]; 3: [7] d->4; 4: [4, 5, 6] e->2,c->3,b->4') 247 '0: [0] a->1; 1: [3, 4, 5, 6] e->2,c->3,b->4; 2(label): [1, 2]; 3: [7] d->4; 4: [4, 5, 6] e->2,c->3,b->4')
247 248
248 def test_dfa_overlapping_choice(self): 249 def test_dfa_overlapping_choice(self):
249 self.assert_dfa_graph('a(?:bcd|bce)', 250 self.assert_dfa_graph('a(?:bcd|bce)',
250 '0: [0] a->1; 1: [3, 4] b->2; 2: [5, 7] c->3; 3: [8, 6] [d-e]->4; 4(label): [1, 2]') 251 '0: [0] a->1; 1: [3, 4] b->2; 2: [5, 7] c->3; 3: [8, 6] [d-e]->4; 4(label): [1, 2]')
251 252
252 def test_dfa_conflicting_choice(self): 253 def test_dfa_conflicting_choice(self):
253 self.assert_dfa_graph('a(?:bc|b*d)', 254 self.assert_dfa_graph('a(?:bc|b*d)',
254 '0: [0] a->1; 1: [3, 4, 6, 7] b->2,d->3; 2: [5, 6, 7] [c-d]->3,b->4; 3(label): [1, 2]; 4: [6, 7] d->3,b->4') 255 '0: [0] a->1; 1: [3, 4, 6, 7] b->2,d->3; 2: [5, 6, 7] [c-d]->3,b->4; 3(label): [1, 2]; 4: [6, 7] d->3,b->4')
255 256
256 def test_dfa_conflicting_choice_2(self): 257 def test_dfa_conflicting_choice_2(self):
257 self.assert_dfa_graph('a(?:bb|b*c)', 258 self.assert_dfa_graph('a(?:bb|b*c)',
258 '0: [0] a->1; 1: [3, 4, 6, 7] b->2,c->3; 2: [5, 6, 7] c->3,b->4; 3(label): [1, 2]; 4(label): [1, 2, 6, 7] c->3,b->5; 5: [6, 7] c->3,b->5') 259 '0: [0] a->1; 1: [3, 4, 6, 7] b->2,c->3; 2: [5, 6, 7] c->3,b->4; 3(label): [1, 2]; 4(label): [1, 2, 6, 7] c->3,b->5; 5: [6, 7] c->3,b->5')
259 260
260 def test_dfa_dot_option(self): 261 def test_dfa_dot_option(self):
261 ''' 262 '''
262 This one's nice - the 'a' completely disappears. 263 This one's nice - the 'a' completely disappears.
263 ''' 264 '''
264 #basicConfig(level=DEBUG) 265 #basicConfig(level=DEBUG)
265 self.assert_dfa_graph('.*a?b', 266 self.assert_dfa_graph('.*a?b',
266 r'0: [0, 3, 4, 5] [\x00-ac-\uffff]->1,b->2; 1: [3, 4, 5] [\x00-ac-\uffff]->1,b->2; 2(label): [1, 2, 3, 4, 5] [\x00-ac-\uffff]->1,b->2') 267 r'0: [0, 3, 4, 5] [\x00-ac-\uffff]->1,b->2; 1: [3, 4, 5] [\x00-ac-\uffff]->1,b->2; 2(label): [1, 2, 3, 4, 5] [\x00-ac-\uffff]->1,b->2')
267 268
268 class DfaTest(TestCase): 269 class DfaTest(TestCase):
269 270
270 def assert_dfa(self, regexp, text, results): 271 def assert_dfa(self, regexp, text, results):
271 r = _test_parser(regexp).dfa().match((text, 0, None)) 272 r = _test_parser(regexp).dfa().match((0, StringHelper(text)))
272 assert r[1] == results, r 273 assert r[1] == results, r
273 274
274 def test_simple(self): 275 def test_simple(self):
275 self.assert_dfa('abc', 'abcd', 'abc') 276 self.assert_dfa('abc', 'abcd', 'abc')
276 277
277 def test_dot_option(self): 278 def test_dot_option(self):
278 self.assert_dfa('.*a?b', 'aaabc', 'aaab') 279 self.assert_dfa('.*a?b', 'aaabc', 'aaab')
279 280
280 def test_empty(self): 281 def test_empty(self):
281 self.assert_dfa('a*', 'bc', '') 282 self.assert_dfa('a*', 'bc', '')
282 self.assert_dfa('a*', '', '') 283 self.assert_dfa('a*', '', '')
283 284
284 def test_conflicting_choice(self): 285 def test_conflicting_choice(self):
285 self.assert_dfa('a(?:bc|b*d)', 'abde', 'abd') 286 self.assert_dfa('a(?:bc|b*d)', 'abde', 'abd')
286 self.assert_dfa('a(?:bc|b*d)', 'abce', 'abc') 287 self.assert_dfa('a(?:bc|b*d)', 'abce', 'abc')
287 288
288 def test_space_star(self): 289 def test_space_star(self):
289 self.assert_dfa(' *', ' a', ' ') 290 self.assert_dfa(' *', ' a', ' ')
Powered by Google Project Hosting