| 1 | #!/bin/sh
|
|---|
| 2 | # Text text escaping (compile.c:normalize_text()).
|
|---|
| 3 | # NOTE:
|
|---|
| 4 | # \dNNN \xNN \oNNN - tested in 'convert-number.sh'
|
|---|
| 5 | # character-classes in POSIX mode - tested in 'posix-char-class.sh'
|
|---|
| 6 |
|
|---|
| 7 | # Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
|---|
| 8 |
|
|---|
| 9 | # This program is free software: you can redistribute it and/or modify
|
|---|
| 10 | # it under the terms of the GNU General Public License as published by
|
|---|
| 11 | # the Free Software Foundation, either version 3 of the License, or
|
|---|
| 12 | # (at your option) any later version.
|
|---|
| 13 |
|
|---|
| 14 | # This program is distributed in the hope that it will be useful,
|
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | # GNU General Public License for more details.
|
|---|
| 18 |
|
|---|
| 19 | # You should have received a copy of the GNU General Public License
|
|---|
| 20 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|---|
| 21 | . "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
|---|
| 22 | print_ver_ sed
|
|---|
| 23 |
|
|---|
| 24 | #
|
|---|
| 25 | # Common backslash combinations
|
|---|
| 26 | #
|
|---|
| 27 | printf "%s\n" a a a a a a >in1 || framework_failure_
|
|---|
| 28 | cat <<\EOF >prog1 || framework_failure_
|
|---|
| 29 | 1y/a/\a/
|
|---|
| 30 | 2y/a/\f/
|
|---|
| 31 | 3y/a/\n/
|
|---|
| 32 | 4y/a/\r/
|
|---|
| 33 | 5y/a/\t/
|
|---|
| 34 | 6y/a/\v/
|
|---|
| 35 | EOF
|
|---|
| 36 | printf "\a\n\f\n\n\n\r\n\t\n\v\n" > exp1 || framework_failure_
|
|---|
| 37 |
|
|---|
| 38 | sed -f prog1 in1 > out1 || fail=1
|
|---|
| 39 | compare_ exp1 out1 || fail=1
|
|---|
| 40 |
|
|---|
| 41 | #
|
|---|
| 42 | # test '\\\n' (backslash followed by ASCII 0x0A)
|
|---|
| 43 | # normalized to a simple '\n' .
|
|---|
| 44 | #
|
|---|
| 45 | echo a > in2 || framework_failure_
|
|---|
| 46 | printf "y/a/\\\n/" > prog2 || framework_failure_
|
|---|
| 47 | printf "\n\n" > exp2 || framework_failure_
|
|---|
| 48 | sed -f prog2 in2 > out2 || fail=1
|
|---|
| 49 | compare_ exp2 out2 || fail=1
|
|---|
| 50 |
|
|---|
| 51 | #
|
|---|
| 52 | # \cX combination
|
|---|
| 53 | #
|
|---|
| 54 | printf "%s\n" a a a a a a a a a a > in3 || framework_failure_
|
|---|
| 55 | cat <<\EOF >prog3 || framework_failure_
|
|---|
| 56 | 1y/a/\cA/
|
|---|
| 57 | 2y/a/\ca/
|
|---|
| 58 | 3y/a/\cZ/
|
|---|
| 59 | 4y/a/\cz/
|
|---|
| 60 | 5y/a/\c{/
|
|---|
| 61 | 6y/a/\c;/
|
|---|
| 62 | 7y/a/\c#/
|
|---|
| 63 | 8y/a/\c[/
|
|---|
| 64 | 9y/a/\c\\/
|
|---|
| 65 | 10y/a/\c]/
|
|---|
| 66 | EOF
|
|---|
| 67 |
|
|---|
| 68 | printf "\1\n\1\n\32\n\32\n;\n{\nc\n\33\n\34\n\35\n" > exp3 || framework_failure_
|
|---|
| 69 | sed -f prog3 in3 > out3 || fail=1
|
|---|
| 70 | compare_ exp3 out3 || fail=1
|
|---|
| 71 |
|
|---|
| 72 | # \c at end of (valid) text - normalize_text() stops, returns control to caller.
|
|---|
| 73 | # TODO: is this a bug?
|
|---|
| 74 | # compare with 'y/a/\d/' and 'y/a/\x/'
|
|---|
| 75 | cat <<\EOF >exp-err-c || framework_failure_
|
|---|
| 76 | sed: -e expression #1, char 7: strings for `y' command are different lengths
|
|---|
| 77 | EOF
|
|---|
| 78 | returns_ 1 sed 'y/a/\c/' </dev/null 2>err-c || fail=1
|
|---|
| 79 | compare_ exp-err-c err-c || fail=1
|
|---|
| 80 |
|
|---|
| 81 | Exit $fail
|
|---|