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([], []), []);
|
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" },
|
|
|
|
{ type: "added", value: "b" }
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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" }]);
|
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" }]);
|
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" }]);
|
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" },
|
|
|
|
{ type: "added", value: "b" }
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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" },
|
|
|
|
{ type: "removed", value: "h" }
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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" },
|
|
|
|
{ type: "removed", value: "h" }
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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" },
|
|
|
|
{ type: "added", value: "h" }
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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" },
|
|
|
|
{ type: "common", value: "c" }
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|