| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 def setUp(self): | 34 def setUp(self): |
| 35 self.state = RuleParserState() | 35 self.state = RuleParserState() |
| 36 | 36 |
| 37 def parse(self, string): | 37 def parse(self, string): |
| 38 return self.state.parse(string) | 38 return self.state.parse(string) |
| 39 | 39 |
| 40 def test_basic(self): | 40 def test_basic(self): |
| 41 self.parse(''' | 41 self.parse(''' |
| 42 alias = /regex/; | 42 alias = /regex/; |
| 43 <cond1> /regex/ <<cond2>> | 43 <<cond1>> /regex/ <||cond2> |
| 44 <cond1> alias <<cond2>> | 44 <<cond1>> alias <||cond2> |
| 45 <cond2> /regex/ {body} | 45 <<cond2>> /regex/ <|{body}|> |
| 46 <cond2> alias {body} | 46 <<cond2>> alias <|{body}|> |
| 47 <cond3> /regex/ {body} <<cond1>> | 47 <<cond3>> /regex/ <{body}||> |
| 48 <cond3> alias {body} <<cond1>>''') | 48 <<cond3>> alias <{body}||>''') |
| 49 | 49 |
| 50 self.assertTrue(len(self.state.aliases), 1) | 50 self.assertTrue(len(self.state.aliases), 1) |
| 51 self.assertTrue('alias' in self.state.aliases) | 51 self.assertTrue('alias' in self.state.aliases) |
| 52 self.assertEquals(self.state.aliases['alias'], RegexParser.parse('regex')) | 52 self.assertEquals(self.state.aliases['alias'], RegexParser.parse('regex')) |
| 53 | 53 |
| 54 self.assertTrue(len(self.state.rules), 2) | 54 self.assertTrue(len(self.state.rules), 2) |
| 55 self.assertTrue('cond1' in self.state.rules) | 55 self.assertTrue('cond1' in self.state.rules) |
| 56 self.assertEquals(len(self.state.rules['cond1']['regex']), 2) | 56 self.assertEquals(len(self.state.rules['cond1']['regex']), 2) |
| 57 # self.assertTrue('regex2' in self.state.rules['cond1']) | 57 # self.assertTrue('regex2' in self.state.rules['cond1']) |
| 58 # self.assertEquals(self.state.rules['cond1']['regex2'], | 58 # self.assertEquals(self.state.rules['cond1']['regex2'], |
| 59 # ('condition', 'cond2')) | 59 # ('condition', 'cond2')) |
| 60 | 60 |
| 61 self.assertTrue('cond2' in self.state.rules) | 61 self.assertTrue('cond2' in self.state.rules) |
| 62 self.assertEquals(len(self.state.rules['cond2']['regex']), 2) | 62 self.assertEquals(len(self.state.rules['cond2']['regex']), 2) |
| 63 # self.assertTrue('regex3' in self.state.rules['cond2']) | 63 # self.assertTrue('regex3' in self.state.rules['cond2']) |
| 64 # self.assertEquals(self.state.rules['cond2']['regex3'], | 64 # self.assertEquals(self.state.rules['cond2']['regex3'], |
| 65 # ('body', 'body')) | 65 # ('body', 'body')) |
| 66 | 66 |
| 67 self.assertTrue('cond3' in self.state.rules) | 67 self.assertTrue('cond3' in self.state.rules) |
| 68 self.assertEquals(len(self.state.rules['cond3']['regex']), 2) | 68 self.assertEquals(len(self.state.rules['cond3']['regex']), 2) |
| 69 # self.assertTrue('regex4' in self.state.rules['cond3']) | 69 # self.assertTrue('regex4' in self.state.rules['cond3']) |
| 70 # self.assertEquals(self.state.rules['cond3']['regex4'], | 70 # self.assertEquals(self.state.rules['cond3']['regex4'], |
| 71 # ('condition_and_body', 'cond4', 'body')) | 71 # ('condition_and_body', 'cond4', 'body')) |
| 72 | 72 |
| 73 def test_more_complicated(self): | 73 def test_more_complicated(self): |
| 74 self.parse(''' | 74 self.parse(''' |
| 75 alias = "regex;with;semicolon"; | 75 alias = "regex;with;semicolon"; |
| 76 <cond1> "regex3}with}braces}" {body {with} braces } | 76 <<cond1>> "regex3}with}braces}" <|{body {with} braces }|> |
| 77 <cond1> "regex4{with{braces}" {body {with} braces }''') | 77 <<cond1>> "regex4{with{braces}" <{body {with} braces }||>''') |
| 78 | 78 |
| 79 self.assertEquals(self.state.aliases['alias'], | 79 self.assertEquals(self.state.aliases['alias'], |
| 80 RegexParser.parse("regex;with;semicolon")) | 80 RegexParser.parse("regex;with;semicolon")) |
| 81 self.assertTrue('cond1' in self.state.rules) | 81 self.assertTrue('cond1' in self.state.rules) |
| 82 self.assertEquals(len(self.state.rules['cond1']['regex']), 2) | 82 self.assertEquals(len(self.state.rules['cond1']['regex']), 2) |
| 83 | 83 |
| 84 # self.assertEquals( | 84 # self.assertEquals( |
| 85 # self.parse['cond1']['regex4{with{braces}'], | 85 # self.parse['cond1']['regex4{with{braces}'], |
| 86 # ('body', 'body {with} braces }')) | 86 # ('body', 'body {with} braces }')) |
| 87 | 87 |
| 88 def test_body_with_if(self): | 88 def test_body_with_if(self): |
| 89 self.parse('<cond> "regex" { if (foo) { bar } }') | 89 self.parse('<<cond>> "regex" <|{ if (foo) { bar } }|>') |
| 90 # self.assertEquals( | 90 # self.assertEquals( |
| 91 # self.parse['cond']['regex'], | 91 # self.parse['cond']['regex'], |
| 92 # ('body', 'if (foo) { bar }')) | 92 # ('body', 'if (foo) { bar }')) |
| 93 | 93 |
| 94 def test_regexp_with_count(self): | 94 def test_regexp_with_count(self): |
| 95 self.parse('<cond> /regex{1,3}/ { if (foo) { bar } }') | 95 self.parse('<<cond>> /regex{1,3}/ <|{ if (foo) { bar } }|>') |
| 96 # self.assertEquals( | 96 # self.assertEquals( |
| 97 # self.parse['cond']['regex{1,3}'], | 97 # self.parse['cond']['regex{1,3}'], |
| 98 # ('body', 'if (foo) { bar }')) | 98 # ('body', 'if (foo) { bar }')) |
| OLD | NEW |