PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/test/lib/regular_expression/test_python_syntax_01.e

http://github.com/tybor/Liberty
Specman e | 89 lines | 66 code | 9 blank | 14 comment | 0 complexity | a2f6a06c9f99e79eb3c4e5bee26111c5 MD5 | raw file
 1-- This file is part of Liberty Eiffel.
 2--
 3-- Liberty Eiffel is free software: you can redistribute it and/or modify
 4-- it under the terms of the GNU General Public License as published by
 5-- the Free Software Foundation, version 3 of the License.
 6--
 7-- Liberty Eiffel is distributed in the hope that it will be useful,
 8-- but WITHOUT ANY WARRANTY; without even the implied warranty of
 9-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10-- GNU General Public License for more details.
11--
12-- You should have received a copy of the GNU General Public License
13-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
14--
15class TEST_PYTHON_SYNTAX_01
16
17insert
18   EIFFELTEST_TOOLS
19
20create {}
21   make
22
23feature {}
24   make
25      local
26         pattern: REGULAR_EXPRESSION
27         text, data: STRING
28      do
29         pattern := re.convert_python_pattern("a+(?P=foo)")
30         assert(pattern = Void)
31         assert(re.last_error_message.is_equal("Error at position 10: undefined named group."))
32         assert(re.last_error_position = 10)
33
34         pattern := re.convert_python_pattern("^(?P<foo>a+)(?P=foo)$")
35         assert(pattern /= Void)
36         assert(not pattern.match("aaa"))
37         text := "aaaa"
38         assert(pattern.match(text))
39         assert(pattern.group_names.count = 1)
40         assert(pattern.group_names.first.is_equal("foo"))
41         assert(pattern.has_group_name("foo"))
42         assert(not pattern.has_group_name("bar"))
43         assert(pattern.ith_group_matched(0))
44         assert(pattern.named_group_matched("foo"))
45         data := ""
46         pattern.append_named_group(text, data, "foo")
47         assert(data.is_equal("aa"))
48
49         pattern := re.convert_python_pattern("^(?P<foo>a+?)(?P=foo)$")
50         assert(pattern /= Void)
51         assert(not pattern.match("aaa"))
52         text := "aaaa"
53         assert(pattern.match(text))
54         assert(pattern.group_names.count = 1)
55         assert(pattern.group_names.first.is_equal("foo"))
56         assert(pattern.has_group_name("foo"))
57         assert(not pattern.has_group_name("bar"))
58         assert(pattern.ith_group_matched(0))
59         assert(pattern.named_group_matched("foo"))
60         data := ""
61         pattern.append_named_group(text, data, "foo")
62         assert(data.is_equal("aa"))
63
64         pattern := re.convert_python_pattern("^(?P<foo>a+b)(?P=foo)$")
65         assert(pattern /= Void)
66         assert(not pattern.match("aaaabab"))
67         text := "aaabaaab"
68         assert(pattern.match(text))
69         assert(pattern.group_names.count = 1)
70         assert(pattern.group_names.first.is_equal("foo"))
71         assert(pattern.has_group_name("foo"))
72         assert(not pattern.has_group_name("bar"))
73         assert(pattern.ith_group_matched(0))
74         assert(pattern.named_group_matched("foo"))
75         data := ""
76         pattern.append_named_group(text, data, "foo")
77         assert(data.is_equal("aaab"))
78         pattern.for_all_matched_named_groups(text, agent compare_group_text("foo", ?, "aaab", ?))
79      end
80
81   compare_group_text (expected_group: STRING; actual_group: FIXED_STRING; expected_data: STRING; actual_data: STRING)
82      do
83         assert(expected_group.is_equal(actual_group))
84         assert(expected_data.is_equal(actual_data))
85      end
86
87   re: REGULAR_EXPRESSION_BUILDER
88
89end -- class TEST_PYTHON_SYNTAX_01