Revision: 17901
Author: [email protected]
Date: Wed Nov 20 09:50:09 2013 UTC
Log: Experimental parser: remove action tests
[email protected]
BUG=
Review URL: https://codereview.chromium.org/77533003
http://code.google.com/p/v8/source/detail?r=17901
Deleted:
/branches/experimental/parser/tools/lexer_generator/action_test.py
Modified:
/branches/experimental/parser/tools/lexer_generator/lexer_test.py
/branches/experimental/parser/tools/lexer_generator/test_suite.py
=======================================
--- /branches/experimental/parser/tools/lexer_generator/action_test.py Thu
Nov 14 20:51:16 2013 UTC
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright 2013 the V8 project authors. All rights reserved.
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided
-# with the distribution.
-# * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import unittest
-from automaton import Action
-from rule_parser import RuleProcessor
-from nfa_builder import NfaBuilder
-from dfa import Dfa
-
-def process_rules(rules):
- rule_map = {}
- for name, automata in RuleProcessor.parse(rules).automata_iter():
- rule_map[name] = automata
- return rule_map
-
-class ActionTestCase(unittest.TestCase):
-
- def __verify_last_action(self, automata, string, expected_code):
- expected_code = (expected_code, None)
- for automaton in [automata.dfa(), automata.minimal_dfa()]:
- actions = list(automaton.collect_actions(string))
- self.assertEqual(actions[-1], Dfa.terminal_action())
- self.assertEqual(actions[-2].match_action(), expected_code)
-
- def test_action_precedence(self):
- rules = '''<<default>>
- "key" <|KEYWORD|>
- /[a-z]+/ <|ID|>'''
- automata_for_conditions = process_rules(rules)
- self.assertEqual(len(automata_for_conditions), 1)
- self.assertTrue('default' in automata_for_conditions)
- automata = automata_for_conditions['default']
-
- self.__verify_last_action(automata, 'foo', 'ID')
- self.__verify_last_action(automata, 'key', 'KEYWORD')
- self.__verify_last_action(automata, 'k', 'ID')
- self.__verify_last_action(automata, 'ke', 'ID')
- self.__verify_last_action(automata, 'keys', 'ID')
-
- def test_wrong_action_precedence(self):
- rules = '''<<default>>
- /[a-z]+/ <|ID|>
- "key" <|KEYWORD|>'''
- automata_for_conditions = process_rules(rules)
- self.assertEqual(len(automata_for_conditions), 1)
- self.assertTrue('default' in automata_for_conditions)
- automata = automata_for_conditions['default']
-
- # The keyword is not recognized because of the rule preference order
(ID
- # is preferred over KEYWORD).
- self.__verify_last_action(automata, 'foo', 'ID')
- self.__verify_last_action(automata, 'key', 'ID')
=======================================
--- /branches/experimental/parser/tools/lexer_generator/lexer_test.py Wed
Nov 20 09:31:53 2013 UTC
+++ /branches/experimental/parser/tools/lexer_generator/lexer_test.py Wed
Nov 20 09:50:09 2013 UTC
@@ -33,13 +33,15 @@
def __verify_action_stream(self, rules, string, expected):
expected = map(lambda (action, s) : (Action(None, (action, None)), s),
expected)
- expected.append((Action(None, ('terminate', None)), '\0'))
automata = RuleProcessor.parse(rules).default_automata()
for automaton in [automata.nfa(), automata.dfa(),
automata.minimal_dfa()]:
for i, (action, start, stop) in enumerate(automaton.lex(string)):
self.assertEquals(expected[i][0], action)
self.assertEquals(expected[i][1], string[start : stop])
+ def __terminate(self):
+ return (Action(None, ('terminate', None)), '\0')
+
def test_simple(self):
rules = '''
eos = [:eos:];
@@ -52,7 +54,7 @@
string = 'foo()'
self.__verify_action_stream(rules, string,
- [('FOO', 'foo'), ('LBRACE', '('), ('RBRACE', ')')])
+ [('FOO', 'foo'), ('LBRACE', '('), ('RBRACE', ')'),
self.__terminate()])
def test_maximal_matching(self):
rules = '''
@@ -65,7 +67,7 @@
string = '<< <'
self.__verify_action_stream(rules, string,
- [('SHL', '<<'), ('SPACE', ' '), ('LT', '<')])
+ [('SHL', '<<'), ('SPACE', ' '), ('LT', '<'), self.__terminate()])
def test_consecutive_epsilon_transitions(self):
rules = '''
@@ -73,8 +75,29 @@
digit = [0-9];
number = (digit+ ("." digit+)?);
<<default>>
- number <|NUMBER|>
- eos <|terminate|>'''
+ number <|NUMBER|>'''
string = '555'
self.__verify_action_stream(rules, string, [('NUMBER', '555')])
+
+ def test_action_precedence(self):
+ rules = '''
+ <<default>>
+ "key" <|KEYWORD|>
+ /[a-z]+/ <|ID|>'''
+
+ self.__verify_action_stream(rules, 'ke', [('ID', 'ke')])
+ self.__verify_action_stream(rules, 'key', [('KEYWORD', 'key')])
+ self.__verify_action_stream(rules, 'keys', [('ID', 'keys')])
+
+ def test_wrong_action_precedence(self):
+ rules = '''
+ <<default>>
+ /[a-z]+/ <|ID|>
+ "key" <|KEYWORD|>'''
+
+ # The keyword is not recognized because of the rule preference order
(ID
+ # is preferred over KEYWORD).
+ self.__verify_action_stream(rules, 'ke', [('ID', 'ke')])
+ self.__verify_action_stream(rules, 'key', [('ID', 'key')])
+ self.__verify_action_stream(rules, 'keys', [('ID', 'keys')])
=======================================
--- /branches/experimental/parser/tools/lexer_generator/test_suite.py Wed
Nov 13 08:33:29 2013 UTC
+++ /branches/experimental/parser/tools/lexer_generator/test_suite.py Wed
Nov 20 09:50:09 2013 UTC
@@ -40,7 +40,6 @@
loader.loadTestsFromTestCase(TransitionKeyTestCase),
loader.loadTestsFromTestCase(AutomataTestCase),
loader.loadTestsFromTestCase(RuleParserTestCase),
- loader.loadTestsFromTestCase(ActionTestCase),
loader.loadTestsFromTestCase(LexerTestCase),
loader.loadTestsFromTestCase(CodeGeneratorTestCase),
))
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.