예제 #1
0
        public void DiffCleanupSemanticLosslessTest()
        {
            diff_match_patchTest dmp = new diff_match_patchTest();
              // Slide diffs to match logical boundaries.
              // Null case.
              List<Diff> diffs = new List<Diff>();
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff>(), diffs);

              // Blank lines.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "AAA\r\n\r\nBBB"),
              new Diff(Operation.INSERT, "\r\nDDD\r\n\r\nBBB"),
              new Diff(Operation.EQUAL, "\r\nEEE")
              };
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "AAA\r\n\r\n"),
              new Diff(Operation.INSERT, "BBB\r\nDDD\r\n\r\n"),
              new Diff(Operation.EQUAL, "BBB\r\nEEE")}, diffs);

              // Line boundaries.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "AAA\r\nBBB"),
              new Diff(Operation.INSERT, " DDD\r\nBBB"),
              new Diff(Operation.EQUAL, " EEE")};
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "AAA\r\n"),
              new Diff(Operation.INSERT, "BBB DDD\r\n"),
              new Diff(Operation.EQUAL, "BBB EEE")}, diffs);

              // Word boundaries.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "The c"),
              new Diff(Operation.INSERT, "ow and the c"),
              new Diff(Operation.EQUAL, "at.")};
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "The "),
              new Diff(Operation.INSERT, "cow and the "),
              new Diff(Operation.EQUAL, "cat.")}, diffs);

              // Alphanumeric boundaries.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "The-c"),
              new Diff(Operation.INSERT, "ow-and-the-c"),
              new Diff(Operation.EQUAL, "at.")};
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "The-"),
              new Diff(Operation.INSERT, "cow-and-the-"),
              new Diff(Operation.EQUAL, "cat.")}, diffs);

              // Hitting the start.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "a"),
              new Diff(Operation.DELETE, "a"),
              new Diff(Operation.EQUAL, "ax")};
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.DELETE, "a"),
              new Diff(Operation.EQUAL, "aax")}, diffs);

              // Hitting the end.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "xa"),
              new Diff(Operation.DELETE, "a"),
              new Diff(Operation.EQUAL, "a")};
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "xaa"),
              new Diff(Operation.DELETE, "a")}, diffs);

              // Sentence boundaries.
              diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "The xxx. The "),
              new Diff(Operation.INSERT, "zzz. The "),
              new Diff(Operation.EQUAL, "yyy.")};
              dmp.DiffCleanupSemanticLossless(diffs);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "The xxx."),
              new Diff(Operation.INSERT, " The zzz."),
              new Diff(Operation.EQUAL, " The yyy.")}, diffs);
        }