t / t4033-diff-patience.shon commit gitweb: do not misparse nonnumeric content tag files that contain a digit (2c162b5)
   1#!/bin/sh
   2
   3test_description='patience diff algorithm'
   4
   5. ./test-lib.sh
   6
   7cat >file1 <<\EOF
   8#include <stdio.h>
   9
  10// Frobs foo heartily
  11int frobnitz(int foo)
  12{
  13    int i;
  14    for(i = 0; i < 10; i++)
  15    {
  16        printf("Your answer is: ");
  17        printf("%d\n", foo);
  18    }
  19}
  20
  21int fact(int n)
  22{
  23    if(n > 1)
  24    {
  25        return fact(n-1) * n;
  26    }
  27    return 1;
  28}
  29
  30int main(int argc, char **argv)
  31{
  32    frobnitz(fact(10));
  33}
  34EOF
  35
  36cat >file2 <<\EOF
  37#include <stdio.h>
  38
  39int fib(int n)
  40{
  41    if(n > 2)
  42    {
  43        return fib(n-1) + fib(n-2);
  44    }
  45    return 1;
  46}
  47
  48// Frobs foo heartily
  49int frobnitz(int foo)
  50{
  51    int i;
  52    for(i = 0; i < 10; i++)
  53    {
  54        printf("%d\n", foo);
  55    }
  56}
  57
  58int main(int argc, char **argv)
  59{
  60    frobnitz(fib(10));
  61}
  62EOF
  63
  64cat >expect <<\EOF
  65diff --git a/file1 b/file2
  66index 6faa5a3..e3af329 100644
  67--- a/file1
  68+++ b/file2
  69@@ -1,26 +1,25 @@
  70 #include <stdio.h>
  71 
  72+int fib(int n)
  73+{
  74+    if(n > 2)
  75+    {
  76+        return fib(n-1) + fib(n-2);
  77+    }
  78+    return 1;
  79+}
  80+
  81 // Frobs foo heartily
  82 int frobnitz(int foo)
  83 {
  84     int i;
  85     for(i = 0; i < 10; i++)
  86     {
  87-        printf("Your answer is: ");
  88         printf("%d\n", foo);
  89     }
  90 }
  91 
  92-int fact(int n)
  93-{
  94-    if(n > 1)
  95-    {
  96-        return fact(n-1) * n;
  97-    }
  98-    return 1;
  99-}
 100-
 101 int main(int argc, char **argv)
 102 {
 103-    frobnitz(fact(10));
 104+    frobnitz(fib(10));
 105 }
 106EOF
 107
 108test_expect_success 'patience diff' '
 109
 110        test_must_fail git diff --no-index --patience file1 file2 > output &&
 111        test_cmp expect output
 112
 113'
 114
 115test_expect_success 'patience diff output is valid' '
 116
 117        mv file2 expect &&
 118        git apply < output &&
 119        test_cmp expect file2
 120
 121'
 122
 123cat >uniq1 <<\EOF
 1241
 1252
 1263
 1274
 1285
 1296
 130EOF
 131
 132cat >uniq2 <<\EOF
 133a
 134b
 135c
 136d
 137e
 138f
 139EOF
 140
 141cat >expect <<\EOF
 142diff --git a/uniq1 b/uniq2
 143index b414108..0fdf397 100644
 144--- a/uniq1
 145+++ b/uniq2
 146@@ -1,6 +1,6 @@
 147-1
 148-2
 149-3
 150-4
 151-5
 152-6
 153+a
 154+b
 155+c
 156+d
 157+e
 158+f
 159EOF
 160
 161test_expect_success 'completely different files' '
 162
 163        test_must_fail git diff --no-index --patience uniq1 uniq2 > output &&
 164        test_cmp expect output
 165
 166'
 167
 168test_done