git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Add test script for git-stripspace.
@ 2007-06-25 19:24 Carlos Rica
  2007-06-27  2:32 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Carlos Rica @ 2007-06-25 19:24 UTC (permalink / raw)
  To: git, Johannes.Schindelin, krh

These tests check some features that git-stripspace already has
and those that it should manage well: Removing trailing spaces
from lines, removing blank lines at the beginning and end,
unifying multiple lines between paragraphs, doing the correct
when there is no newline at the last line, etc.

It seems that the implementation needs to save the whole line
in memory to be able to manage correctly long lines with
text and spaces conveniently distribuited on them.

Signed-off-by: Carlos Rica <jasampler@gmail.com>
---
t/t0030-stripspace.sh |  355
+++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 355 insertions(+), 0 deletions(-)
create mode 100644 t/t0030-stripspace.sh

diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
new file mode 100644
index 0000000..abd82d7
--- /dev/null
+++ b/t/t0030-stripspace.sh
@@ -0,0 +1,355 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Carlos Rica
+#
+
+test_description='git-stripspace'
+
+. ./test-lib.sh
+
+t40='A quick brown fox jumps over the lazy do'
+s40='                                        '
+sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
+ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
+
+test_expect_success \
+    'long lines without spaces should be unchanged' '
+    echo "$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$ttt$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$ttt$ttt$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_success \
+    'lines with spaces at the beginning should be unchanged' '
+    echo "$sss$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$sss$sss$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$sss$sss$sss$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_success \
+    'lines with intermediate spaces should be unchanged' '
+    echo "$ttt$sss$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$sss$sss$ttt" >expect &&
+    cat expect | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_success \
+    'consecutive blank lines should be unified' '
+    printf "$ttt\n\n$ttt\n" > expect &&
+    printf "$ttt\n\n\n\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt\n\n$ttt\n" > expect &&
+    printf "$ttt$ttt\n\n\n\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt$ttt\n\n$ttt\n" > expect &&
+    printf "$ttt$ttt$ttt\n\n\n\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n\n$ttt\n" > expect &&
+    printf "$ttt\n\n\n\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n\n$ttt$ttt\n" > expect &&
+    printf "$ttt\n\n\n\n\n$ttt$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n\n$ttt$ttt$ttt\n" > expect &&
+    printf "$ttt\n\n\n\n\n$ttt$ttt$ttt\n" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_success \
+    'consecutive blank lines at the beginning should be removed' '
+    printf "" > expect &&
+    printf "\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "$sss\n$sss\n$sss\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "$sss$sss\n$sss\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "\n$sss\n$sss$sss\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "$sss$sss$sss$sss\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "\n$sss$sss$sss$sss\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "" > expect &&
+    printf "\n\n$sss$sss$sss$sss\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "\n\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt\n" > expect &&
+    printf "\n\n\n$ttt$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt$ttt\n" > expect &&
+    printf "\n\n\n$ttt$ttt$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt$ttt$ttt\n" > expect &&
+    printf "\n\n\n$ttt$ttt$ttt$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$sss\n$sss\n$sss\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "\n$sss\n$sss$sss\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$sss$sss\n$sss\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$sss$sss$sss\n\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "\n$sss$sss$sss\n\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "\n\n$sss$sss$sss\n$ttt\n" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_success \
+    'consecutive blank lines at the end should be removed' '
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt\n" > expect &&
+    printf "$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt$ttt\n" > expect &&
+    printf "$ttt$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt$ttt$ttt\n" > expect &&
+    printf "$ttt$ttt$ttt$ttt\n\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n$sss\n$sss\n$sss\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n\n$sss\n$sss$sss\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n$sss$sss\n$sss\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n$sss$sss$sss\n\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n\n$sss$sss$sss\n\n" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" > expect &&
+    printf "$ttt\n\n\n$sss$sss$sss\n" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_success \
+    'text without newline at end should end with newline' '
+    test `printf "$ttt" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$ttt" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$ttt$ttt" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$ttt$ttt$ttt" | git-stripspace | wc -l` -gt 0
+'
+
+# text plus spaces at the end:
+
+test_expect_success \
+    'text plus spaces without newline at end should end with newline' '
+    test `printf "$ttt$sss" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$ttt$sss" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$ttt$ttt$sss" | git-stripspace | wc -l` -gt 0
+    test `printf "$ttt$sss$sss" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$ttt$sss$sss" | git-stripspace | wc -l` -gt 0 &&
+    test `printf "$ttt$sss$sss$sss" | git-stripspace | wc -l` -gt 0
+'
+
+test_expect_failure \
+    'text plus spaces without newline at end should not show spaces' '
+    printf "$ttt$sss" | git-stripspace | grep -q "  " ||
+    printf "$ttt$ttt$sss" | git-stripspace | grep -q "  " ||
+    printf "$ttt$ttt$ttt$sss" | git-stripspace | grep -q "  " ||
+    printf "$ttt$sss$sss" | git-stripspace | grep -q "  " ||
+    printf "$ttt$ttt$sss$sss" | git-stripspace | grep -q "  " ||
+    printf "$ttt$sss$sss$sss" | git-stripspace | grep -q "  "
+'
+
+test_expect_success \
+    'text plus spaces without newline should show the correct lines' '
+    printf "$ttt\n" >expect &&
+    printf "$ttt$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" >expect &&
+    printf "$ttt$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt\n" >expect &&
+    printf "$ttt$sss$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt\n" >expect &&
+    printf "$ttt$ttt$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt\n" >expect &&
+    printf "$ttt$ttt$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    printf "$ttt$ttt$ttt\n" >expect &&
+    printf "$ttt$ttt$ttt$sss" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_failure \
+    'text plus spaces at end should not show spaces' '
+    echo "$ttt$sss" | git-stripspace | grep -q "  " ||
+    echo "$ttt$ttt$sss" | git-stripspace | grep -q "  " ||
+    echo "$ttt$ttt$ttt$sss" | git-stripspace | grep -q "  " ||
+    echo "$ttt$sss$sss" | git-stripspace | grep -q "  " ||
+    echo "$ttt$ttt$sss$sss" | git-stripspace | grep -q "  " ||
+    echo "$ttt$sss$sss$sss" | git-stripspace | grep -q "  "
+'
+
+test_expect_success \
+    'text plus spaces at end should be cleaned and newline must remain' '
+    echo "$ttt" >expect &&
+    echo "$ttt$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt" >expect &&
+    echo "$ttt$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt" >expect &&
+    echo "$ttt$sss$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$ttt" >expect &&
+    echo "$ttt$ttt$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$ttt" >expect &&
+    echo "$ttt$ttt$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$ttt$ttt$ttt" >expect &&
+    echo "$ttt$ttt$ttt$sss" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+# spaces only:
+
+test_expect_success \
+    'spaces with newline at end should be replaced with empty string' '
+    printf "" >expect &&
+
+    echo | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$sss$sss$sss" | git-stripspace >actual &&
+    git diff expect actual &&
+
+    echo "$sss$sss$sss$sss" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_expect_failure \
+    'spaces without newline at end should not show spaces' '
+    printf "" | git-stripspace | grep -q " " ||
+    printf "$sss" | git-stripspace | grep -q " " ||
+    printf "$sss$sss" | git-stripspace | grep -q " " ||
+    printf "$sss$sss$sss" | git-stripspace | grep -q " " ||
+    printf "$sss$sss$sss$sss" | git-stripspace | grep -q " "
+'
+
+test_expect_success \
+    'spaces without newline at end should be replaced with empty string' '
+    printf "" >expect &&
+
+    printf "" | git-stripspace >actual &&
+    git diff expect actual
+
+    printf "$sss$sss" | git-stripspace >actual &&
+    git diff expect actual
+
+    printf "$sss$sss$sss" | git-stripspace >actual &&
+    git diff expect actual
+
+    printf "$sss$sss$sss$sss" | git-stripspace >actual &&
+    git diff expect actual
+'
+
+test_done
-- 
1.5.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Add test script for git-stripspace.
  2007-06-25 19:24 [PATCH 1/2] Add test script for git-stripspace Carlos Rica
@ 2007-06-27  2:32 ` Junio C Hamano
  2007-06-27  5:54   ` Carlos Rica
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2007-06-27  2:32 UTC (permalink / raw)
  To: Carlos Rica; +Cc: git, Johannes.Schindelin, krh

Carlos Rica <jasampler@gmail.com> writes:

> These tests check some features that git-stripspace already has
> and those that it should manage well: Removing trailing spaces
> from lines, removing blank lines at the beginning and end,
> unifying multiple lines between paragraphs, doing the correct
> when there is no newline at the last line, etc.
>
> It seems that the implementation needs to save the whole line
> in memory to be able to manage correctly long lines with
> text and spaces conveniently distribuited on them.
>
> Signed-off-by: Carlos Rica <jasampler@gmail.com>

Thanks.  That's extensive set of tests for a little utility.

> t/t0030-stripspace.sh |  355
> +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 355 insertions(+), 0 deletions(-)
> create mode 100644 t/t0030-stripspace.sh
>
> diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
> new file mode 100644
> index 0000000..abd82d7
> --- /dev/null
> +++ b/t/t0030-stripspace.sh

100755?

> @@ -0,0 +1,355 @@
> ...
> +test_expect_success \
> +    'long lines without spaces should be unchanged' '
> +    echo "$ttt" >expect &&
> +    cat expect | git-stripspace >actual &&
> +    git diff expect actual &&

Please don't cat a single file into a pipeline.

	git-stripspace <actual >expect

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Add test script for git-stripspace.
  2007-06-27  2:32 ` Junio C Hamano
@ 2007-06-27  5:54   ` Carlos Rica
  0 siblings, 0 replies; 3+ messages in thread
From: Carlos Rica @ 2007-06-27  5:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes.Schindelin, krh

2007/6/27, Junio C Hamano <gitster@pobox.com>:
> Thanks.  That's extensive set of tests for a little utility.

I hope not being overtesting the program. In order to reuse the
function that does this job from the builtins, perhaps we need another
implementation doing the same in a memory buffer instead a file
stream. The tests save the need to feed manually the program in this
development, and clarify the expected behaviour for the utility.

> > new file mode 100644
> 100755?

> > +    cat expect | git-stripspace >actual &&
> Please don't cat a single file into a pipeline.
>         git-stripspace <actual >expect

Thank you for your corrections. I Will resend it with those fixed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-27  5:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-25 19:24 [PATCH 1/2] Add test script for git-stripspace Carlos Rica
2007-06-27  2:32 ` Junio C Hamano
2007-06-27  5:54   ` Carlos Rica

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).