NewsBlur/node/node_modules/difflib/test/SequenceMatcher.js
2019-04-13 15:11:58 -04:00

107 lines
3.5 KiB
JavaScript

// Generated by CoffeeScript 1.8.0
(function() {
var SequenceMatcher;
SequenceMatcher = require('..').SequenceMatcher;
suite('SequenceMatcher');
test('#setSeqs', function() {
var s;
s = new SequenceMatcher();
s.setSeqs('abcd', 'bcde');
return s.ratio().should.eql(0.75);
});
test('#setSeq1', function() {
var s;
s = new SequenceMatcher(null, 'abcd', 'bcde');
s.ratio().should.eql(0.75);
s.setSeq1('bcde');
return s.ratio().should.eql(1.0);
});
test('#setSeq2', function() {
var s;
s = new SequenceMatcher(null, 'abcd', 'bcde');
s.ratio().should.eql(0.75);
s.setSeq2('abcd');
return s.ratio().should.eql(1.0);
});
test('#findLongestMatch', function() {
var isjunk, m, s;
isjunk = function(x) {
return x === ' ';
};
s = new SequenceMatcher(isjunk, ' abcd', 'abcd abcd');
m = s.findLongestMatch(0, 5, 0, 9);
m.should.eql([1, 0, 4]);
s = new SequenceMatcher(null, 'ab', 'c');
m = s.findLongestMatch(0, 2, 0, 1);
return m.should.eql([0, 0, 0]);
});
test('#getMatchingBlocks', function() {
var isjunk, ms, s;
s = new SequenceMatcher(null, 'abxcd', 'abcd');
ms = s.getMatchingBlocks();
ms.should.eql([[0, 0, 2], [3, 2, 2], [5, 4, 0]]);
isjunk = function(x) {
return x === ' ';
};
s = new SequenceMatcher(isjunk, 'private Thread currentThread;', 'private volatile Thread currentThread;');
return s.getMatchingBlocks().should.eql([[0, 0, 8], [8, 17, 21], [29, 38, 0]]);
});
test('#getOpcodes', function() {
var isjunk, s;
s = new SequenceMatcher(null, 'qabxcd', 'abycdf');
s.getOpcodes().should.eql([['delete', 0, 1, 0, 0], ['equal', 1, 3, 0, 2], ['replace', 3, 4, 2, 3], ['equal', 4, 6, 3, 5], ['insert', 6, 6, 5, 6]]);
isjunk = function(x) {
return x === ' ';
};
s = new SequenceMatcher(isjunk, 'private Thread currentThread;', 'private volatile Thread currentThread;');
return s.getOpcodes().should.eql([['equal', 0, 8, 0, 8], ['insert', 8, 8, 8, 17], ['equal', 8, 29, 17, 38]]);
});
test('#getGroupedOpcodes', function() {
var a, b, s, _i, _ref, _results;
a = (function() {
_results = [];
for (_i = 1; _i < 40; _i++){ _results.push(_i); }
return _results;
}).apply(this).map(String);
b = a.slice();
[].splice.apply(b, [8, 0].concat('i')), 'i';
b[20] += 'x';
[].splice.apply(b, [23, 5].concat(_ref = [])), _ref;
b[30] += 'y';
s = new SequenceMatcher(null, a, b);
return s.getGroupedOpcodes().should.eql([[['equal', 5, 8, 5, 8], ['insert', 8, 8, 8, 9], ['equal', 8, 11, 9, 12]], [['equal', 16, 19, 17, 20], ['replace', 19, 20, 20, 21], ['equal', 20, 22, 21, 23], ['delete', 22, 27, 23, 23], ['equal', 27, 30, 23, 26]], [['equal', 31, 34, 27, 30], ['replace', 34, 35, 30, 31], ['equal', 35, 38, 31, 34]]]);
});
test('#ratio', function() {
var isjunk, s;
s = new SequenceMatcher(null, 'abcd', 'bcde');
s.ratio().should.equal(0.75);
isjunk = function(x) {
return x === ' ';
};
s = new SequenceMatcher(isjunk, 'private Thread currentThread;', 'private volatile Thread currentThread;');
return s.ratio().toPrecision(3).should.eql('0.866');
});
test('#quickRatio', function() {
var s;
s = new SequenceMatcher(null, 'abcd', 'bcde');
return s.quickRatio().should.equal(0.75);
});
test('#realQuickRatio', function() {
var s;
s = new SequenceMatcher(null, 'abcd', 'bcde');
return s.realQuickRatio().should.equal(1.0);
});
}).call(this);