My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
Changes to /src/lepl/rxpy/engine/_test/support.py
a9fcd7366d1c vs. 6c6b12a47a37 Compare: vs.  Format:
Revision 6c6b12a47a37
Go to: 
Project members, sign in to write a code review
/src/lepl/rxpy/engine/_test/support.py   a9fcd7366d1c /src/lepl/rxpy/engine/_test/support.py   6c6b12a47a37
1 #LICENCE 1 #LICENCE
2 2
3 3
4 from unittest import TestCase 4 from unittest import TestCase
5 5
6 from lepl.rxpy.engine.support import StreamTargetMixin 6 from lepl.rxpy.engine.support import StreamTargetMixin
7 from lepl.stream.factory import DEFAULT_STREAM_FACTORY 7 from lepl.stream.factory import DEFAULT_STREAM_FACTORY
8 8
9 9
10 class StreamTargetTest(TestCase): 10 class StreamTargetTest(TestCase):
11 11
12 def new_target(self, text, offset, previous=None): 12 def new_target(self, text, offset, previous=None):
13 stream = DEFAULT_STREAM_FACTORY.from_string(text) 13 stream = DEFAULT_STREAM_FACTORY.from_string(text)
14 target = StreamTargetMixin() 14 target = StreamTargetMixin()
15 target._reset(offset, stream, previous) 15 target._reset(offset, stream, previous)
16 return target 16 return target
17 17
18 def assert_target(self, target, offset, previous, current, excess): 18 def assert_target(self, target, offset, previous, current, excess):
19 assert target._offset == offset, target._offset 19 assert target._offset == offset, target._offset
20 assert target._previous == previous, target._previous 20 assert target._previous == previous, target._previous
21 assert target._current == current, target._current 21 assert target._current == current, target._current
22 assert target._excess == excess, target._excess 22 assert target._excess == excess, target._excess
23 23
24 def test_empty(self): 24 def test_empty(self):
25 25
26 target = self.new_target('', 0) 26 target = self.new_target('', 0)
27 self.assert_target(target, 0, None, None, 1) 27 self.assert_target(target, 0, None, None, 1)
28 target._advance(1) 28 target._advance()
29 self.assert_target(target, 1, None, None, 2) 29 self.assert_target(target, 1, None, None, 2)
30 30
31 target = self.new_target('', 1) 31 target = self.new_target('', 1)
32 self.assert_target(target, 1, None, None, 1) 32 self.assert_target(target, 1, None, None, 1)
33 target._advance(2) 33 target._advance(2)
34 self.assert_target(target, 3, None, None, 3) 34 self.assert_target(target, 3, None, None, 3)
35 35
36 target = self.new_target('', 0, previous='x') 36 target = self.new_target('', 0, previous='x')
37 self.assert_target(target, 0, 'x', None, 1) 37 self.assert_target(target, 0, 'x', None, 1)
38 target._advance(1) 38 target._advance()
39 self.assert_target(target, 1, None, None, 2) 39 self.assert_target(target, 1, None, None, 2)
40 40
41 def test_char(self): 41 def test_char(self):
42 42
43 target = self.new_target('x', 0) 43 target = self.new_target('x', 0)
44 self.assert_target(target, 0, None, 'x', 0) 44 self.assert_target(target, 0, None, 'x', 0)
45 target._advance(1) 45 target._advance()
46 self.assert_target(target, 1, 'x', None, 1) 46 self.assert_target(target, 1, 'x', None, 1)
47 target._advance(1) 47 target._advance()
48 self.assert_target(target, 2, None, None, 2) 48 self.assert_target(target, 2, None, None, 2)
49 49
50 target = self.new_target('x', 1) 50 target = self.new_target('x', 1)
51 self.assert_target(target, 1, None, 'x', 0) 51 self.assert_target(target, 1, None, 'x', 0)
52 target._advance(2) 52 target._advance(2)
53 self.assert_target(target, 3, None, None, 2) 53 self.assert_target(target, 3, None, None, 2)
54 54
55 target = self.new_target('x', 0, previous='y') 55 target = self.new_target('x', 0, previous='y')
56 self.assert_target(target, 0, 'y', 'x', 0) 56 self.assert_target(target, 0, 'y', 'x', 0)
57 target._advance(1) 57 target._advance()
58 self.assert_target(target, 1, 'x', None, 1) 58 self.assert_target(target, 1, 'x', None, 1)
59 target._advance(1) 59 target._advance()
60 self.assert_target(target, 2, None, None, 2) 60 self.assert_target(target, 2, None, None, 2)
61 61
62 def test_string(self): 62 def test_string(self):
63 63
64 target = self.new_target('xz', 0) 64 target = self.new_target('xz', 0)
65 self.assert_target(target, 0, None, 'x', 0) 65 self.assert_target(target, 0, None, 'x', 0)
66 target._advance(1) 66 target._advance()
67 self.assert_target(target, 1, 'x', 'z', 0) 67 self.assert_target(target, 1, 'x', 'z', 0)
68 target._advance(1) 68 target._advance()
69 self.assert_target(target, 2, 'z', None, 1) 69 self.assert_target(target, 2, 'z', None, 1)
70 70
71 target = self.new_target('xz', 1) 71 target = self.new_target('xz', 1)
72 self.assert_target(target, 1, None, 'x', 0) 72 self.assert_target(target, 1, None, 'x', 0)
73 target._advance(2) 73 target._advance(2)
74 self.assert_target(target, 3, 'z', None, 1) 74 self.assert_target(target, 3, 'z', None, 1)
75 75
76 target = self.new_target('xz', 0, previous='y') 76 target = self.new_target('xz', 0, previous='y')
77 self.assert_target(target, 0, 'y', 'x', 0) 77 self.assert_target(target, 0, 'y', 'x', 0)
78 target._advance(1) 78 target._advance()
79 self.assert_target(target, 1, 'x', 'z', 0) 79 self.assert_target(target, 1, 'x', 'z', 0)
80 target._advance(1) 80 target._advance()
81 self.assert_target(target, 2, 'z', None, 1) 81 self.assert_target(target, 2, 'z', None, 1)
82 target._advance(1) 82 target._advance()
83 self.assert_target(target, 3, None, None, 2) 83 self.assert_target(target, 3, None, None, 2)
84 84
85 target = self.new_target('xz', 0, previous='y') 85 target = self.new_target('xz', 0, previous='y')
86 self.assert_target(target, 0, 'y', 'x', 0) 86 self.assert_target(target, 0, 'y', 'x', 0)
87 target._advance(2) 87 target._advance(2)
88 self.assert_target(target, 2, 'z', None, 1) 88 self.assert_target(target, 2, 'z', None, 1)
89 target._advance(1) 89 target._advance()
90 self.assert_target(target, 3, None, None, 2) 90 self.assert_target(target, 3, None, None, 2)
91 91
92 target = self.new_target('xz', 0, previous='y') 92 target = self.new_target('xz', 0, previous='y')
93 self.assert_target(target, 0, 'y', 'x', 0) 93 self.assert_target(target, 0, 'y', 'x', 0)
94 target._advance(3) 94 target._advance(3)
95 self.assert_target(target, 3, None, None, 2) 95 self.assert_target(target, 3, None, None, 2)
96 96
Powered by Google Project Hosting