| OLD | NEW |
| 1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 import unittest | 28 import unittest |
| 29 from automaton import Term, Action | 29 from automaton import Term, Action |
| 30 from rule_parser import RuleProcessor | 30 from rule_parser import RuleProcessor |
| 31 | 31 |
| 32 class LexerTestCase(unittest.TestCase): | 32 class LexerTestCase(unittest.TestCase): |
| 33 | 33 |
| 34 def __verify_action_stream(self, rules, string, expected): | 34 def __verify_action_stream(self, rules, string, expected): |
| 35 expected = map(lambda (action, s) : (Action(None, Term(action)), s), | 35 expected = map(lambda (action, s) : ( |
| 36 expected) | 36 Action(Term.empty_term(), Term(action)), s), |
| 37 expected) |
| 37 rule_processor = RuleProcessor.parse(rules, 'latin1') | 38 rule_processor = RuleProcessor.parse(rules, 'latin1') |
| 38 automata = rule_processor.default_automata() | 39 automata = rule_processor.default_automata() |
| 39 for automaton in [automata.nfa(), automata.dfa(), automata.minimal_dfa()]: | 40 for automaton in [automata.nfa(), automata.dfa(), automata.minimal_dfa()]: |
| 40 for i, (action, start, stop) in enumerate( | 41 for i, (action, start, stop) in enumerate( |
| 41 automaton.lex(string, rule_processor.default_action)): | 42 automaton.lex(string, rule_processor.default_action)): |
| 42 self.assertEquals(expected[i][0], action) | 43 self.assertEquals(expected[i][0], action) |
| 43 self.assertEquals(expected[i][1], string[start : stop]) | 44 self.assertEquals(expected[i][1], string[start : stop]) |
| 44 | 45 |
| 45 @staticmethod | 46 @staticmethod |
| 46 def __terminate(): | 47 def __terminate(): |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 /[b-z]/ <|ID|Identifier> | 138 /[b-z]/ <|ID|Identifier> |
| 138 " " <|SPACE|> | 139 " " <|SPACE|> |
| 139 <<Identifier>> | 140 <<Identifier>> |
| 140 /[b-z]/ <|ID|continue> | 141 /[b-z]/ <|ID|continue> |
| 141 /[a]/ <|INVALID|> | 142 /[a]/ <|INVALID|> |
| 142 ''' | 143 ''' |
| 143 self.__verify_action_stream(rules, 'bc ba de', | 144 self.__verify_action_stream(rules, 'bc ba de', |
| 144 [('ID', 'bc'), ('SPACE', ' '), | 145 [('ID', 'bc'), ('SPACE', ' '), |
| 145 ('INVALID', 'ba'), ('SPACE', ' '), | 146 ('INVALID', 'ba'), ('SPACE', ' '), |
| 146 ('ID', 'de')]) | 147 ('ID', 'de')]) |
| OLD | NEW |