2016-03-13 21:23:11 -04:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<!--
|
|
|
|
|
Copyright (C) 2016 The Android Open Source Project
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
|
|
|
|
<title>gr-diff-builder</title>
|
|
|
|
|
|
|
|
|
|
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
|
|
|
|
<script src="gr-diff-line.js"></script>
|
|
|
|
|
<script src="gr-diff-group.js"></script>
|
|
|
|
|
<script src="gr-diff-builder.js"></script>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
suite('gr-diff-builder tests', function() {
|
2016-03-22 16:34:03 -04:00
|
|
|
|
var builder;
|
|
|
|
|
|
|
|
|
|
setup(function() {
|
|
|
|
|
var prefs = {
|
|
|
|
|
line_length: 10,
|
|
|
|
|
show_tabs: true,
|
|
|
|
|
tab_size: 4,
|
|
|
|
|
};
|
|
|
|
|
builder = new GrDiffBuilder({content: []}, {left: [], right: []}, prefs);
|
|
|
|
|
});
|
2016-03-13 21:23:11 -04:00
|
|
|
|
|
|
|
|
|
test('process loaded content', function() {
|
|
|
|
|
var content = [
|
|
|
|
|
{
|
|
|
|
|
ab: [
|
|
|
|
|
'<!DOCTYPE html>',
|
|
|
|
|
'<meta charset="utf-8">',
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
a: [
|
|
|
|
|
' Welcome ',
|
|
|
|
|
' to the wooorld of tomorrow!',
|
|
|
|
|
],
|
|
|
|
|
b: [
|
|
|
|
|
' Hello, world!',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ab: [
|
|
|
|
|
'Leela: This is the only place the ship can’t hear us, so ',
|
|
|
|
|
'everyone pretend to shower.',
|
|
|
|
|
'Fry: Same as every day. Got it.',
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
var groups = [];
|
2016-03-22 16:34:03 -04:00
|
|
|
|
|
|
|
|
|
builder._processContent(content, groups, -1);
|
2016-03-13 21:23:11 -04:00
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups.length, 4);
|
2016-03-13 21:23:11 -04:00
|
|
|
|
|
|
|
|
|
var group = groups[0];
|
|
|
|
|
assert.equal(group.type, GrDiffGroup.Type.BOTH);
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(group.lines.length, 1);
|
|
|
|
|
assert.equal(group.lines[0].text, '');
|
|
|
|
|
assert.equal(group.lines[0].beforeNumber, GrDiffLine.FILE);
|
|
|
|
|
assert.equal(group.lines[0].afterNumber, GrDiffLine.FILE);
|
|
|
|
|
|
|
|
|
|
group = groups[1];
|
|
|
|
|
assert.equal(group.type, GrDiffGroup.Type.BOTH);
|
2016-03-13 21:23:11 -04:00
|
|
|
|
assert.equal(group.lines.length, 2);
|
|
|
|
|
assert.equal(group.lines.length, 2);
|
|
|
|
|
|
|
|
|
|
function beforeNumberFn(l) { return l.beforeNumber; }
|
|
|
|
|
function afterNumberFn(l) { return l.afterNumber; }
|
|
|
|
|
function textFn(l) { return l.text; }
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(group.lines.map(beforeNumberFn), [1, 2]);
|
|
|
|
|
assert.deepEqual(group.lines.map(afterNumberFn), [1, 2]);
|
|
|
|
|
assert.deepEqual(group.lines.map(textFn), [
|
|
|
|
|
'<!DOCTYPE html>',
|
|
|
|
|
'<meta charset="utf-8">',
|
|
|
|
|
]);
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
group = groups[2];
|
2016-03-13 21:23:11 -04:00
|
|
|
|
assert.equal(group.type, GrDiffGroup.Type.DELTA);
|
|
|
|
|
assert.equal(group.lines.length, 3);
|
|
|
|
|
assert.equal(group.adds.length, 1);
|
|
|
|
|
assert.equal(group.removes.length, 2);
|
|
|
|
|
assert.deepEqual(group.removes.map(beforeNumberFn), [3, 4]);
|
|
|
|
|
assert.deepEqual(group.adds.map(afterNumberFn), [3]);
|
|
|
|
|
assert.deepEqual(group.removes.map(textFn), [
|
|
|
|
|
' Welcome ',
|
|
|
|
|
' to the wooorld of tomorrow!',
|
|
|
|
|
]);
|
|
|
|
|
assert.deepEqual(group.adds.map(textFn), [
|
|
|
|
|
' Hello, world!',
|
|
|
|
|
]);
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
group = groups[3];
|
2016-03-13 21:23:11 -04:00
|
|
|
|
assert.equal(group.type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(group.lines.length, 3);
|
|
|
|
|
assert.deepEqual(group.lines.map(beforeNumberFn), [5, 6, 7]);
|
|
|
|
|
assert.deepEqual(group.lines.map(afterNumberFn), [4, 5, 6]);
|
|
|
|
|
assert.deepEqual(group.lines.map(textFn), [
|
|
|
|
|
'Leela: This is the only place the ship can’t hear us, so ',
|
|
|
|
|
'everyone pretend to shower.',
|
|
|
|
|
'Fry: Same as every day. Got it.',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-15 18:58:46 -04:00
|
|
|
|
test('insert context groups', function() {
|
|
|
|
|
var content = [
|
|
|
|
|
{ab: []},
|
|
|
|
|
{a: ['all work and no play make andybons a dull boy']},
|
|
|
|
|
{ab: []},
|
|
|
|
|
{b: ['elgoog elgoog elgoog']},
|
|
|
|
|
{ab: []},
|
|
|
|
|
];
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
|
content[0].ab.push('all work and no play make jack a dull boy');
|
|
|
|
|
content[4].ab.push('all work and no play make jill a dull girl');
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < 5; i++) {
|
|
|
|
|
content[2].ab.push('no tv and no beer make homer go crazy');
|
|
|
|
|
}
|
|
|
|
|
var groups = [];
|
|
|
|
|
var context = 10;
|
|
|
|
|
|
2016-03-22 16:34:03 -04:00
|
|
|
|
builder._processContent(content, groups, context);
|
2016-03-15 18:58:46 -04:00
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[0].type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(groups[0].lines.length, 1);
|
|
|
|
|
assert.equal(groups[0].lines[0].text, '');
|
|
|
|
|
assert.equal(groups[0].lines[0].beforeNumber, GrDiffLine.FILE);
|
|
|
|
|
assert.equal(groups[0].lines[0].afterNumber, GrDiffLine.FILE);
|
|
|
|
|
|
|
|
|
|
assert.equal(groups[1].type, GrDiffGroup.Type.CONTEXT_CONTROL);
|
|
|
|
|
assert.equal(groups[1].lines[0].contextLines.length, 90);
|
|
|
|
|
groups[1].lines[0].contextLines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[0].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[2].type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(groups[2].lines.length, context);
|
|
|
|
|
groups[2].lines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[0].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[3].type, GrDiffGroup.Type.DELTA);
|
|
|
|
|
assert.equal(groups[3].lines.length, 1);
|
|
|
|
|
assert.equal(groups[3].removes.length, 1);
|
|
|
|
|
assert.equal(groups[3].removes[0].text,
|
2016-03-15 18:58:46 -04:00
|
|
|
|
'all work and no play make andybons a dull boy');
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[4].type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(groups[4].lines.length, 5);
|
|
|
|
|
groups[4].lines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[2].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[5].type, GrDiffGroup.Type.DELTA);
|
|
|
|
|
assert.equal(groups[5].lines.length, 1);
|
|
|
|
|
assert.equal(groups[5].adds.length, 1);
|
|
|
|
|
assert.equal(groups[5].adds[0].text, 'elgoog elgoog elgoog');
|
2016-03-15 18:58:46 -04:00
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[6].type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(groups[6].lines.length, context);
|
|
|
|
|
groups[6].lines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[4].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[7].type, GrDiffGroup.Type.CONTEXT_CONTROL);
|
|
|
|
|
assert.equal(groups[7].lines[0].contextLines.length, 90);
|
|
|
|
|
groups[7].lines[0].contextLines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[4].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
content = [
|
|
|
|
|
{a: ['all work and no play make andybons a dull boy']},
|
|
|
|
|
{ab: []},
|
|
|
|
|
{b: ['elgoog elgoog elgoog']},
|
|
|
|
|
];
|
|
|
|
|
for (var i = 0; i < 50; i++) {
|
|
|
|
|
content[1].ab.push('no tv and no beer make homer go crazy');
|
|
|
|
|
}
|
|
|
|
|
groups = [];
|
|
|
|
|
|
2016-03-22 16:34:03 -04:00
|
|
|
|
builder._processContent(content, groups, 10);
|
2016-03-15 18:58:46 -04:00
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[0].type, GrDiffGroup.Type.BOTH);
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(groups[0].lines.length, 1);
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[0].lines[0].text, '');
|
|
|
|
|
assert.equal(groups[0].lines[0].beforeNumber, GrDiffLine.FILE);
|
|
|
|
|
assert.equal(groups[0].lines[0].afterNumber, GrDiffLine.FILE);
|
|
|
|
|
|
|
|
|
|
assert.equal(groups[1].type, GrDiffGroup.Type.DELTA);
|
|
|
|
|
assert.equal(groups[1].lines.length, 1);
|
|
|
|
|
assert.equal(groups[1].removes.length, 1);
|
|
|
|
|
assert.equal(groups[1].removes[0].text,
|
2016-03-15 18:58:46 -04:00
|
|
|
|
'all work and no play make andybons a dull boy');
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[2].type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(groups[2].lines.length, context);
|
|
|
|
|
groups[2].lines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[1].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[3].type, GrDiffGroup.Type.CONTEXT_CONTROL);
|
|
|
|
|
assert.equal(groups[3].lines[0].contextLines.length, 30);
|
|
|
|
|
groups[3].lines[0].contextLines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[1].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[4].type, GrDiffGroup.Type.BOTH);
|
|
|
|
|
assert.equal(groups[4].lines.length, context);
|
|
|
|
|
groups[4].lines.forEach(function(l) {
|
2016-03-15 18:58:46 -04:00
|
|
|
|
assert.equal(l.text, content[1].ab[0]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-24 17:59:35 -04:00
|
|
|
|
assert.equal(groups[5].type, GrDiffGroup.Type.DELTA);
|
|
|
|
|
assert.equal(groups[5].lines.length, 1);
|
|
|
|
|
assert.equal(groups[5].adds.length, 1);
|
|
|
|
|
assert.equal(groups[5].adds[0].text, 'elgoog elgoog elgoog');
|
2016-03-15 18:58:46 -04:00
|
|
|
|
});
|
2016-03-17 14:39:42 -04:00
|
|
|
|
|
|
|
|
|
test('newlines', function() {
|
|
|
|
|
var text = 'abcdef';
|
|
|
|
|
assert.equal(builder._addNewlines(text, text), text);
|
|
|
|
|
text = 'a'.repeat(20);
|
|
|
|
|
assert.equal(builder._addNewlines(text, text),
|
|
|
|
|
'a'.repeat(10) +
|
|
|
|
|
GrDiffBuilder.LINE_FEED_HTML +
|
|
|
|
|
'a'.repeat(10));
|
|
|
|
|
|
|
|
|
|
text = '<span class="thumbsup">👍</span>';
|
|
|
|
|
var html = '<span class="thumbsup">👍</span>';
|
|
|
|
|
assert.equal(builder._addNewlines(text, html),
|
|
|
|
|
'<span clas' +
|
|
|
|
|
GrDiffBuilder.LINE_FEED_HTML +
|
|
|
|
|
's="thumbsu' +
|
|
|
|
|
GrDiffBuilder.LINE_FEED_HTML +
|
|
|
|
|
'p">👍</spa' +
|
|
|
|
|
GrDiffBuilder.LINE_FEED_HTML +
|
|
|
|
|
'n>');
|
|
|
|
|
|
|
|
|
|
text = '01234\t56789';
|
|
|
|
|
assert.equal(builder._addNewlines(text, text),
|
|
|
|
|
'01234\t5' +
|
|
|
|
|
GrDiffBuilder.LINE_FEED_HTML +
|
|
|
|
|
'6789');
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-11 21:17:38 -04:00
|
|
|
|
test('text length with tabs', function() {
|
|
|
|
|
assert.equal(builder._textLength('12345', 4), 5);
|
|
|
|
|
assert.equal(builder._textLength('\t\t12', 4), 10);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-17 14:39:42 -04:00
|
|
|
|
test('tab wrapper insertion', function() {
|
|
|
|
|
var html = 'abc\tdef';
|
2016-03-22 16:34:03 -04:00
|
|
|
|
var wrapper = builder._getTabWrapper(
|
|
|
|
|
builder._prefs.tab_size,
|
|
|
|
|
builder._prefs.show_tabs);
|
2016-03-18 16:06:37 -04:00
|
|
|
|
assert.ok(wrapper);
|
|
|
|
|
assert.isAbove(wrapper.length, 0);
|
2016-03-17 14:39:42 -04:00
|
|
|
|
assert.equal(builder._addTabWrappers(html), 'abc' + wrapper + 'def');
|
|
|
|
|
assert.throws(builder._getTabWrapper.bind(
|
|
|
|
|
builder,
|
|
|
|
|
'"><img src="/" onerror="alert(1);"><span class="',
|
|
|
|
|
true));
|
|
|
|
|
});
|
2016-03-20 14:14:20 -04:00
|
|
|
|
|
|
|
|
|
test('comments', function() {
|
|
|
|
|
var line = new GrDiffLine(GrDiffLine.Type.BOTH);
|
|
|
|
|
line.beforeNumber = 3;
|
|
|
|
|
line.afterNumber = 5;
|
|
|
|
|
|
2016-04-29 22:25:51 +02:00
|
|
|
|
var comments = {left: [], right: []};
|
2016-03-22 16:34:03 -04:00
|
|
|
|
assert.deepEqual(builder._getCommentsForLine(comments, line), []);
|
|
|
|
|
assert.deepEqual(builder._getCommentsForLine(comments, line,
|
|
|
|
|
GrDiffBuilder.Side.LEFT), []);
|
|
|
|
|
assert.deepEqual(builder._getCommentsForLine(comments, line,
|
|
|
|
|
GrDiffBuilder.Side.RIGHT), []);
|
2016-03-20 14:14:20 -04:00
|
|
|
|
|
|
|
|
|
comments = {
|
|
|
|
|
left: [
|
|
|
|
|
{id: 'l3', line: 3},
|
|
|
|
|
{id: 'l5', line: 5},
|
|
|
|
|
],
|
|
|
|
|
right: [
|
|
|
|
|
{id: 'r3', line: 3},
|
|
|
|
|
{id: 'r5', line: 5},
|
|
|
|
|
],
|
|
|
|
|
};
|
2016-03-22 16:34:03 -04:00
|
|
|
|
assert.deepEqual(builder._getCommentsForLine(comments, line),
|
2016-03-20 14:14:20 -04:00
|
|
|
|
[{id: 'l3', line: 3}, {id: 'r5', line: 5}]);
|
2016-03-22 16:34:03 -04:00
|
|
|
|
assert.deepEqual(builder._getCommentsForLine(comments, line,
|
|
|
|
|
GrDiffBuilder.Side.LEFT), [{id: 'l3', line: 3}]);
|
|
|
|
|
assert.deepEqual(builder._getCommentsForLine(comments, line,
|
|
|
|
|
GrDiffBuilder.Side.RIGHT), [{id: 'r5', line: 5}]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-22 19:14:12 -04:00
|
|
|
|
test('comment thread creation', function() {
|
|
|
|
|
builder._comments = {
|
|
|
|
|
meta: {
|
|
|
|
|
changeNum: '42',
|
|
|
|
|
patchRange: {
|
|
|
|
|
basePatchNum: 'PARENT',
|
|
|
|
|
patchNum: '3',
|
|
|
|
|
},
|
|
|
|
|
path: '/path/to/foo',
|
|
|
|
|
projectConfig: {foo: 'bar'},
|
|
|
|
|
},
|
|
|
|
|
left: [
|
|
|
|
|
{id: 'l3', line: 3},
|
|
|
|
|
{id: 'l5', line: 5},
|
|
|
|
|
],
|
|
|
|
|
right: [
|
|
|
|
|
{id: 'r5', line: 5},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-29 22:25:51 +02:00
|
|
|
|
function checkThreadProps(threadEl, patchNum, side, comments) {
|
2016-03-22 19:14:12 -04:00
|
|
|
|
assert.equal(threadEl.changeNum, '42');
|
|
|
|
|
assert.equal(threadEl.patchNum, patchNum);
|
|
|
|
|
assert.equal(threadEl.path, '/path/to/foo');
|
|
|
|
|
assert.equal(threadEl.side, side);
|
|
|
|
|
assert.deepEqual(threadEl.projectConfig, {foo: 'bar'});
|
|
|
|
|
assert.deepEqual(threadEl.comments, comments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var line = new GrDiffLine(GrDiffLine.Type.BOTH);
|
|
|
|
|
line.beforeNumber = 5;
|
|
|
|
|
line.afterNumber = 5;
|
2016-04-29 22:25:51 +02:00
|
|
|
|
var threadEl = builder._commentThreadForLine(line);
|
|
|
|
|
checkThreadProps(threadEl, '3', 'REVISION',
|
2016-03-22 19:14:12 -04:00
|
|
|
|
[{id: 'l5', line: 5}, {id: 'r5', line: 5}]);
|
|
|
|
|
|
|
|
|
|
threadEl = builder._commentThreadForLine(line, GrDiffBuilder.Side.RIGHT);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '3', 'REVISION', [{id: 'r5', line: 5}]);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
|
|
|
|
|
threadEl = builder._commentThreadForLine(line, GrDiffBuilder.Side.LEFT);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '3', 'PARENT', [{id: 'l5', line: 5}]);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
|
|
|
|
|
builder._comments.meta.patchRange.basePatchNum = '1';
|
|
|
|
|
|
|
|
|
|
threadEl = builder._commentThreadForLine(line);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '3', 'REVISION',
|
2016-03-22 19:14:12 -04:00
|
|
|
|
[{id: 'l5', line: 5}, {id: 'r5', line: 5}]);
|
|
|
|
|
|
|
|
|
|
threadEl = builder._commentThreadForLine(line, GrDiffBuilder.Side.LEFT);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '1', 'REVISION', [{id: 'l5', line: 5}]);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
|
|
|
|
|
threadEl = builder._commentThreadForLine(line, GrDiffBuilder.Side.RIGHT);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '3', 'REVISION', [{id: 'r5', line: 5}]);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
|
|
|
|
|
builder._comments.meta.patchRange.basePatchNum = 'PARENT';
|
|
|
|
|
|
|
|
|
|
line = new GrDiffLine(GrDiffLine.Type.REMOVE);
|
|
|
|
|
line.beforeNumber = 5;
|
|
|
|
|
line.afterNumber = 5;
|
|
|
|
|
threadEl = builder._commentThreadForLine(line);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '3', 'PARENT',
|
2016-03-22 19:14:12 -04:00
|
|
|
|
[{id: 'l5', line: 5}, {id: 'r5', line: 5}]);
|
|
|
|
|
|
|
|
|
|
line = new GrDiffLine(GrDiffLine.Type.ADD);
|
|
|
|
|
line.beforeNumber = 3;
|
|
|
|
|
line.afterNumber = 5;
|
|
|
|
|
threadEl = builder._commentThreadForLine(line);
|
2016-04-29 22:25:51 +02:00
|
|
|
|
checkThreadProps(threadEl, '3', 'REVISION',
|
2016-03-22 19:14:12 -04:00
|
|
|
|
[{id: 'l3', line: 3}, {id: 'r5', line: 5}]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-22 16:34:03 -04:00
|
|
|
|
test('break up common diff chunks', function() {
|
|
|
|
|
builder._commentLocations = {
|
|
|
|
|
left: {1: true},
|
|
|
|
|
right: {10: true},
|
|
|
|
|
};
|
|
|
|
|
var lineNums = {
|
|
|
|
|
left: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
};
|
|
|
|
|
var content = [
|
|
|
|
|
{
|
|
|
|
|
ab: [
|
|
|
|
|
'Copyright (C) 2015 The Android Open Source Project',
|
|
|
|
|
'',
|
|
|
|
|
'Licensed under the Apache License, Version 2.0 (the "License");',
|
|
|
|
|
'you may not use this file except in compliance with the License.',
|
|
|
|
|
'You may obtain a copy of the License at',
|
|
|
|
|
'',
|
|
|
|
|
'http://www.apache.org/licenses/LICENSE-2.0',
|
|
|
|
|
'',
|
|
|
|
|
'Unless required by applicable law or agreed to in writing, ',
|
|
|
|
|
'software distributed under the License is distributed on an ',
|
|
|
|
|
'"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, ',
|
|
|
|
|
'either express or implied. See the License for the specific ',
|
|
|
|
|
'language governing permissions and limitations under the License.',
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
var result = builder._splitCommonGroupsWithComments(content, lineNums);
|
|
|
|
|
assert.deepEqual(result, [
|
|
|
|
|
{
|
|
|
|
|
ab: ['Copyright (C) 2015 The Android Open Source Project'],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ab: [
|
|
|
|
|
'',
|
|
|
|
|
'Licensed under the Apache License, Version 2.0 (the "License");',
|
|
|
|
|
'you may not use this file except in compliance with the License.',
|
|
|
|
|
'You may obtain a copy of the License at',
|
|
|
|
|
'',
|
|
|
|
|
'http://www.apache.org/licenses/LICENSE-2.0',
|
|
|
|
|
'',
|
|
|
|
|
'Unless required by applicable law or agreed to in writing, ',
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ab: ['software distributed under the License is distributed on an '],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ab: [
|
|
|
|
|
'"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, ',
|
|
|
|
|
'either express or implied. See the License for the specific ',
|
|
|
|
|
'language governing permissions and limitations under the License.',
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]);
|
2016-03-20 14:14:20 -04:00
|
|
|
|
});
|
2016-03-25 09:02:30 -04:00
|
|
|
|
|
|
|
|
|
test('intraline normalization', function() {
|
|
|
|
|
// The content and highlights are in the format returned by the Gerrit
|
|
|
|
|
// REST API.
|
|
|
|
|
var content = [
|
|
|
|
|
' <section class="summary">',
|
|
|
|
|
' <gr-linked-text content="' +
|
|
|
|
|
'[[_computeCurrentRevisionMessage(change)]]"></gr-linked-text>',
|
|
|
|
|
' </section>',
|
|
|
|
|
];
|
|
|
|
|
var highlights = [
|
|
|
|
|
[31, 34], [42, 26]
|
|
|
|
|
];
|
|
|
|
|
var results = GrDiffBuilder.prototype._normalizeIntralineHighlights(
|
|
|
|
|
content, highlights);
|
|
|
|
|
assert.deepEqual(results, [
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 0,
|
|
|
|
|
startIndex: 31,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 1,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
endIndex: 33,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 1,
|
|
|
|
|
startIndex: 75,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 2,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
endIndex: 6,
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
content = [
|
|
|
|
|
' this._path = value.path;',
|
|
|
|
|
'',
|
|
|
|
|
' // When navigating away from the page, there is a possibility that the',
|
|
|
|
|
' // patch number is no longer a part of the URL (say when navigating to',
|
|
|
|
|
' // the top-level change info view) and therefore undefined in `params`.',
|
|
|
|
|
' if (!this._patchRange.patchNum) {',
|
|
|
|
|
];
|
|
|
|
|
highlights = [
|
|
|
|
|
[14, 17],
|
|
|
|
|
[11, 70],
|
|
|
|
|
[12, 67],
|
|
|
|
|
[12, 67],
|
|
|
|
|
[14, 29],
|
|
|
|
|
];
|
|
|
|
|
results = GrDiffBuilder.prototype._normalizeIntralineHighlights(content,
|
|
|
|
|
highlights);
|
|
|
|
|
assert.deepEqual(results, [
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 0,
|
|
|
|
|
startIndex: 14,
|
|
|
|
|
endIndex: 31,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 2,
|
|
|
|
|
startIndex: 8,
|
|
|
|
|
endIndex: 78,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 3,
|
|
|
|
|
startIndex: 11,
|
|
|
|
|
endIndex: 78,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 4,
|
|
|
|
|
startIndex: 11,
|
|
|
|
|
endIndex: 78,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
contentIndex: 5,
|
|
|
|
|
startIndex: 12,
|
|
|
|
|
endIndex: 41,
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
});
|
2016-03-13 21:23:11 -04:00
|
|
|
|
});
|
|
|
|
|
</script>
|