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

Source Code for Module lepl.stream._test.iter

 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  from lepl._test.base import BaseTest 
32  from lepl.stream.core import s_empty, s_fmt, s_line, s_next, s_stream, \ 
33      s_debug, s_deepest 
34  from lepl.stream.factory import DEFAULT_STREAM_FACTORY 
35   
36   
37 -class GenericTest(BaseTest):
38
39 - def test_all(self):
40 lines = iter(['first line', 'second line', 'third line']) 41 f = DEFAULT_STREAM_FACTORY 42 s1 = f(lines) 43 # just created 44 assert not s_empty(s1) 45 # get first line 46 (l1, s2) = s_line(s1, False) 47 assert 'first line' == l1, l1 48 # get first character of next line 49 (c21, s21) = s_next(s2) 50 assert c21 == 's', c21 51 # and test fmtting 52 locn = s_fmt(s21, '{location}: {rest}') 53 assert locn == "line 2, character 2: 'econd line'", locn 54 # then get rest of second line 55 (c22, s3) = s_next(s21, count=len('econd line')) 56 assert c22 == 'econd line', c22 57 d = s_debug(s21) 58 assert d == "1:'e'", d 59 # and move on to third line 60 (c31, s31) = s_next(s3) 61 assert c31 == 't', c31 62 (c32, s32) = s_next(s31) 63 assert c32 == 'h', c32 64 # now try branching (think tokens) at line 1 65 s10 = s_stream(s2, l1) 66 (l1, s20) = s_line(s10, False) 67 assert l1 == 'first line', l1 68 assert not s_empty(s20) 69 (c1, s11) = s_next(s10) 70 assert c1 == 'f', c1 71 d = s_debug(s11) 72 assert d == "1:'i'", d 73 # finally look at max depth (which was after 'h' in third line) 74 m = s_deepest(s1) 75 locn = s_fmt(m, '{location}: {rest}') 76 assert locn == "line 3, character 3: 'ird line'", locn
77