2019-02-15 11:11:55 -05:00
|
|
|
import diff from "./diff.ts";
|
2019-03-06 19:42:24 -05:00
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2020-02-11 11:24:27 -05:00
|
|
|
const { test } = Deno;
|
2019-02-15 11:11:55 -05:00
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test({
|
|
|
|
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
|
|
|
});
|