gitweb: Add a feature to show side-by-side diff
[gitweb.git] / t / t0081-line-buffer.sh
index 13ac735b550777447c2969e56b9973306aad434c..bd83ed371acb5075b2b3cbb7866d36aa4bd48519 100755 (executable)
@@ -1,62 +1,76 @@
 #!/bin/sh
 
 test_description="Test the svn importer's input handling routines.
+
+These tests provide some simple checks that the line_buffer API
+behaves as advertised.
+
+While at it, check that input of newlines and null bytes are handled
+correctly.
 "
 . ./test-lib.sh
 
-test_expect_success 'read greeting' '
-       echo HELLO >expect &&
+test_expect_success 'hello world' '
+       echo ">HELLO" >expect &&
        test-line-buffer <<-\EOF >actual &&
-       read 5
+       binary 6
        HELLO
        EOF
        test_cmp expect actual
 '
 
 test_expect_success '0-length read, send along greeting' '
-       printf "%s\n" "" HELLO >expect &&
+       echo ">HELLO" >expect &&
        test-line-buffer <<-\EOF >actual &&
-       read 0
-
-       copy 5
+       binary 0
+       copy 6
        HELLO
        EOF
        test_cmp expect actual
 '
 
-test_expect_success 'buffer_read_string copes with trailing null byte' '
-       echo >expect &&
+test_expect_success 'read from file descriptor' '
+       rm -f input &&
+       echo hello >expect &&
+       echo hello >input &&
+       echo copy 6 |
+       test-line-buffer "&4" 4<input >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'skip, copy null byte' '
+       echo Q | q_to_nul >expect &&
        q_to_nul <<-\EOF | test-line-buffer >actual &&
-       read 1
+       skip 2
+       Q
+       copy 2
        Q
        EOF
        test_cmp expect actual
 '
 
-test_expect_success '0-length read, copy null byte' '
-       printf "%s\n" "" Q | q_to_nul >expect &&
+test_expect_success 'read null byte' '
+       echo ">QhelloQ" | q_to_nul >expect &&
        q_to_nul <<-\EOF | test-line-buffer >actual &&
-       read 0
-
-       copy 1
-       Q
+       binary 8
+       QhelloQ
        EOF
        test_cmp expect actual
 '
 
 test_expect_success 'long reads are truncated' '
-       printf "%s\n" foo "" >expect &&
+       echo ">foo" >expect &&
        test-line-buffer <<-\EOF >actual &&
-       read 5
+       binary 5
        foo
        EOF
        test_cmp expect actual
 '
 
 test_expect_success 'long copies are truncated' '
-       printf "%s\n" "" foo >expect &&
+       printf "%s\n" ">" foo >expect &&
        test-line-buffer <<-\EOF >actual &&
-       read 0
+       binary 1
 
        copy 5
        foo
@@ -64,4 +78,13 @@ test_expect_success 'long copies are truncated' '
        test_cmp expect actual
 '
 
+test_expect_success 'long binary reads are truncated' '
+       echo ">foo" >expect &&
+       test-line-buffer <<-\EOF >actual &&
+       binary 5
+       foo
+       EOF
+       test_cmp expect actual
+'
+
 test_done