summaryrefslogtreecommitdiff
path: root/testing/diff.ts
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-03-05 20:58:28 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-05 14:58:28 -0500
commit787207f11bfcd657b93b47f2ffeb457cdd6f4eb0 (patch)
treeac71143a059261805d4c5750a7254583714397d7 /testing/diff.ts
parent39fde3a454b6bcc7daa6bca4fb7f4317550e9e58 (diff)
Refactor asserts in testing (denoland/deno_std#227)
Original: https://github.com/denoland/deno_std/commit/c734e3234322cea5298a887373fe4ad1591d7c97
Diffstat (limited to 'testing/diff.ts')
-rw-r--r--testing/diff.ts22
1 files changed, 13 insertions, 9 deletions
diff --git a/testing/diff.ts b/testing/diff.ts
index 4fab75e4a..e951032f5 100644
--- a/testing/diff.ts
+++ b/testing/diff.ts
@@ -4,7 +4,11 @@ interface FarthestPoint {
id: number;
}
-export type DiffType = "removed" | "common" | "added";
+export enum DiffType {
+ removed = "removed",
+ common = "common",
+ added = "added"
+}
export interface DiffResult<T> {
type: DiffType;
@@ -50,12 +54,12 @@ export default function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
if (!M && !N && !suffixCommon.length && !prefixCommon.length) return [];
if (!N) {
return [
- ...prefixCommon.map(c => ({ type: "common" as DiffType, value: c })),
+ ...prefixCommon.map(c => ({ type: DiffType.common, value: c })),
...A.map(a => ({
- type: (swapped ? "added" : "removed") as DiffType,
+ type: swapped ? DiffType.added : DiffType.removed,
value: a
})),
- ...suffixCommon.map(c => ({ type: "common" as DiffType, value: c }))
+ ...suffixCommon.map(c => ({ type: DiffType.common, value: c }))
];
}
const offset = N;
@@ -91,18 +95,18 @@ export default function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
const prev = j;
if (type === REMOVED) {
result.unshift({
- type: (swapped ? "removed" : "added") as DiffType,
+ type: swapped ? DiffType.removed : DiffType.added,
value: B[b]
});
b -= 1;
} else if (type === ADDED) {
result.unshift({
- type: (swapped ? "added" : "removed") as DiffType,
+ type: swapped ? DiffType.added : DiffType.removed,
value: A[a]
});
a -= 1;
} else {
- result.unshift({ type: "common" as DiffType, value: A[a] });
+ result.unshift({ type: DiffType.common, value: A[a] });
a -= 1;
b -= 1;
}
@@ -194,8 +198,8 @@ export default function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
);
}
return [
- ...prefixCommon.map(c => ({ type: "common" as DiffType, value: c })),
+ ...prefixCommon.map(c => ({ type: DiffType.common, value: c })),
...backTrace(A, B, fp[delta + offset], swapped),
- ...suffixCommon.map(c => ({ type: "common" as DiffType, value: c }))
+ ...suffixCommon.map(c => ({ type: DiffType.common, value: c }))
];
}