-
Notifications
You must be signed in to change notification settings - Fork 0
/
Patch.test.js
81 lines (65 loc) · 2.45 KB
/
Patch.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { test } = require("gunit");
const { Patch } = require("./Patch");
test("diffs", t => {
var $ = JSON.stringify;
var x = '{ foo: "bar", baz: "qux" }';
var y = '{ foo: "barrister", baz: "qux" }';
t.is($(Patch.diff(x, y)), $([0, 11, "rister", 11]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux" }';
y = '{ foo: "barrister", baz: "quxster" }';
t.is($(Patch.diff(x, y)), $([0, 11, "rister", 11, 23, "ster", 23]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux" }';
y = '{ foo: "bar" }';
t.is($(Patch.diff(x, y)), $([0, 12, 24]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar" }';
y = '{ foo: "jar" }';
t.is($(Patch.diff(x, y)), $([0, 8, "j", 9]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux" }';
y = '{ foo: "bar", baz: "qux" }';
t.is($(Patch.diff(x, y)), $([0]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux" }';
y = "";
t.is($(Patch.diff(x, y)), $([]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux" ';
y = '{ foo: "bar", baz: "qux" }';
t.is($(Patch.diff(x, y)), $([0, "}"]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux" }';
y = '{ foo: "bar", baz: "qux" ';
t.is($(Patch.diff(x, y)), $([0, 25]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = "{";
y = '{ foo: "bar", baz: "qux" }';
t.is($(Patch.diff(x, y)), $(['{ foo: "bar", baz: "qux" }']));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = "";
y = '{ foo: "bar", baz: "qux" }';
t.is($(Patch.diff(x, y)), $(['{ foo: "bar", baz: "qux" }']));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "", baz: "qux" }';
y = '{ foo: "bar", abc: "xyz", baz: "" }';
t.is($(Patch.diff(x, y)), $([0, 8, 'bar", abc: "xyz', 8, 17, 20]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar", baz: "qux", abc: "xyz" }';
y = '{ foo: "bar", abc: "xyz" }';
t.is($(Patch.diff(x, y)), $([0, 14, 26]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = "renice";
y = "renie";
t.is($(Patch.diff(x, y)), $([0, 4, 5]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bad", baz: "qux" }';
y = '{ foo: "bark", baz: "qux" }';
t.is($(Patch.diff(x, y)), $([0, 10, "rk", 11]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
x = '{ foo: "bar" }';
y = ' foo: "bar" }';
t.is($(Patch.diff(x, y)), $([1]));
t.is(Patch.apply(x, Patch.diff(x, y)), y);
});