changesets
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -97,2 +97,4 @@ /*! | ||
}) | ||
return newCs | ||
} | ||
@@ -131,5 +133,7 @@ | ||
Changeset.prototype.invert = function() { | ||
return this.map(function(op) { | ||
return op.invert() | ||
var newCs = new Changeset | ||
this.forEach(function(op) { | ||
newCs.push(op.invert()) | ||
}) | ||
return newCs | ||
} | ||
@@ -136,0 +140,0 @@ |
@@ -67,3 +67,4 @@ /*! | ||
// in my range, don't delete them again! | ||
return new Delete(this.pos, this.text.substr(0, Math.min(change.pos - this.pos, this.len)), this.accessory) | ||
var startOfOther = Math.min(change.pos - this.pos, this.len) | ||
return new Delete(this.pos, this.text.substr(0, startOfOther) + this.text.substr(startOfOther + change.len), this.accessory) | ||
} | ||
@@ -70,0 +71,0 @@ |
@@ -73,3 +73,3 @@ /*! | ||
// 'xaxbc' | ||
if (change.pos < this.pos) { | ||
if (change.pos <= this.pos) { | ||
return new Insert(this.pos+change.len, this.text, this.accessory) | ||
@@ -76,0 +76,0 @@ } |
{ | ||
"name": "changesets", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A Changeset library incorporating operational transformation (OT).", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -99,3 +99,9 @@ # changesets | ||
# Todo | ||
* make Changeset#substract() more sane | ||
* What happens, if you apply the same CS multiple times, with or without transforming it? | ||
* Perhaps add text length diff to `Operation`s in order to be able validate them | ||
* Add a `pack()`/`unpack()`method to changesets | ||
# License | ||
MIT |
@@ -35,2 +35,4 @@ /*! | ||
// IT | ||
;// Insert onto Insert | ||
@@ -52,2 +54,3 @@ [ ["123", ["a123", "123b"], "a123b", "Insert onto Insert; o1.pos < o2.pos"] | ||
, ["123", ["3", "23"], "3", "Delete onto Delete; something at the beginning of my range has already been deleted"] | ||
, ["1234", ["4", "134"], "4", "Delete onto Delete; something in the middle of my range has already been deleted"] | ||
, ["123", ["13", "1"], "1", "Delete onto Delete; my whole range has already been deleted ('twas at the beginning of the other change's range)"] | ||
@@ -80,5 +83,5 @@ , ["123", ["12", "1"], "1", "Delete onto Delete; my whole range has already been deleted ('twas at the end of the other change's range)"] | ||
}, | ||
'should be correctly transformed using operational transformation': function(err, text) { | ||
'should be correctly transformed using inclusion transformation': function(err, text) { | ||
assert.ifError(err) | ||
assert.equal(text, test[2]) | ||
assert.equal(test[2], text) | ||
} | ||
@@ -89,2 +92,46 @@ } | ||
// ET | ||
;// Insert minus Insert | ||
[ [["123", "123b", "a123b"], "a123", "Insert minus Insert; o2.pos < o1.pos"] | ||
, [["123", "b123", "b12a3"], "12a3", "Insert minus Insert; o1.pos < o2.pos"] | ||
, [["123", "bb123", "bab123"], "a123", "Insert minus Insert; o1.pos < o2.pos < o1.pos+len"] | ||
// Insert minus Delete | ||
, [["1234", "124", "a124"], "a1234", "Insert minus Delete; o2.pos < o1.pos"] | ||
, [["1234", "134", "1a34"], "12a34", "Insert minus Delete; o2.pos = o1.pos"] | ||
, [["1234", "34", "3a4"], "123a4", "Insert minus Delete; o1.pos < o2.pos"] | ||
// Delete minus Insert | ||
, [["123", "a123", "a13"], "13", "Delete minus Insert; o1.pos < o2.pos"] | ||
, [["123", "123a", "13a"], "13", "Delete minus Insert; o2.pos < o1.pos"] | ||
, [["1234", "12a34", "14"], "14", "Delete minus Insert; o2.pos < o1.pos < o2.pos+len"] | ||
, [["123", "12abc3", "12ac3"], "123", "Delete minus Insert; o1.pos < o2.pos < o2.pos+len < o1.pos+len"] | ||
// Delete minus Delete | ||
, [["1234", "34", "4"], "124", "Delete minus Delete; o1.pos < o2.pos"] | ||
, [["1234", "123", "23"], "234", "Delete minus Delete; o2.pos < o1.pos"] | ||
, [["1234", "123", "12"], "124", "Delete minus Delete; o2.pos < o1.pos"] | ||
] | ||
.forEach(function(test, i) { | ||
var batch = {} | ||
batch[test[2]] = { | ||
topic: function() { | ||
var cs1 = engine.constructChangeset(test[0][0],test[0][1], 1) | ||
, cs2 = engine.constructChangeset(test[0][1],test[0][2], 2) | ||
console.log("\n\n", test[0][2], '-', test[0][1]) | ||
console.dir(cs1.dump()) | ||
console.dir(cs2.dump()) | ||
cs2 = cs2.substract(cs1) | ||
console.log('=>', cs2.dump()) | ||
return cs2.apply(test[0][0]) | ||
}, | ||
'should be correctly transformed using exclusion transformation': function(err, text) { | ||
assert.ifError(err) | ||
assert.equal(test[1], text) | ||
} | ||
} | ||
suite.addBatch(batch) | ||
}) | ||
suite.export(module) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32911
643
106