Package lepl :: Package regexp :: Package _test :: Module binary
[hide private]
[frames] | no frames]

Source Code for Module lepl.regexp._test.binary

 1   
 2  # 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  # in compliance with the License. You may obtain a copy of the License 
 5  # at http://www.mozilla.org/MPL/ 
 6  # 
 7  # Software distributed under the License is distributed on an "AS IS" 
 8  # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
 9  # the License for the specific language governing rights and 
10  # limitations under the License. 
11  # 
12  # The Original Code is LEPL (http://www.acooke.org/lepl) 
13  # The Initial Developer of the Original Code is Andrew Cooke. 
14  # Portions created by the Initial Developer are Copyright (C) 2009-2010 
15  # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 
16  # 
17  # Alternatively, the contents of this file may be used under the terms 
18  # of the LGPL license (the GNU Lesser General Public License, 
19  # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 
20  # of the LGPL License are applicable instead of those above. 
21  # 
22  # 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  # 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  # 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  # MPL or the LGPL License. 
29   
30  ''' 
31  Tests for the lepl.regexp.binary module. 
32  ''' 
33   
34  from unittest import TestCase 
35   
36  #from logging import basicConfig, DEBUG 
37  from lepl.regexp.binary import binary_single_parser 
38  from lepl.support.lib import fmt 
39   
40  # pylint: disable-msg=C0103, C0111, C0301, C0324, R0201, R0903, R0904 
41  # (dude this is just a test) 
42   
43   
44 -def _test_parser(text):
45 return binary_single_parser('label', text)
46
47 -def label(text):
48 return fmt('(?P<label>{0!s})', text)
49
50 -class CharactersTest(TestCase):
51
52 - def test_dot(self):
53 #basicConfig(level=DEBUG) 54 c = _test_parser('.') 55 assert label('.') == str(c), str(c)
56 # assert 0 == c[0][0][0][0], type(c[0][0][0][0]) 57 # assert 1 == c[0][0][0][1], type(c[0][0][0][1]) 58
59 - def test_brackets(self):
60 #basicConfig(level=DEBUG) 61 c = _test_parser('0') 62 assert label('0') == str(c), str(c) 63 # this is the lower bound for the interval 64 # assert 0 == c[0][0][0][0], type(c[0][0][0][0]) 65 # and the upper - we really do have a digit 66 # assert 0 == c[0][0][0][1], type(c[0][0][0][1]) 67 c = _test_parser('1') 68 assert label('1') == str(c), str(c) 69 c = _test_parser('0101') 70 assert label('0101') == str(c), str(c)
71
72 - def test_star(self):
73 c = _test_parser('0*') 74 assert label('0*') == str(c), str(c) 75 c = _test_parser('0(?:01)*1') 76 assert label('0(?:01)*1') == str(c), str(c)
77
78 - def test_option(self):
79 c = _test_parser('1?') 80 assert label('1?') == str(c), str(c) 81 c = _test_parser('0(?:01)?1') 82 assert label('0(?:01)?1') == str(c), str(c)
83
84 - def test_choice(self):
85 c = _test_parser('(?:0*|1)') 86 assert label('(?:0*|1)') == str(c), str(c)
87