2020-09-21 08:26:41 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-10-01 13:15:05 -04:00
|
|
|
import { diff } from "./_diff.ts";
|
2019-03-06 19:42:24 -05:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2019-02-15 11:11:55 -05:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: "empty",
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff([], []), []);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"a" vs "b"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(["a"], ["b"]), [
|
2019-02-15 11:11:55 -05:00
|
|
|
{ type: "removed", value: "a" },
|
2020-03-28 13:03:49 -04:00
|
|
|
{ type: "added", value: "b" },
|
2019-02-15 11:11:55 -05:00
|
|
|
]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"a" vs "a"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(["a"], ["a"]), [{ type: "common", value: "a" }]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"a" vs ""',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(["a"], []), [{ type: "removed", value: "a" }]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"" vs "a"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff([], ["a"]), [{ type: "added", value: "a" }]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"a" vs "a, b"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(["a"], ["a", "b"]), [
|
2019-02-15 11:11:55 -05:00
|
|
|
{ type: "common", value: "a" },
|
2020-03-28 13:03:49 -04:00
|
|
|
{ type: "added", value: "b" },
|
2019-02-15 11:11:55 -05:00
|
|
|
]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"strength" vs "string"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(Array.from("strength"), Array.from("string")), [
|
2019-02-15 11:11:55 -05:00
|
|
|
{ type: "common", value: "s" },
|
|
|
|
{ type: "common", value: "t" },
|
|
|
|
{ type: "common", value: "r" },
|
|
|
|
{ type: "removed", value: "e" },
|
|
|
|
{ type: "added", value: "i" },
|
|
|
|
{ type: "common", value: "n" },
|
|
|
|
{ type: "common", value: "g" },
|
|
|
|
{ type: "removed", value: "t" },
|
2020-03-28 13:03:49 -04:00
|
|
|
{ type: "removed", value: "h" },
|
2019-02-15 11:11:55 -05:00
|
|
|
]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"strength" vs ""',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(Array.from("strength"), Array.from("")), [
|
2019-02-15 11:11:55 -05:00
|
|
|
{ type: "removed", value: "s" },
|
|
|
|
{ type: "removed", value: "t" },
|
|
|
|
{ type: "removed", value: "r" },
|
|
|
|
{ type: "removed", value: "e" },
|
|
|
|
{ type: "removed", value: "n" },
|
|
|
|
{ type: "removed", value: "g" },
|
|
|
|
{ type: "removed", value: "t" },
|
2020-03-28 13:03:49 -04:00
|
|
|
{ type: "removed", value: "h" },
|
2019-02-15 11:11:55 -05:00
|
|
|
]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"" vs "strength"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(Array.from(""), Array.from("strength")), [
|
2019-02-15 11:11:55 -05:00
|
|
|
{ type: "added", value: "s" },
|
|
|
|
{ type: "added", value: "t" },
|
|
|
|
{ type: "added", value: "r" },
|
|
|
|
{ type: "added", value: "e" },
|
|
|
|
{ type: "added", value: "n" },
|
|
|
|
{ type: "added", value: "g" },
|
|
|
|
{ type: "added", value: "t" },
|
2020-03-28 13:03:49 -04:00
|
|
|
{ type: "added", value: "h" },
|
2019-02-15 11:11:55 -05:00
|
|
|
]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-02-15 11:11:55 -05:00
|
|
|
name: '"abc", "c" vs "abc", "bcd", "c"',
|
2019-04-24 07:41:23 -04:00
|
|
|
fn(): void {
|
2019-03-06 19:42:24 -05:00
|
|
|
assertEquals(diff(["abc", "c"], ["abc", "bcd", "c"]), [
|
2019-02-15 11:11:55 -05:00
|
|
|
{ type: "common", value: "abc" },
|
|
|
|
{ type: "added", value: "bcd" },
|
2020-03-28 13:03:49 -04:00
|
|
|
{ type: "common", value: "c" },
|
2019-02-15 11:11:55 -05:00
|
|
|
]);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-02-15 11:11:55 -05:00
|
|
|
});
|