easy-richtextarea 4.0.34 → 4.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example.js +93 -1563
- package/lib/browser.js +1 -37
- package/lib/main.js +4 -45
- package/lib/mixins/event.js +11 -10
- package/lib/richTextarea.js +31 -156
- package/lib/selection.js +7 -146
- package/package.json +1 -3
- package/src/browser.js +0 -11
- package/src/main.js +0 -12
- package/src/mixins/event.js +3 -4
- package/src/richTextarea.js +22 -239
- package/src/selection.js +4 -154
- package/lib/constants.js +0 -22
- package/lib/contentCompare.js +0 -34
- package/lib/eventTypes.js +0 -49
- package/lib/keyCodes.js +0 -13
- package/lib/operation/delete.js +0 -290
- package/lib/operation/empty.js +0 -116
- package/lib/operation/insert.js +0 -245
- package/lib/operations/fromJSON.js +0 -40
- package/lib/operations/generate.js +0 -42
- package/lib/operations/toJSON.js +0 -17
- package/lib/transform/content.js +0 -19
- package/lib/transform/operations.js +0 -31
- package/lib/transform/selection.js +0 -19
- package/lib/types.js +0 -34
- package/lib/undoBuffer.js +0 -145
- package/src/constants.js +0 -4
- package/src/contentCompare.js +0 -34
- package/src/eventTypes.js +0 -15
- package/src/keyCodes.js +0 -3
- package/src/operation/delete.js +0 -285
- package/src/operation/empty.js +0 -76
- package/src/operation/insert.js +0 -221
- package/src/operations/fromJSON.js +0 -34
- package/src/operations/generate.js +0 -46
- package/src/operations/toJSON.js +0 -5
- package/src/transform/content.js +0 -11
- package/src/transform/operations.js +0 -57
- package/src/transform/selection.js +0 -11
- package/src/types.js +0 -11
- package/src/undoBuffer.js +0 -119
- package/test/content/transform.js +0 -57
- package/test/helpers.js +0 -91
- package/test/operation/delete.js +0 -390
- package/test/operation/empty.js +0 -101
- package/test/operation/insert.js +0 -306
- package/test/operations/generate.js +0 -78
- package/test/operations/transform.js +0 -69
package/test/operation/insert.js
DELETED
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { assert } = require("chai"),
|
|
4
|
-
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ Selection, EmptyOperation, DeleteOperation, InsertOperation } = require("../../lib/browser"); ///
|
|
6
|
-
|
|
7
|
-
const { first, second } = arrayUtilities;
|
|
8
|
-
|
|
9
|
-
describe("InsertOperation", () => {
|
|
10
|
-
describe("transform", () => {
|
|
11
|
-
it("leaves an empty operation intact", () => {
|
|
12
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("nhTY", 1),
|
|
13
|
-
emptyOperation2 = EmptyOperation.fromNothing(),
|
|
14
|
-
transformedOperations = insertOperation1.transformOperation(emptyOperation2);
|
|
15
|
-
|
|
16
|
-
assert.lengthOf(transformedOperations, 1);
|
|
17
|
-
|
|
18
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
19
|
-
transformedOperation = firstTransformedOperation, ///
|
|
20
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
21
|
-
expectedTransformedOperation = emptyOperation2.clone(),
|
|
22
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
23
|
-
|
|
24
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe("to the left of another insert", () => {
|
|
28
|
-
it("moves the other insert to the right by its own length", () => {
|
|
29
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("iUYHgt", 2),
|
|
30
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("ahBGFRtq", 10),
|
|
31
|
-
transformedOperations = insertOperation1.transformOperation(insertOperation2);
|
|
32
|
-
|
|
33
|
-
assert.lengthOf(transformedOperations, 1);
|
|
34
|
-
|
|
35
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
36
|
-
transformedOperation = firstTransformedOperation, ///
|
|
37
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
38
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("ahBGFRtq", 16),
|
|
39
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
40
|
-
|
|
41
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("at the same position whilst lexicographically less than another insert", () => {
|
|
46
|
-
it("moves the other insert to the right by its own length", () => {
|
|
47
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("acnhJU", 4),
|
|
48
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("xKId", 4),
|
|
49
|
-
transformedOperations = insertOperation1.transformOperation(insertOperation2);
|
|
50
|
-
|
|
51
|
-
assert.lengthOf(transformedOperations, 1);
|
|
52
|
-
|
|
53
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
54
|
-
transformedOperation = firstTransformedOperation, ///
|
|
55
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
56
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("xKId", 10),
|
|
57
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
58
|
-
|
|
59
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe("at the same position whilst lexicographically greater than another insert", () => {
|
|
64
|
-
it("leaves the other insert intact", () => {
|
|
65
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("xcnhJU", 4),
|
|
66
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("aKId", 4),
|
|
67
|
-
transformedOperations = insertOperation1.transformOperation(insertOperation2);
|
|
68
|
-
|
|
69
|
-
assert.lengthOf(transformedOperations, 1);
|
|
70
|
-
|
|
71
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
72
|
-
transformedOperation = firstTransformedOperation, ///
|
|
73
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
74
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("aKId", 4),
|
|
75
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
76
|
-
|
|
77
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("at the same position whilst lexicographically equal to another insert", () => {
|
|
82
|
-
it("leaves the other insert intact", () => {
|
|
83
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("xcnhJU", 4),
|
|
84
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("xcnhJU", 4),
|
|
85
|
-
transformedOperations = insertOperation1.transformOperation(insertOperation2);
|
|
86
|
-
|
|
87
|
-
assert.lengthOf(transformedOperations, 1);
|
|
88
|
-
|
|
89
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
90
|
-
transformedOperation = firstTransformedOperation, ///
|
|
91
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
92
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("xcnhJU", 4),
|
|
93
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
94
|
-
|
|
95
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("to the right of another insert", () => {
|
|
100
|
-
it("leaves the other insert intact", () => {
|
|
101
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("kiuj", 14),
|
|
102
|
-
insertOperation2 = InsertOperation.fromContentAndPosition("xcnhJU", 4),
|
|
103
|
-
transformedOperations = insertOperation1.transformOperation(insertOperation2);
|
|
104
|
-
|
|
105
|
-
assert.lengthOf(transformedOperations, 1);
|
|
106
|
-
|
|
107
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
108
|
-
transformedOperation = firstTransformedOperation, ///
|
|
109
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
110
|
-
expectedTransformedOperation = InsertOperation.fromContentAndPosition("xcnhJU", 4),
|
|
111
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
112
|
-
|
|
113
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON)
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("to the left of a delete", () => {
|
|
118
|
-
it("moves the other delete to the right by its own length", () => {
|
|
119
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("jabgTF", 2),
|
|
120
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("cHYg", 10),
|
|
121
|
-
transformedOperations = insertOperation1.transformOperation(deleteOperation2);
|
|
122
|
-
|
|
123
|
-
assert.lengthOf(transformedOperations, 1);
|
|
124
|
-
|
|
125
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
126
|
-
transformedOperation = firstTransformedOperation, ///
|
|
127
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
128
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("cHYg", 16),
|
|
129
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
130
|
-
|
|
131
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("in the same position as a delete", () => {
|
|
136
|
-
it("moves the other delete to the right by its own length", () => {
|
|
137
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("jabgTF", 2),
|
|
138
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("cHYg", 2),
|
|
139
|
-
transformedOperations = insertOperation1.transformOperation(deleteOperation2);
|
|
140
|
-
|
|
141
|
-
assert.lengthOf(transformedOperations, 1);
|
|
142
|
-
|
|
143
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
144
|
-
transformedOperation = firstTransformedOperation, ///
|
|
145
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
146
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("cHYg", 8),
|
|
147
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
148
|
-
|
|
149
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("strictly overlapped by a delete", () => {
|
|
154
|
-
it("splits the delete in two", () => {
|
|
155
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("XsAz", 4),
|
|
156
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("xhytgGTY", 2),
|
|
157
|
-
transformedOperations = insertOperation1.transformOperation(deleteOperation2);
|
|
158
|
-
|
|
159
|
-
assert.lengthOf(transformedOperations, 2);
|
|
160
|
-
|
|
161
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
162
|
-
secondTransformedOperation = second(transformedOperations),
|
|
163
|
-
firstTransformedOperationJSON = firstTransformedOperation.toJSON(),
|
|
164
|
-
secondTransformedOperationJSON = secondTransformedOperation.toJSON(),
|
|
165
|
-
firstExpectedTransformedOperation = DeleteOperation.fromContentAndPosition("xh", 2),
|
|
166
|
-
firstExpectedTransformedOperationJSON = firstExpectedTransformedOperation.toJSON(),
|
|
167
|
-
secondExpectedTransformedOperation = DeleteOperation.fromContentAndPosition("ytgGTY", 6),
|
|
168
|
-
secondExpectedTransformedOperationJSON = secondExpectedTransformedOperation.toJSON();
|
|
169
|
-
|
|
170
|
-
assert.deepEqual(firstTransformedOperationJSON, firstExpectedTransformedOperationJSON);
|
|
171
|
-
assert.deepEqual(secondTransformedOperationJSON, secondExpectedTransformedOperationJSON);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe("to the right of a delete", () => {
|
|
176
|
-
it("leaves the delete intact", () => {
|
|
177
|
-
const insertOperation1 = InsertOperation.fromContentAndPosition("juhY", 10),
|
|
178
|
-
deleteOperation2 = DeleteOperation.fromContentAndPosition("xhyTYa", 2),
|
|
179
|
-
transformedOperations = insertOperation1.transformOperation(deleteOperation2);
|
|
180
|
-
|
|
181
|
-
assert.lengthOf(transformedOperations, 1);
|
|
182
|
-
|
|
183
|
-
const firstTransformedOperation = first(transformedOperations),
|
|
184
|
-
transformedOperation = firstTransformedOperation, ///
|
|
185
|
-
transformedOperationJSON = transformedOperation.toJSON(),
|
|
186
|
-
expectedTransformedOperation = DeleteOperation.fromContentAndPosition("xhyTYa", 2),
|
|
187
|
-
expectedTransformedOperationJSON = expectedTransformedOperation.toJSON();
|
|
188
|
-
|
|
189
|
-
assert.deepEqual(transformedOperationJSON, expectedTransformedOperationJSON);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
describe("transformContent", () => {
|
|
195
|
-
it("inserts the requisite characters into the content", () => {
|
|
196
|
-
const content = "adsfxvbc",
|
|
197
|
-
emptyOperation = InsertOperation.fromContentAndPosition("123", 1),
|
|
198
|
-
transformedContent = emptyOperation.transformContent(content),
|
|
199
|
-
expectedContent = "a123dsfxvbc";
|
|
200
|
-
|
|
201
|
-
assert.equal(transformedContent, expectedContent);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe("#transformSelection", () => {
|
|
206
|
-
let insertOperation;
|
|
207
|
-
|
|
208
|
-
beforeEach(() => {
|
|
209
|
-
const content = "JHg",
|
|
210
|
-
position = 4;
|
|
211
|
-
|
|
212
|
-
insertOperation = InsertOperation.fromContentAndPosition(content, position);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
describe("the selection is to its left", () => {
|
|
216
|
-
it("leaves the selection intact", () => {
|
|
217
|
-
const startPosition = 1,
|
|
218
|
-
endPosition = 2,
|
|
219
|
-
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
220
|
-
transformedSelection = insertOperation.transformSelection(selection),
|
|
221
|
-
expectedSelection = selection, ///
|
|
222
|
-
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
223
|
-
expectedSelectionJSON = expectedSelection.toJSON();
|
|
224
|
-
|
|
225
|
-
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe("the selection overlaps its left", () => {
|
|
230
|
-
it("moves the selections's right by its length", () => {
|
|
231
|
-
const startPosition = 1,
|
|
232
|
-
endPosition = 5,
|
|
233
|
-
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
234
|
-
transformedSelection = insertOperation.transformSelection(selection),
|
|
235
|
-
expectedStartPosition = 1,
|
|
236
|
-
expectedEndPosition = 8,
|
|
237
|
-
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
238
|
-
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
239
|
-
expectedSelectionJSON = expectedSelection.toJSON();
|
|
240
|
-
|
|
241
|
-
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
describe("the selection overlaps it completely, moves the selections's right by its length", () => {
|
|
246
|
-
it("the selection overlaps it completely, moves the selections's right by its length", () => {
|
|
247
|
-
const startPosition = 1,
|
|
248
|
-
endPosition = 10,
|
|
249
|
-
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
250
|
-
transformedSelection = insertOperation.transformSelection(selection),
|
|
251
|
-
expectedStartPosition = 1,
|
|
252
|
-
expectedEndPosition = 13,
|
|
253
|
-
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
254
|
-
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
255
|
-
expectedSelectionJSON = expectedSelection.toJSON();
|
|
256
|
-
|
|
257
|
-
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
describe("the selection overlaps its right", () => {
|
|
262
|
-
it("moves the selection right by its length", () => {
|
|
263
|
-
const startPosition = 5,
|
|
264
|
-
endPosition = 8,
|
|
265
|
-
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
266
|
-
transformedSelection = insertOperation.transformSelection(selection),
|
|
267
|
-
expectedStartPosition = 8,
|
|
268
|
-
expectedEndPosition = 11,
|
|
269
|
-
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
270
|
-
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
271
|
-
expectedSelectionJSON = expectedSelection.toJSON();
|
|
272
|
-
|
|
273
|
-
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe("the selection is completely to its right", () => {
|
|
278
|
-
it("moves the selection right by its length", () => {
|
|
279
|
-
const startPosition = 8,
|
|
280
|
-
endPosition = 10,
|
|
281
|
-
selection = Selection.fromStartPositionAndEndPosition(startPosition, endPosition),
|
|
282
|
-
transformedSelection = insertOperation.transformSelection(selection),
|
|
283
|
-
expectedStartPosition = 11,
|
|
284
|
-
expectedEndPosition = 13,
|
|
285
|
-
expectedSelection = Selection.fromStartPositionAndEndPosition(expectedStartPosition, expectedEndPosition),
|
|
286
|
-
transformedSelectionJSON = transformedSelection.toJSON(),
|
|
287
|
-
expectedSelectionJSON = expectedSelection.toJSON();
|
|
288
|
-
|
|
289
|
-
assert.deepEqual(transformedSelectionJSON, expectedSelectionJSON);
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
describe("fromJSON, toJSON", () => {
|
|
295
|
-
it("transforms from and to JSON, leaving the operation intact", () => {
|
|
296
|
-
const expectedJSON = {
|
|
297
|
-
"type": "insert",
|
|
298
|
-
"content": "a",
|
|
299
|
-
"position": 1
|
|
300
|
-
},
|
|
301
|
-
json = InsertOperation.fromJSON(expectedJSON).toJSON();
|
|
302
|
-
|
|
303
|
-
assert.deepEqual(json, expectedJSON);
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { assert } = require("chai"),
|
|
4
|
-
{ arrayUtilities } = require("necessary"),
|
|
5
|
-
{ InsertOperation, DeleteOperation, generateOperations } = require("../../lib/browser"); ///
|
|
6
|
-
|
|
7
|
-
const{ first, second } = arrayUtilities;
|
|
8
|
-
|
|
9
|
-
describe("generateOperations", () => {
|
|
10
|
-
describe("the contents are the same", () => {
|
|
11
|
-
it("generates a zero length array of operations", () => {
|
|
12
|
-
const content = "ngYtFRdeaQ",
|
|
13
|
-
operations = generateOperations(content, content);
|
|
14
|
-
|
|
15
|
-
assert.lengthOf(operations, 0);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("the first content is a subset of the second content", () => {
|
|
20
|
-
it("generates a array of operations containing an insert operation", () => {
|
|
21
|
-
const contentA = "juhGTre",
|
|
22
|
-
contentB = "juhJHuyGTre",
|
|
23
|
-
operations = generateOperations(contentA, contentB);
|
|
24
|
-
|
|
25
|
-
assert.lengthOf(operations, 1);
|
|
26
|
-
|
|
27
|
-
const firstOperation = first(operations),
|
|
28
|
-
insertOperation = InsertOperation.fromContentAndPosition("JHuy", 3),
|
|
29
|
-
operation = firstOperation, ///
|
|
30
|
-
expectedOperation = insertOperation, ///
|
|
31
|
-
operationJSON = operation.toJSON(),
|
|
32
|
-
expectedOperationJSON = expectedOperation.toJSON();
|
|
33
|
-
|
|
34
|
-
assert.deepEqual(operationJSON, expectedOperationJSON);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("the second content is a subset of first content", () => {
|
|
39
|
-
it("generates array of operations containing a delete operation", () => {
|
|
40
|
-
const contentA = "ayHTgvcregd",
|
|
41
|
-
contentB = "ayHTegd",
|
|
42
|
-
operations = generateOperations(contentA, contentB);
|
|
43
|
-
|
|
44
|
-
assert.lengthOf(operations, 1);
|
|
45
|
-
|
|
46
|
-
const firstOperation = first(operations),
|
|
47
|
-
deleteOperation = DeleteOperation.fromContentAndPosition("gvcr", 4),
|
|
48
|
-
operation = firstOperation, ///
|
|
49
|
-
expectedOperation = deleteOperation, ///
|
|
50
|
-
operationJSON = operation.toJSON(),
|
|
51
|
-
expectedOperationJSON = expectedOperation.toJSON();
|
|
52
|
-
|
|
53
|
-
assert.deepEqual(operationJSON, expectedOperationJSON);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("the contents are different", () => {
|
|
58
|
-
it("generates array of operations containing one delete operation followed by an insert operation", () => {
|
|
59
|
-
const contentA = "khbgytrcGFRDwr",
|
|
60
|
-
contentB = "khb12buhGTFRDwr",
|
|
61
|
-
operations = generateOperations(contentA, contentB);
|
|
62
|
-
|
|
63
|
-
assert.lengthOf(operations, 2);
|
|
64
|
-
|
|
65
|
-
const firstOperation = first(operations),
|
|
66
|
-
secondOperation = second(operations),
|
|
67
|
-
firstOperationJSON = firstOperation.toJSON(),
|
|
68
|
-
secondOperationJSON = secondOperation.toJSON(),
|
|
69
|
-
expectedFirstOperation = DeleteOperation.fromContentAndPosition("gytrcG", 3),
|
|
70
|
-
expectedSecondOperation = InsertOperation.fromContentAndPosition("12buhGT", 3),
|
|
71
|
-
expectedFirstOperationJSON = expectedFirstOperation.toJSON(),
|
|
72
|
-
expectedSecondOperationType = expectedSecondOperation.toJSON();
|
|
73
|
-
|
|
74
|
-
assert.deepEqual(firstOperationJSON, expectedFirstOperationJSON);
|
|
75
|
-
assert.deepEqual(secondOperationJSON, expectedSecondOperationType);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { assert } = require("chai"),
|
|
4
|
-
{ transformContent, transformOperations } = require("../../lib/browser"); ///
|
|
5
|
-
|
|
6
|
-
const helpers = require("../helpers");
|
|
7
|
-
|
|
8
|
-
describe("transformOperations", () => {
|
|
9
|
-
describe("for two sequences each containing a hundred operations", () => {
|
|
10
|
-
it("The intentions are preserved 1", () => {
|
|
11
|
-
assertIntentionsPreserved();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("The intentions are preserved 2", () => {
|
|
15
|
-
assertIntentionsPreserved();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("The intentions are preserved 3", () => {
|
|
19
|
-
assertIntentionsPreserved();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("The intentions are preserved 4", () => {
|
|
23
|
-
assertIntentionsPreserved();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("The intentions are preserved 6", () => {
|
|
27
|
-
assertIntentionsPreserved();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("The intentions are preserved 6", () => {
|
|
31
|
-
assertIntentionsPreserved();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("The intentions are preserved 7", () => {
|
|
35
|
-
assertIntentionsPreserved();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("The intentions are preserved 8", () => {
|
|
39
|
-
assertIntentionsPreserved();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("The intentions are preserved 9", () => {
|
|
43
|
-
assertIntentionsPreserved();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("The intentions are preserved 10", () => {
|
|
47
|
-
assertIntentionsPreserved();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
function assertIntentionsPreserved() {
|
|
53
|
-
const content = helpers.content(1000);
|
|
54
|
-
|
|
55
|
-
let firstOperations = helpers.operations(content, 100),
|
|
56
|
-
secondOperations = helpers.operations(content, 100);
|
|
57
|
-
|
|
58
|
-
const transformedFirstOperations = transformOperations(firstOperations, secondOperations),
|
|
59
|
-
transformedSecondOperations = transformOperations(secondOperations, firstOperations);
|
|
60
|
-
|
|
61
|
-
firstOperations = firstOperations.concat(transformedSecondOperations);
|
|
62
|
-
|
|
63
|
-
secondOperations = secondOperations.concat(transformedFirstOperations);
|
|
64
|
-
|
|
65
|
-
const firstTransformedContent = transformContent(content, firstOperations),
|
|
66
|
-
secondTransformedContent = transformContent(content, secondOperations);
|
|
67
|
-
|
|
68
|
-
assert.equal(firstTransformedContent, secondTransformedContent);
|
|
69
|
-
}
|