VirtualBox

source: kBuild/trunk/src/sed/testsuite/posix-char-class.sh@ 3613

Last change on this file since 3613 was 3613, checked in by bird, 7 months ago

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

File size: 2.2 KB
Line 
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
35print_ver_ sed
36
37echo X > exp || framework_failure_
38
39# Closing bracket without opening bracket, match as-is
40echo ']' | sed --posix 's/]/X/' > out1 || fail=1
41compare_ exp out1 || fail=1
42
43# Two opening brackets (same state when opening the second one)
44echo '[' | sed --posix 's/[[]/X/' > out2 || fail=1
45compare_ exp out2 || fail=1
46
47# Escaping before and after the character class, but not inside it (POSIX MODE)
48printf "\tt\t\n" | sed --posix 's/\t[\t]\t/X/' > out3 || fail=1
49compare_ exp out3 || fail=1
50
51# Escaping before, inside, and after the character class (GNU MODE)
52printf "\t\t\t\n" | sed 's/\t[\t]\t/X/' > out4 || fail=1
53compare_ exp out4 || fail=1
54
55# Special characters, but outside a valid character-class syntax
56printf "=\n" | sed --posix 's/[.=:.]/X/' > out5 || fail=1
57compare_ exp out5 || fail=1
58
59# A valid character class definition
60printf "b\n" | sed --posix 's/[[:alpha:]]/X/' > out6 || fail=1
61compare_ exp out6 || fail=1
62
63
64
65Exit $fail
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette