From 65a0483fb55bd2b4dab305af8a95cd25e292142b Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Tue, 19 Jul 2011 09:06:37 +0100 Subject: unexpand: fix misalignment when spaces span a tabstop The following dropped the space from the first field printf "1234567 \t1\n" | unexpand -a Note POSIX says that spaces should not precede tabs. Also a single trailing space should not be converted if the next field starts with non blank characters. So we enforce those rules too, with this change. * src/unexpand.c (unexpand): Implement as per POSIX rules. * tests/misc/unexpand: Add tests, and adjust existing tests as per POSIX rules. * NEWS: Mention the fix. Reported by Hallvard B Furuseth --- tests/misc/unexpand | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests/misc/unexpand') diff --git a/tests/misc/unexpand b/tests/misc/unexpand index 81c3bcd85..c56b059ac 100755 --- a/tests/misc/unexpand +++ b/tests/misc/unexpand @@ -52,7 +52,7 @@ my @Tests = ['infloop-1', '-t', '1,2', {IN=> " \t\t .\n"}, {OUT=>"\t\t\t .\n"}], ['infloop-2', '-t', '4,5', {IN=> ' 'x4 . "\t\t \n"}, {OUT=>"\t\t\t \n"}], - ['infloop-3', '-t', '2,3', {IN=> "x \t\t \n"}, {OUT=>"x \t\t \n"}], + ['infloop-3', '-t', '2,3', {IN=> "x \t\t \n"}, {OUT=>"x\t\t\t \n"}], ['infloop-4', '-t', '1,2', {IN=> " \t\t \n"}, {OUT=>"\t\t\t \n"}], ['c-1', '-t', '1,2', {IN=> "x\t\t .\n"}, {OUT=>"x\t\t .\n"}], @@ -70,12 +70,22 @@ my @Tests = ['blanks-6', qw(-t 1), {IN=> "a "}, {OUT=> "a\t\t"}], ['blanks-7', qw(-t 1), {IN=> "a "}, {OUT=> "a\t\t\t"}], ['blanks-8', qw(-t 1), {IN=> " a a a\n"}, {OUT=> "\ta a\t\ta\n"}], - ['blanks-9', qw(-t 2), {IN=> " a a a\n"}, {OUT=> "\t a\ta a\n"}], + ['blanks-9', qw(-t 2), {IN=> " a a a\n"}, {OUT=> "\t a\ta\t a\n"}], ['blanks-10', '-t', '3,4', {IN=> "0 2 4 6\t8\n"}, {OUT=> "0 2 4 6\t8\n"}], ['blanks-11', '-t', '3,4', {IN=> " 4\n"}, {OUT=> "\t\t4\n"}], ['blanks-12', '-t', '3,4', {IN=> "01 4\n"}, {OUT=> "01\t\t4\n"}], ['blanks-13', '-t', '3,4', {IN=> "0 4\n"}, {OUT=> "0\t\t4\n"}], + # POSIX says spaces should only follow tabs. Also a single + # trailing space is not converted to a tab, when before + # a field starting with non blanks + ['posix-1', '-a', {IN=> "1234567 \t1\n"}, {OUT=>"1234567\t\t1\n"}], + ['posix-2', '-a', {IN=> "1234567 \t1\n"}, {OUT=>"1234567\t\t1\n"}], + ['posix-3', '-a', {IN=> "1234567 \t1\n"}, {OUT=>"1234567\t\t1\n"}], + ['posix-4', '-a', {IN=> "1234567\t1\n"}, {OUT=>"1234567\t1\n"}], + ['posix-5', '-a', {IN=> "1234567 1\n"}, {OUT=>"1234567\t 1\n"}], + ['posix-6', '-a', {IN=> "1234567 1\n"}, {OUT=>"1234567 1\n"}], + # It is debatable whether this test should require an environment # setting of e.g., _POSIX2_VERSION=1. ['obs-ovflo', "-$limits->{UINTMAX_OFLOW}", {IN=>''}, {OUT=>''}, -- cgit v1.2.3-54-g00ecf