[3611] | 1 | #!/bin/sh
|
---|
| 2 | # Test character-class definitions in POSIX mode.
|
---|
| 3 |
|
---|
| 4 | # Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
---|
| 5 |
|
---|
| 6 | # This program is free software: you can redistribute it and/or modify
|
---|
| 7 | # it under the terms of the GNU General Public License as published by
|
---|
| 8 | # the Free Software Foundation, either version 3 of the License, or
|
---|
| 9 | # (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | # This program is distributed in the hope that it will be useful,
|
---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | # GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | # You should have received a copy of the GNU General Public License
|
---|
| 17 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
---|
| 18 |
|
---|
| 19 | # NOTE:
|
---|
| 20 | # In GNU Extension mode, all text is normalized (e.g. backslash-X combinations).
|
---|
| 21 | # In POSIX mode, normalize_text() ensures content of character
|
---|
| 22 | # classes is not normalized.
|
---|
| 23 | #
|
---|
| 24 | # Compare:
|
---|
| 25 | # $ printf "t\t\n" | sed 's/[\t]/X/' | od -a
|
---|
| 26 | # 0000000 t X nl
|
---|
| 27 | # $ printf "t\t\n" | sed --posix 's/[\t]/X/' | od -a
|
---|
| 28 | # 0000000 X ht nl
|
---|
| 29 | #
|
---|
| 30 | # This test unit validates the special handling of character classes
|
---|
| 31 | # in posix mode (compile.c:normalize_text() implementation).
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
---|
| 35 | print_ver_ sed
|
---|
| 36 |
|
---|
| 37 | echo X > exp || framework_failure_
|
---|
| 38 |
|
---|
| 39 | # Closing bracket without opening bracket, match as-is
|
---|
| 40 | echo ']' | sed --posix 's/]/X/' > out1 || fail=1
|
---|
| 41 | compare_ exp out1 || fail=1
|
---|
| 42 |
|
---|
| 43 | # Two opening brackets (same state when opening the second one)
|
---|
| 44 | echo '[' | sed --posix 's/[[]/X/' > out2 || fail=1
|
---|
| 45 | compare_ exp out2 || fail=1
|
---|
| 46 |
|
---|
| 47 | # Escaping before and after the character class, but not inside it (POSIX MODE)
|
---|
| 48 | printf "\tt\t\n" | sed --posix 's/\t[\t]\t/X/' > out3 || fail=1
|
---|
| 49 | compare_ exp out3 || fail=1
|
---|
| 50 |
|
---|
| 51 | # Escaping before, inside, and after the character class (GNU MODE)
|
---|
| 52 | printf "\t\t\t\n" | sed 's/\t[\t]\t/X/' > out4 || fail=1
|
---|
| 53 | compare_ exp out4 || fail=1
|
---|
| 54 |
|
---|
| 55 | # Special characters, but outside a valid character-class syntax
|
---|
| 56 | printf "=\n" | sed --posix 's/[.=:.]/X/' > out5 || fail=1
|
---|
| 57 | compare_ exp out5 || fail=1
|
---|
| 58 |
|
---|
| 59 | # A valid character class definition
|
---|
| 60 | printf "b\n" | sed --posix 's/[[:alpha:]]/X/' > out6 || fail=1
|
---|
| 61 | compare_ exp out6 || fail=1
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | Exit $fail
|
---|