Package lepl :: Package lexer :: Package lines :: Package _test :: Module stream
[hide private]
[frames] | no frames]

Source Code for Module lepl.lexer.lines._test.stream

  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.lexer.lines.stream module. 
 32  ''' 
 33   
 34  #from logging import basicConfig, DEBUG 
 35  from unittest import TestCase 
 36   
 37  from lepl.lexer.matchers import Token 
 38  from lepl.matchers.core import Regexp, Literal, Any 
 39  from lepl.lexer.lines.matchers import Line, LineStart, LineEnd, NO_BLOCKS 
 40   
41 -class LineTest(TestCase):
42 43 # no longer a bad config!
44 - def test_bad_config(self):
45 #basicConfig(level=DEBUG) 46 text = Token('[^\n\r]+') 47 quoted = Regexp("'[^']'") 48 line = Line(text(quoted)) 49 line.config.lines() 50 parser = line.get_parse_string() 51 assert parser("'a'") == ["'a'"]
52
53 - def test_line(self):
54 #basicConfig(level=DEBUG) 55 text = Token('[^\n\r]+') 56 quoted = Regexp("'[^']'") 57 line = Line(text(quoted)) 58 line.config.lines(block_start=0) 59 parser = line.get_parse_string() 60 assert parser("'a'") == ["'a'"]
61
62 - def test_offset(self):
63 #basicConfig(level=DEBUG) 64 text = Token('[^\n\r]+') 65 line = Line(text(~Literal('aa') & Regexp('.*'))) 66 line.config.lines(block_start=0) 67 parser = line.get_parse_string() 68 assert parser('aabc') == ['bc'] 69 # what happens with an empty match? 70 check = ~Literal('aa') & Regexp('.*') 71 check.config.no_full_first_match() 72 assert check.parse('aa') == [''] 73 assert parser('aa') == ['']
74 75 # def test_single_line(self): 76 # #basicConfig(level=DEBUG) 77 # line = DfaRegexp('(*SOL)[a-z]*(*EOL)') 78 # line.config.lines() 79 # parser = line.get_parse_string() 80 # assert parser('abc') == ['abc'] 81
82 - def test_tabs(self):
83 ''' 84 Use block_policy here so that the regexp parser that excludes SOL 85 and EOL is used; otherwise Any()[:] matches those and we end up 86 with a single monster token. 87 ''' 88 line = LineStart() & Token(Any()) & LineEnd() 89 line.config.lines(tabsize=8, block_start=NO_BLOCKS, block_policy=0).trace_stack(True) 90 result = line.parse('a') 91 assert result == ['', 'a'], result 92 result = line.parse('\ta') 93 assert result == [' ', 'a'], result 94 line.config.lines(tabsize=None, block_start=NO_BLOCKS, block_policy=0) 95 result = line.parse('\ta') 96 assert result == ['\t', 'a'], result 97 line.config.lines(block_policy=0, block_start=NO_BLOCKS) 98 result = line.parse('\ta') 99 assert result == [' ', 'a'], result
100