busybox/testsuite/rev.tests
Ron Yorston 4357569fdc rev: correct output for long input lines
The input buffer is initialised to a reasonable size and extended
if necessary.  When this happened the offset into the buffer wasn't
reset to zero so subsequent lines were appended to the long line.

Fix this and add some tests.

function                                             old     new   delta
rev_main                                             377     368      -9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-9)               Total: -9 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-08-22 00:08:18 +02:00

47 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Copyright 2021 by Ron Yorston
# Licensed under GPLv2, see file LICENSE in this source tree.
. ./testing.sh
# testing "test name" "commands" "expected result" "file input" "stdin"
testing "rev works" \
"rev input" \
"\
1 enil
3 enil
" \
"line 1\n\nline 3\n" \
""
testing "rev file with missing newline" \
"rev input" \
"\
1 enil
3 enil" \
"line 1\n\nline 3" \
""
testing "rev file with NUL character" \
"rev input" \
"\
nil
3 enil
" \
"lin\000e 1\n\nline 3\n" \
""
testing "rev file with long line" \
"rev input" \
"\
+--------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------
cba
" \
"---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+--------------+\nabc\n" \
""
exit $FAILCOUNT