This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy paththreewaymerge_test.js
188 lines (169 loc) · 6.1 KB
/
threewaymerge_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*global describe:false, it:false */
"use client";
require(["lib/architect/architect", "lib/chai/chai", "/vfs-root", "events", "ace/document"], function(architect, chai, baseProc, events, document) {
var expect = chai.expect;
var Emitter = events.EventEmitter;
var Document = document.Document;
var ev = new Emitter();
// var merge = require("./threewaymerge");
expect.setupArchitectTest([
{
packagePath: "plugins/c9.core/c9",
startdate: new Date(),
debug: true,
hosted: true,
davPrefix: "/",
local: false,
projectName: "Test Project"
},
{
packagePath: "plugins/c9.ide.ui/ui",
staticPrefix: "plugins/c9.ide.ui"
},
"plugins/c9.ide.ui/lib_apf",
{
packagePath: "plugins/c9.fs/fs",
baseProc: baseProc
},
"plugins/c9.core/ext",
"plugins/c9.core/http-xhr",
"plugins/c9.core/util",
"plugins/c9.core/settings",
"plugins/c9.vfs.client/vfs_client",
"plugins/c9.vfs.client/endpoint",
"plugins/c9.ide.auth/auth",
"plugins/c9.core/api",
"plugins/c9.ide.threewaymerge/threewaymerge",
{
consumes: ["threewaymerge", "fs"],
provides: [],
setup: main
}
], architect);
function main(options, imports, register) {
var merge = imports.threewaymerge;
var fs = imports.fs;
describe('threewaymerge', function() {
it("should patch remote changes changes", function(done) {
var root = "Hello World";
var theirs = "Hello Peter";
var ours = new Document(root);
merge.merge(root, theirs, ours);
expect(ours.getValue()).equal("Hello Peter");
done();
});
it("should patch remote with local changes", function(done) {
var root = "Hello World";
var theirs = "Hello World";
var ours = new Document("Hello Max");
merge.merge(root, theirs, ours);
expect(ours.getValue()).equal("Hello Max");
done();
});
it("should patch against both changes", function(done) {
var root = "Hello World";
var theirs = "Hello Peter";
var ours = new Document("Hallo World");
merge.merge(root, theirs, ours);
expect(ours.getValue()).equal("Hallo Peter");
done();
});
it("should patch multi-lines documents against changes", function(done) {
var root = [
"Hello Peter",
"abcdefg",
"o my god"
].join("\n");
var theirs = [
"Hello Max",
"abcdefg",
"bla bla",
"o my god"
].join("\n");
var ours = new Document([
"Hello Paul",
"abcdefg",
"o my"
]);
merge.merge(root, theirs, ours);
expect(ours.getValue()).equal([
"<<<<<<<<< saved version",
"Hello Max",
"=========",
"Hello Paul",
">>>>>>>>> local version",
"abcdefg",
"bla bla",
"o my"
].join("\n")
);
done();
});
it("should patch both changes with conflicts", function(done) {
var root = "Hello World";
var theirs = "Hello Peter";
var ours = new Document("Hello Max");
merge.merge(root, theirs, ours);
expect(ours.getValue()).equal([
"<<<<<<<<< saved version",
"Hello Peter",
"=========",
"Hello Max",
">>>>>>>>> local version"].join("\n")
);
done();
});
it("should not remove all listeners", function(done) {
var root = [
"Hello Peter",
"abcdefg",
"o my god"
].join("\n");
var theirs = [
"Hello Max",
"abcdefg",
"bla bla",
"o my god"
].join("\n");
var ours = [
"Hello Paul",
"abcdefg",
"o my"
].join("\n");
var merged = merge.diff3(theirs, root, ours);
expect(merged).equal([
"<<<<<<<<< saved version",
"Hello Max",
"=========",
"Hello Paul",
">>>>>>>>> local version",
"abcdefg",
"bla bla",
"o my"
].join("\n")
);
done();
});
it("should patch ace document", function(done) {
var value = "Juhu kinners";
var newValue = "Juhu max";
var doc = new Document(value);
merge.patchAce(value, newValue, doc);
expect(newValue).equal(doc.getValue());
done();
});
it("should patch bigger file", function(done) {
fs.readFile("/file.js", function (err, value) {
var doc = new Document(value);
var newValue = value.replace(/function/g, "def");
console.time("patch");
merge.patchAce(value, newValue, doc);
console.timeEnd("patch");
expect(newValue).equal(doc.getValue());
done();
});
});
});
onload();
}
});