Exemple #1
0
        public static DiffList BuildDiffList(FilesIndex source, FilesIndex target)
        {
            var diffList = new DiffList();

            foreach (var targetInfo in target.Index)
            {
                if (source.Index.TryGetValue(targetInfo.Key, out var record) &&
                    targetInfo.Value.Equals(record) &&
                    !diffList.ReuseFiles.ContainsKey(targetInfo.Key))
                {
                    diffList.ReuseFiles.Add(targetInfo.Key, targetInfo.Key);
                }
                else
                {
                    string?alternativeName = source.GetFileNameByRecord(targetInfo.Value);
                    if (alternativeName != null && !diffList.ReuseFiles.ContainsKey(alternativeName))
                    {
                        diffList.ReuseFiles.Add(alternativeName, targetInfo.Key);
                    }
                    else
                    {
                        diffList.ChangedFiles.Add(targetInfo.Key);
                    }
                }
            }
            foreach (var sourceInfo in source.Index)
            {
                if (!target.Index.ContainsKey(sourceInfo.Key) &&
                    !diffList.ReuseFiles.ContainsKey(sourceInfo.Key))
                {
                    diffList.RemoveFiles.Add(sourceInfo.Key);
                }
            }
            return(diffList);
        }
Exemple #2
0
 public void FromDelta_InvalidInput_Throws()
 {
     var delta = "=x";
     Assert.Throws<ArgumentException>(() => 
         DiffList.FromDelta("", delta).ToList()
     );
 }
Exemple #3
0
 public void FromDelta_GeneratesExpectedDiffs()
 {
     var delta = diffs.ToDelta();
     var result  = DiffList.FromDelta(diffs.Text1(), delta);
     Assert.Equal(diffs, result.ToList());
     
 }
Exemple #4
0
        public void ToDelta_InputTooShort_Throws()
        {
            var delta = diffs.ToDelta();
            var text1 = diffs.Text1().Substring(1);

            DiffList.FromDelta(text1, delta).ToList();
        }
Exemple #5
0
        public void ToDelta_InputTooLong_Throws()
        {
            var delta = diffs.ToDelta();
            var text1 = diffs.Text1() + "x";

            DiffList.FromDelta(text1, delta).ToList();
        }
Exemple #6
0
 public void FromDelta_InputTooLong_Throws()
 {
     var delta = diffs.ToDelta();
     var text1 = diffs.Text1() + "x";
     Assert.Throws<ArgumentException>(() =>
         DiffList.FromDelta(text1, delta).ToList()
     );
 }
        public void ToDelta_InputTooShort_Throws()
        {
            var diffs = new List <Diff>
            {
                Diff.Equal("jump"),
                Diff.Delete("s"),
                Diff.Insert("ed"),
                Diff.Equal(" over "),
                Diff.Delete("the"),
                Diff.Insert("a"),
                Diff.Equal(" lazy"),
                Diff.Insert("old dog")
            };
            var delta = diffs.ToDelta();
            var text1 = diffs.Text1().Substring(1);

            Assert.Throws <ArgumentException>(() => DiffList.FromDelta(text1, delta).ToList());
        }
        public void FromDelta_GeneratesExpectedDiffs()
        {
            var diffs = new List <Diff>
            {
                Diff.Equal("jump"),
                Diff.Delete("s"),
                Diff.Insert("ed"),
                Diff.Equal(" over "),
                Diff.Delete("the"),
                Diff.Insert("a"),
                Diff.Equal(" lazy"),
                Diff.Insert("old dog")
            };
            var delta  = diffs.ToDelta();
            var result = DiffList.FromDelta(diffs.Text1(), delta);

            CollectionAssert.AreEqual(diffs, result.ToList());
        }
        public void Delta_LargeString()
        {
            // 160 kb string.
            var a = "abcdefghij";

            for (var i = 0; i < 14; i++)
            {
                a += a;
            }
            var diffs2 = new List <Diff> {
                Diff.Insert(a)
            };
            var delta = diffs2.ToDelta();

            Assert.AreEqual("+" + a, delta);

            // Convert delta string into a diff.
            CollectionAssert.AreEqual(diffs2, DiffList.FromDelta("", delta).ToList(), "diff_fromDelta: 160kb string.");
        }
        public void Delta_FromUnchangedCharacters_Succeeds()
        {
            // Verify pool of unchanged characters.
            var expected = new List <Diff>
            {
                Diff.Insert("A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # ")
            };
            var text2 = expected.Text2();

            Assert.AreEqual("A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", text2);

            var delta = expected.ToDelta();

            Assert.AreEqual("+A-Z a-z 0-9 - _ . ! ~ * \' ( ) ; / ? : @ & = + $ , # ", delta);

            // Convert delta string into a diff.
            var actual = DiffList.FromDelta("", delta);

            CollectionAssert.AreEqual(expected, actual.ToList(), "diff_fromDelta: Unchanged characters.");
        }
        public void Delta_SpecialCharacters_Works()
        {
            var zero   = (char)0;
            var one    = (char)1;
            var two    = (char)2;
            var diffs2 = new List <Diff>
            {
                Diff.Equal("\u0680 " + zero + " \t %"),
                Diff.Delete("\u0681 " + one + " \n ^"),
                Diff.Insert("\u0682 " + two + " \\ |")
            };
            var text1 = diffs2.Text1();

            Assert.AreEqual("\u0680 " + zero + " \t %\u0681 " + one + " \n ^", text1);

            var delta = diffs2.ToDelta();

            // Lowercase, due to UrlEncode uses lower.
            Assert.AreEqual("=7\t-7\t+%da%82 %02 %5c %7c", delta, "diff_toDelta: Unicode.");

            CollectionAssert.AreEqual(diffs2, DiffList.FromDelta(text1, delta).ToList(), "diff_fromDelta: Unicode.");
        }
Exemple #12
0
 public void FromDelta_EmptyTokensAreOk()
 {
     var delta = "\t\t";
     var diffs = DiffList.FromDelta("", delta);
     Assert.Empty(diffs);
 }
 public void FromDelta_InvalidUnicodeInput_Throws()
 {
     DiffList.FromDelta("", "+%c3%xy").ToList();
 }