Skip to content

Commit c18670d

Browse files
committed
Adding a new test for ParserProtocol.
1 parent 49e099a commit c18670d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ometa/test/test_protocol.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
someA = ('a' 'a') -> state('a')
1010
someB = ('b' 'b') -> state('b')
11+
someC = ('c' 'c') -> state('c')
1112
1213
initial = someA
1314
@@ -121,6 +122,18 @@ def test_ruleSwitchingViaState(self):
121122
self.protocol.dataReceived('abb')
122123
self.assertEqual(self.protocol.state.calls, ['a', 'a', 'b'])
123124

125+
def test_ruleSwitchingViaStateGetsOverridden(self):
126+
"""Returning a new rule takes priority over calling setNextRule."""
127+
self.protocol.makeConnection(None)
128+
self.protocol.dataReceived('aa')
129+
self.assertEqual(self.protocol.state.calls, ['a'])
130+
self.protocol.dataReceived('a')
131+
self.assertEqual(self.protocol.state.calls, ['a'])
132+
self.protocol.state.parser.setNextRule('someB')
133+
self.protocol.state.returnMap['a'] = 'someC'
134+
self.protocol.dataReceived('acc')
135+
self.assertEqual(self.protocol.state.calls, ['a', 'a', 'c'])
136+
124137
def test_connectionLoss(self):
125138
"""The reason for connection loss is forwarded to the state."""
126139
self.protocol.makeConnection(None)

0 commit comments

Comments
 (0)