Fossil SCM
Add the test-line-diff command for testing the oneLineChange() routine of the diff logic.
Commit
0755a81bb5115b4121a0ccadfaa78960323e1018fca7206fb8670abc976c2809
Parent
4381c7ea8c9873d…
1 file changed
+51
+51
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -707,10 +707,61 @@ | ||
| 707 | 707 | p->a[0].iStart1 = nPrefix; |
| 708 | 708 | p->a[0].iLen1 = nLeft - nCommon; |
| 709 | 709 | p->a[0].iStart2 = nPrefix; |
| 710 | 710 | p->a[0].iLen2 = nRight - nCommon; |
| 711 | 711 | } |
| 712 | + | |
| 713 | +/* | |
| 714 | +** COMMAND: test-line-diff | |
| 715 | +** Usage: %fossil% test-line-diff STRING1 STRING2 | |
| 716 | +** | |
| 717 | +** Show the differences between the two strings. Used for testing | |
| 718 | +** the oneLineChange() routine in the diff logic. | |
| 719 | +*/ | |
| 720 | +void test_line_diff(void){ | |
| 721 | + DLine a, b; | |
| 722 | + ChangeSpan span; | |
| 723 | + int i, j, x; | |
| 724 | + if( g.argc!=4 ) usage("STRING1 STRING2"); | |
| 725 | + a.z = g.argv[2]; | |
| 726 | + a.n = (int)strlen(a.z); | |
| 727 | + b.z = g.argv[3]; | |
| 728 | + b.n = (int)strlen(b.z); | |
| 729 | + oneLineChange(&a, &b, &span); | |
| 730 | + fossil_print("left: [%s]\n", a.z); | |
| 731 | + for(i=x=0; i<span.n; i++){ | |
| 732 | + int ofst = span.a[i].iStart1; | |
| 733 | + int len = span.a[i].iLen1; | |
| 734 | + if( len ){ | |
| 735 | + if( x==0 ){ fossil_print("%*s", 8, ""); } | |
| 736 | + while( ofst > x ){ | |
| 737 | + if( (a.z[x]&0xc0)!=0x80 ) fossil_print(" "); | |
| 738 | + x++; | |
| 739 | + } | |
| 740 | + for(j=0; j<len; j++, x++){ | |
| 741 | + if( (a.z[x]&0xc0)!=0x80 ) fossil_print("%d",i); | |
| 742 | + } | |
| 743 | + } | |
| 744 | + } | |
| 745 | + if( x ) fossil_print("\n"); | |
| 746 | + fossil_print("right: [%s]\n", b.z); | |
| 747 | + for(i=x=0; i<span.n; i++){ | |
| 748 | + int ofst = span.a[i].iStart2; | |
| 749 | + int len = span.a[i].iLen2; | |
| 750 | + if( len ){ | |
| 751 | + if( x==0 ){ fossil_print("%*s", 8, ""); } | |
| 752 | + while( ofst > x ){ | |
| 753 | + if( (b.z[x]&0xc0)!=0x80 ) fossil_print(" "); | |
| 754 | + x++; | |
| 755 | + } | |
| 756 | + for(j=0; j<len; j++, x++){ | |
| 757 | + if( (b.z[x]&0xc0)!=0x80 ) fossil_print("%d",i); | |
| 758 | + } | |
| 759 | + } | |
| 760 | + } | |
| 761 | + if( x ) fossil_print("\n"); | |
| 762 | +} | |
| 712 | 763 | |
| 713 | 764 | /* |
| 714 | 765 | ** Minimum of two values |
| 715 | 766 | */ |
| 716 | 767 | static int minInt(int a, int b){ return a<b ? a : b; } |
| 717 | 768 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -707,10 +707,61 @@ | |
| 707 | p->a[0].iStart1 = nPrefix; |
| 708 | p->a[0].iLen1 = nLeft - nCommon; |
| 709 | p->a[0].iStart2 = nPrefix; |
| 710 | p->a[0].iLen2 = nRight - nCommon; |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | ** Minimum of two values |
| 715 | */ |
| 716 | static int minInt(int a, int b){ return a<b ? a : b; } |
| 717 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -707,10 +707,61 @@ | |
| 707 | p->a[0].iStart1 = nPrefix; |
| 708 | p->a[0].iLen1 = nLeft - nCommon; |
| 709 | p->a[0].iStart2 = nPrefix; |
| 710 | p->a[0].iLen2 = nRight - nCommon; |
| 711 | } |
| 712 | |
| 713 | /* |
| 714 | ** COMMAND: test-line-diff |
| 715 | ** Usage: %fossil% test-line-diff STRING1 STRING2 |
| 716 | ** |
| 717 | ** Show the differences between the two strings. Used for testing |
| 718 | ** the oneLineChange() routine in the diff logic. |
| 719 | */ |
| 720 | void test_line_diff(void){ |
| 721 | DLine a, b; |
| 722 | ChangeSpan span; |
| 723 | int i, j, x; |
| 724 | if( g.argc!=4 ) usage("STRING1 STRING2"); |
| 725 | a.z = g.argv[2]; |
| 726 | a.n = (int)strlen(a.z); |
| 727 | b.z = g.argv[3]; |
| 728 | b.n = (int)strlen(b.z); |
| 729 | oneLineChange(&a, &b, &span); |
| 730 | fossil_print("left: [%s]\n", a.z); |
| 731 | for(i=x=0; i<span.n; i++){ |
| 732 | int ofst = span.a[i].iStart1; |
| 733 | int len = span.a[i].iLen1; |
| 734 | if( len ){ |
| 735 | if( x==0 ){ fossil_print("%*s", 8, ""); } |
| 736 | while( ofst > x ){ |
| 737 | if( (a.z[x]&0xc0)!=0x80 ) fossil_print(" "); |
| 738 | x++; |
| 739 | } |
| 740 | for(j=0; j<len; j++, x++){ |
| 741 | if( (a.z[x]&0xc0)!=0x80 ) fossil_print("%d",i); |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | if( x ) fossil_print("\n"); |
| 746 | fossil_print("right: [%s]\n", b.z); |
| 747 | for(i=x=0; i<span.n; i++){ |
| 748 | int ofst = span.a[i].iStart2; |
| 749 | int len = span.a[i].iLen2; |
| 750 | if( len ){ |
| 751 | if( x==0 ){ fossil_print("%*s", 8, ""); } |
| 752 | while( ofst > x ){ |
| 753 | if( (b.z[x]&0xc0)!=0x80 ) fossil_print(" "); |
| 754 | x++; |
| 755 | } |
| 756 | for(j=0; j<len; j++, x++){ |
| 757 | if( (b.z[x]&0xc0)!=0x80 ) fossil_print("%d",i); |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | if( x ) fossil_print("\n"); |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | ** Minimum of two values |
| 766 | */ |
| 767 | static int minInt(int a, int b){ return a<b ? a : b; } |
| 768 |