]>
Commit | Line | Data |
---|---|---|
4a94e368 | 1 | # Copyright 2021-2022 Free Software Foundation, Inc. |
ca498784 TV |
2 | # This program is free software; you can redistribute it and/or modify |
3 | # it under the terms of the GNU General Public License as published by | |
4 | # the Free Software Foundation; either version 3 of the License, or | |
5 | # (at your option) any later version. | |
6 | # | |
7 | # This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | |
14 | ||
15 | # Testsuite self-tests for string_to_regexp/string_list_to_regexp. | |
16 | # The former is not explicitly tested, assuming string_list_to_regexp uses | |
17 | # string_to_regexp. | |
18 | ||
19 | set test_nr 0 | |
20 | ||
21 | proc test_regexp { args } { | |
22 | global test_nr | |
23 | incr test_nr | |
24 | ||
25 | set fargs {} | |
26 | set farg 1 | |
27 | foreach arg $args { | |
28 | if { $farg } { | |
29 | if { $arg == "--" } { | |
30 | set farg 0 | |
31 | continue | |
32 | } | |
33 | lappend fargs $arg | |
34 | } else { | |
35 | set re $arg | |
36 | break | |
37 | } | |
38 | } | |
39 | set res [string_list_to_regexp {*}$fargs] | |
40 | ||
41 | set test "#$test_nr: got expected re" | |
42 | if { $res eq $re } { | |
43 | pass $test | |
44 | } else { | |
45 | verbose -log "Expecting '$re'" | |
46 | verbose -log "Got '$res'" | |
47 | fail $test | |
48 | } | |
49 | ||
50 | set test "#$test_nr: re matches string" | |
51 | set str [join $fargs ""] | |
52 | if { [regexp $re $str] } { | |
53 | pass $test | |
54 | } else { | |
55 | verbose -log "Matching '$str'" | |
56 | verbose -log "Failed against '$re'" | |
57 | fail $test | |
58 | } | |
59 | } | |
60 | ||
61 | test_regexp abc -- abc | |
62 | test_regexp abc def -- abcdef | |
63 | test_regexp {\\} -- {\\\\} | |
64 | test_regexp "\n" -- "\n" | |
65 | test_regexp {\n} -- {\\n} | |
66 | test_regexp {\\} n -- {\\\\n} |