tests/test-diff-indent-heuristic.t
changeset 36678 7834927f0243
child 49621 55c6ebd11cb9
equal deleted inserted replaced
36677:a247a0e82e7d 36678:7834927f0243
       
     1 #testcases bdiff xdiff
       
     2 
       
     3 #if xdiff
       
     4 #require xdiff
       
     5   $ cat >> $HGRCPATH <<EOF
       
     6   > [experimental]
       
     7   > xdiff = true
       
     8   > EOF
       
     9 #endif
       
    10 
       
    11   $ hg init
       
    12 
       
    13   $ cat > a.c <<'EOF'
       
    14   > /*
       
    15   >  * This function returns 1.
       
    16   >  */
       
    17   > int f() {
       
    18   >   return 1;
       
    19   > }
       
    20   > /*
       
    21   >  * This function returns 2.
       
    22   >  */
       
    23   > int g() {
       
    24   >   return 2;
       
    25   > }
       
    26   > /*
       
    27   >  * This function returns 3.
       
    28   >  */
       
    29   > int h() {
       
    30   >   return 3;
       
    31   > }
       
    32   > EOF
       
    33 
       
    34   $ cat > b.c <<'EOF'
       
    35   > if (x) {
       
    36   >    do_something();
       
    37   > }
       
    38   > 
       
    39   > if (y) {
       
    40   >    do_something_else();
       
    41   > }
       
    42   > EOF
       
    43 
       
    44   $ cat > c.rb <<'EOF'
       
    45   > #!ruby
       
    46   > ["foo", "bar", "baz"].map do |i|
       
    47   >   i.upcase
       
    48   > end
       
    49   > EOF
       
    50 
       
    51   $ cat > d.py <<'EOF'
       
    52   > try:
       
    53   >     import foo
       
    54   > except ImportError:
       
    55   >     pass
       
    56   > try:
       
    57   >     import bar
       
    58   > except ImportError:
       
    59   >     pass
       
    60   > EOF
       
    61 
       
    62 The below two files are taken from git: t/t4061-diff-indent.sh
       
    63 
       
    64   $ cat > spaces.txt <<'EOF'
       
    65   > 1
       
    66   > 2
       
    67   > a
       
    68   > 
       
    69   > b
       
    70   > 3
       
    71   > 4
       
    72   > EOF
       
    73 
       
    74   $ cat > functions.c <<'EOF'
       
    75   > 1
       
    76   > 2
       
    77   > /* function */
       
    78   > foo() {
       
    79   >     foo
       
    80   > }
       
    81   > 
       
    82   > 3
       
    83   > 4
       
    84   > EOF
       
    85 
       
    86   $ hg commit -m 1 -A . -q
       
    87 
       
    88   $ cat > a.c <<'EOF'
       
    89   > /*
       
    90   >  * This function returns 1.
       
    91   >  */
       
    92   > int f() {
       
    93   >   return 1;
       
    94   > }
       
    95   > /*
       
    96   >  * This function returns 3.
       
    97   >  */
       
    98   > int h() {
       
    99   >   return 3;
       
   100   > }
       
   101   > EOF
       
   102 
       
   103   $ cat > b.c <<'EOF'
       
   104   > if (x) {
       
   105   >    do_something();
       
   106   > }
       
   107   > 
       
   108   > if (y) {
       
   109   >    do_another_thing();
       
   110   > }
       
   111   > 
       
   112   > if (y) {
       
   113   >    do_something_else();
       
   114   > }
       
   115   > EOF
       
   116 
       
   117   $ cat > c.rb <<'EOF'
       
   118   > #!ruby
       
   119   > ["foo", "bar", "baz"].map do |i|
       
   120   >   i
       
   121   > end
       
   122   > ["foo", "bar", "baz"].map do |i|
       
   123   >   i.upcase
       
   124   > end
       
   125   > EOF
       
   126 
       
   127   $ cat > d.py <<'EOF'
       
   128   > try:
       
   129   >     import foo
       
   130   > except ImportError:
       
   131   >     pass
       
   132   > try:
       
   133   >     import baz
       
   134   > except ImportError:
       
   135   >     pass
       
   136   > try:
       
   137   >     import bar
       
   138   > except ImportError:
       
   139   >     pass
       
   140   > EOF
       
   141 
       
   142   $ cat > spaces.txt <<'EOF'
       
   143   > 1
       
   144   > 2
       
   145   > a
       
   146   > 
       
   147   > b
       
   148   > a
       
   149   > 
       
   150   > b
       
   151   > 3
       
   152   > 4
       
   153   > EOF
       
   154 
       
   155   $ cat > functions.c <<'EOF'
       
   156   > 1
       
   157   > 2
       
   158   > /* function */
       
   159   > bar() {
       
   160   >     foo
       
   161   > }
       
   162   > 
       
   163   > /* function */
       
   164   > foo() {
       
   165   >     foo
       
   166   > }
       
   167   > 
       
   168   > 3
       
   169   > 4
       
   170   > EOF
       
   171 
       
   172 #if xdiff
       
   173   $ hg diff --git
       
   174   diff --git a/a.c b/a.c
       
   175   --- a/a.c
       
   176   +++ b/a.c
       
   177   @@ -4,12 +4,6 @@
       
   178    int f() {
       
   179      return 1;
       
   180    }
       
   181   -/*
       
   182   - * This function returns 2.
       
   183   - */
       
   184   -int g() {
       
   185   -  return 2;
       
   186   -}
       
   187    /*
       
   188     * This function returns 3.
       
   189     */
       
   190   diff --git a/b.c b/b.c
       
   191   --- a/b.c
       
   192   +++ b/b.c
       
   193   @@ -2,6 +2,10 @@
       
   194       do_something();
       
   195    }
       
   196    
       
   197   +if (y) {
       
   198   +   do_another_thing();
       
   199   +}
       
   200   +
       
   201    if (y) {
       
   202       do_something_else();
       
   203    }
       
   204   diff --git a/c.rb b/c.rb
       
   205   --- a/c.rb
       
   206   +++ b/c.rb
       
   207   @@ -1,4 +1,7 @@
       
   208    #!ruby
       
   209   +["foo", "bar", "baz"].map do |i|
       
   210   +  i
       
   211   +end
       
   212    ["foo", "bar", "baz"].map do |i|
       
   213      i.upcase
       
   214    end
       
   215   diff --git a/d.py b/d.py
       
   216   --- a/d.py
       
   217   +++ b/d.py
       
   218   @@ -2,6 +2,10 @@
       
   219        import foo
       
   220    except ImportError:
       
   221        pass
       
   222   +try:
       
   223   +    import baz
       
   224   +except ImportError:
       
   225   +    pass
       
   226    try:
       
   227        import bar
       
   228    except ImportError:
       
   229   diff --git a/functions.c b/functions.c
       
   230   --- a/functions.c
       
   231   +++ b/functions.c
       
   232   @@ -1,5 +1,10 @@
       
   233    1
       
   234    2
       
   235   +/* function */
       
   236   +bar() {
       
   237   +    foo
       
   238   +}
       
   239   +
       
   240    /* function */
       
   241    foo() {
       
   242        foo
       
   243   diff --git a/spaces.txt b/spaces.txt
       
   244   --- a/spaces.txt
       
   245   +++ b/spaces.txt
       
   246   @@ -2,6 +2,9 @@
       
   247    2
       
   248    a
       
   249    
       
   250   +b
       
   251   +a
       
   252   +
       
   253    b
       
   254    3
       
   255    4
       
   256 #else
       
   257   $ hg diff --git
       
   258   diff --git a/a.c b/a.c
       
   259   --- a/a.c
       
   260   +++ b/a.c
       
   261   @@ -5,12 +5,6 @@
       
   262      return 1;
       
   263    }
       
   264    /*
       
   265   - * This function returns 2.
       
   266   - */
       
   267   -int g() {
       
   268   -  return 2;
       
   269   -}
       
   270   -/*
       
   271     * This function returns 3.
       
   272     */
       
   273    int h() {
       
   274   diff --git a/b.c b/b.c
       
   275   --- a/b.c
       
   276   +++ b/b.c
       
   277   @@ -3,5 +3,9 @@
       
   278    }
       
   279    
       
   280    if (y) {
       
   281   +   do_another_thing();
       
   282   +}
       
   283   +
       
   284   +if (y) {
       
   285       do_something_else();
       
   286    }
       
   287   diff --git a/c.rb b/c.rb
       
   288   --- a/c.rb
       
   289   +++ b/c.rb
       
   290   @@ -1,4 +1,7 @@
       
   291    #!ruby
       
   292    ["foo", "bar", "baz"].map do |i|
       
   293   +  i
       
   294   +end
       
   295   +["foo", "bar", "baz"].map do |i|
       
   296      i.upcase
       
   297    end
       
   298   diff --git a/d.py b/d.py
       
   299   --- a/d.py
       
   300   +++ b/d.py
       
   301   @@ -3,6 +3,10 @@
       
   302    except ImportError:
       
   303        pass
       
   304    try:
       
   305   +    import baz
       
   306   +except ImportError:
       
   307   +    pass
       
   308   +try:
       
   309        import bar
       
   310    except ImportError:
       
   311        pass
       
   312   diff --git a/functions.c b/functions.c
       
   313   --- a/functions.c
       
   314   +++ b/functions.c
       
   315   @@ -1,6 +1,11 @@
       
   316    1
       
   317    2
       
   318    /* function */
       
   319   +bar() {
       
   320   +    foo
       
   321   +}
       
   322   +
       
   323   +/* function */
       
   324    foo() {
       
   325        foo
       
   326    }
       
   327   diff --git a/spaces.txt b/spaces.txt
       
   328   --- a/spaces.txt
       
   329   +++ b/spaces.txt
       
   330   @@ -3,5 +3,8 @@
       
   331    a
       
   332    
       
   333    b
       
   334   +a
       
   335   +
       
   336   +b
       
   337    3
       
   338    4
       
   339 #endif