示例#1
0
        public void TestUnifiedDiffParsing_AddedRemoved()
        {
            string inputA =
                "This is a test file!\n" +
                "Added another line to test file\n" +
                "Adding a third line to test file";

            string inputB =
                "This is a test file!\n" +
                "Adding a third line to test file\n" +
                "Adding a fourth line to test file";

            List <Diff.Diff> diff      = DiffFactory.GenerateDiffCache(inputA, inputB);
            DiffTextModel    textModel = DiffFactory.GenerateUnifiedDiff(diff);

            Assert.IsTrue(textModel.LineCount == 5);

            DiffTextLine removedLine = textModel.GetLine(1) as DiffTextLine;

            Assert.IsTrue(removedLine.ToString() == "Added another line to test file");
            Assert.IsTrue(removedLine.BeforeLineNo == 2);
            Assert.IsTrue(removedLine.ChangeType == DiffLineType.Remove);

            DiffTextLine addedLine = textModel.GetLine(3) as DiffTextLine;

            Assert.IsTrue(addedLine.ToString() == "Adding a third line to test file");
            Assert.IsTrue(addedLine.BeforeLineNo == -1);
            Assert.IsTrue(addedLine.LineNo == 2);
            Assert.IsTrue(addedLine.ChangeType == DiffLineType.Insert);
        }
示例#2
0
        public static async Task <List <Diff> > GenerateDiffCache(string fileA, string fileB)
        {
            if (string.IsNullOrEmpty(fileA) || string.IsNullOrEmpty(fileB))
            {
                return(new List <Diff>());
            }

            fileA = fileA.Replace("/", "\\");
            fileB = fileB.Replace("/", "\\");

            var fileAFolder = await StorageFolder.GetFolderFromPathAsync(
                fileA.Substring(0, fileA.LastIndexOf('\\')));

            var fileBFolder = await StorageFolder.GetFolderFromPathAsync(
                fileB.Substring(0, fileB.LastIndexOf('\\')));

            var fileAFile = await fileAFolder.GetFileAsync(FileHelper.GetFileName(fileA));

            var fileBFile = await fileBFolder.GetFileAsync(FileHelper.GetFileName(fileB));

            var fileAText = await Windows.Storage.FileIO.ReadTextAsync(fileAFile);

            var fileBText = await Windows.Storage.FileIO.ReadTextAsync(fileBFile);

            fileAText = fileAText.Replace("\r\n", "\n");
            fileBText = fileBText.Replace("\r\n", "\n");

            return(DiffFactory.GenerateDiffCache(fileAText, fileBText));
        }
示例#3
0
        public void TestSplitDiffParsing()
        {
            string inputA =
                "This is a test file!\n" +
                "Added another line to test file\n" +
                "Adding a third line to test file";

            string inputB =
                "This is a test file!\n" +
                "Added another line to test file\n" +
                "Adding a third line to test file\n" +
                "Adding a fourth line to test file";

            List <Diff.Diff> diff      = DiffFactory.GenerateDiffCache(inputA, inputB);
            SplitDiffModel   splitDiff = DiffFactory.GenerateSplitDiff(diff);

            Assert.IsTrue(splitDiff.SideA.LineCount == 3);
            Assert.IsTrue(splitDiff.SideB.LineCount == 4);

            DiffTextLine addedLine = splitDiff.SideB.GetLine(3) as DiffTextLine;

            Assert.IsTrue(addedLine.BeforeLineNo == -1);
            Assert.IsTrue(addedLine.LineNo == 4);
            Assert.IsTrue(addedLine.ChangeType == DiffLineType.Insert);
        }