提交 3ac4b025 编写于 作者: S Sandeep Somavarapu

fix tests

上级 439e6181
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
import * as assert from 'assert'; import * as assert from 'assert';
import { merge, updateIgnoredSettings, addSetting } from 'vs/platform/userDataSync/common/settingsMerge'; import { merge, updateIgnoredSettings, addSetting } from 'vs/platform/userDataSync/common/settingsMerge';
import type { IConflictSetting } from 'vs/platform/userDataSync/common/userDataSync';
const formattingOptions = { eol: '\n', insertSpaces: false, tabSize: 4 }; const formattingOptions = { eol: '\n', insertSpaces: false, tabSize: 4 };
suite('SettingsMerge - No Conflicts', () => { suite('SettingsMerge - Merge', () => {
test('merge when local and remote are same with one entry', async () => { test('merge when local and remote are same with one entry', async () => {
const localContent = stringify({ 'a': 1 }); const localContent = stringify({ 'a': 1 });
...@@ -262,11 +263,6 @@ suite('SettingsMerge - No Conflicts', () => { ...@@ -262,11 +263,6 @@ suite('SettingsMerge - No Conflicts', () => {
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
});
/*
suite('SettingsMerge - Conflicts', () => {
test('merge when local and remote with one entry but different value', async () => { test('merge when local and remote with one entry but different value', async () => {
const localContent = stringify({ const localContent = stringify({
'a': 1 'a': 1
...@@ -276,16 +272,10 @@ suite('SettingsMerge - Conflicts', () => { ...@@ -276,16 +272,10 @@ suite('SettingsMerge - Conflicts', () => {
}); });
const expectedConflicts: IConflictSetting[] = [{ key: 'a', localValue: 1, remoteValue: 2 }]; const expectedConflicts: IConflictSetting[] = [{ key: 'a', localValue: 1, remoteValue: 2 }];
const actual = merge(localContent, remoteContent, null, [], [], formattingOptions); const actual = merge(localContent, remoteContent, null, [], [], formattingOptions);
assert.ok(actual.hasChanges); assert.equal(actual.localContent, localContent);
assert.deepEqual(actual.conflicts, expectedConflicts); assert.equal(actual.remoteContent, remoteContent);
assert.equal(actual.mergeContent, assert.ok(actual.hasConflicts);
`{ assert.deepEqual(actual.conflictsSettings, expectedConflicts);
<<<<<<< local
"a": 1
=======
"a": 2,
>>>>>>> remote
}`);
}); });
test('merge when the entry is removed in remote but updated in local and a new entry is added in remote', async () => { test('merge when the entry is removed in remote but updated in local and a new entry is added in remote', async () => {
...@@ -300,16 +290,13 @@ suite('SettingsMerge - Conflicts', () => { ...@@ -300,16 +290,13 @@ suite('SettingsMerge - Conflicts', () => {
}); });
const expectedConflicts: IConflictSetting[] = [{ key: 'a', localValue: 2, remoteValue: undefined }]; const expectedConflicts: IConflictSetting[] = [{ key: 'a', localValue: 2, remoteValue: undefined }];
const actual = merge(localContent, remoteContent, baseContent, [], [], formattingOptions); const actual = merge(localContent, remoteContent, baseContent, [], [], formattingOptions);
assert.ok(actual.hasChanges); assert.equal(actual.localContent, stringify({
assert.deepEqual(actual.conflicts, expectedConflicts); 'a': 2,
assert.equal(actual.mergeContent, 'b': 2
`{ }));
<<<<<<< local assert.equal(actual.remoteContent, remoteContent);
"a": 2, assert.ok(actual.hasConflicts);
======= assert.deepEqual(actual.conflictsSettings, expectedConflicts);
>>>>>>> remote
"b": 2
}`);
}); });
test('merge with single entry and local is empty', async () => { test('merge with single entry and local is empty', async () => {
...@@ -322,15 +309,10 @@ suite('SettingsMerge - Conflicts', () => { ...@@ -322,15 +309,10 @@ suite('SettingsMerge - Conflicts', () => {
}); });
const expectedConflicts: IConflictSetting[] = [{ key: 'a', localValue: undefined, remoteValue: 2 }]; const expectedConflicts: IConflictSetting[] = [{ key: 'a', localValue: undefined, remoteValue: 2 }];
const actual = merge(localContent, remoteContent, baseContent, [], [], formattingOptions); const actual = merge(localContent, remoteContent, baseContent, [], [], formattingOptions);
assert.ok(actual.hasChanges); assert.equal(actual.localContent, localContent);
assert.deepEqual(actual.conflicts, expectedConflicts); assert.equal(actual.remoteContent, remoteContent);
assert.equal(actual.mergeContent, assert.ok(actual.hasConflicts);
`{ assert.deepEqual(actual.conflictsSettings, expectedConflicts);
<<<<<<< local
=======
"a": 2,
>>>>>>> remote
}`);
}); });
test('merge when local and remote has moved forwareded with conflicts', async () => { test('merge when local and remote has moved forwareded with conflicts', async () => {
...@@ -356,38 +338,29 @@ suite('SettingsMerge - Conflicts', () => { ...@@ -356,38 +338,29 @@ suite('SettingsMerge - Conflicts', () => {
const expectedConflicts: IConflictSetting[] = [ const expectedConflicts: IConflictSetting[] = [
{ key: 'b', localValue: undefined, remoteValue: 3 }, { key: 'b', localValue: undefined, remoteValue: 3 },
{ key: 'a', localValue: 2, remoteValue: undefined }, { key: 'a', localValue: 2, remoteValue: undefined },
{ key: 'e', localValue: 4, remoteValue: 5 },
{ key: 'd', localValue: 5, remoteValue: 6 }, { key: 'd', localValue: 5, remoteValue: 6 },
{ key: 'e', localValue: 4, remoteValue: 5 },
]; ];
const actual = merge(localContent, remoteContent, baseContent, [], [], formattingOptions); const actual = merge(localContent, remoteContent, baseContent, [], [], formattingOptions);
assert.ok(actual.hasChanges); assert.equal(actual.localContent, stringify({
assert.deepEqual(actual.conflicts, expectedConflicts); 'a': 2,
assert.equal(actual.mergeContent, 'c': 3,
`{ 'd': 5,
<<<<<<< local 'e': 4,
"a": 2, 'f': 1,
======= }));
>>>>>>> remote assert.equal(actual.remoteContent, stringify({
"c": 3, 'b': 3,
<<<<<<< local 'c': 3,
"d": 5, 'd': 6,
======= 'e': 5,
"d": 6, 'f': 1,
>>>>>>> remote }));
<<<<<<< local assert.ok(actual.hasConflicts);
"e": 4, assert.deepEqual(actual.conflictsSettings, expectedConflicts);
=======
"e": 5,
>>>>>>> remote
"f": 1
<<<<<<< local
=======
"b": 3,
>>>>>>> remote
}`);
}); });
test('resolve when local and remote has moved forwareded with conflicts', async () => { test('resolve when local and remote has moved forwareded with resolved conflicts', async () => {
const baseContent = stringify({ const baseContent = stringify({
'a': 1, 'a': 1,
'b': 2, 'b': 2,
...@@ -411,27 +384,24 @@ suite('SettingsMerge - Conflicts', () => { ...@@ -411,27 +384,24 @@ suite('SettingsMerge - Conflicts', () => {
{ key: 'd', localValue: 5, remoteValue: 6 }, { key: 'd', localValue: 5, remoteValue: 6 },
]; ];
const actual = merge(localContent, remoteContent, baseContent, [], [{ key: 'a', value: 2 }, { key: 'b', value: undefined }, { key: 'e', value: 5 }], formattingOptions); const actual = merge(localContent, remoteContent, baseContent, [], [{ key: 'a', value: 2 }, { key: 'b', value: undefined }, { key: 'e', value: 5 }], formattingOptions);
assert.ok(actual.hasChanges); assert.equal(actual.localContent, stringify({
assert.deepEqual(actual.conflicts, expectedConflicts); 'a': 2,
assert.equal(actual.mergeContent, 'c': 3,
`{ 'd': 5,
"a": 2, 'e': 5,
"c": 3, 'f': 1,
<<<<<<< local }));
"d": 5, assert.equal(actual.remoteContent, stringify({
======= 'c': 3,
"d": 6, 'd': 6,
>>>>>>> remote 'e': 5,
"e": 5, 'f': 1,
"f": 1 'a': 2,
}`); }));
assert.ok(actual.hasConflicts);
assert.deepEqual(actual.conflictsSettings, expectedConflicts);
}); });
});
*/
suite('SettingsMerge - Ignored Settings', () => {
test('ignored setting is not merged when changed in local and remote', async () => { test('ignored setting is not merged when changed in local and remote', async () => {
const localContent = stringify({ 'a': 1 }); const localContent = stringify({ 'a': 1 });
const remoteContent = stringify({ 'a': 2 }); const remoteContent = stringify({ 'a': 2 });
...@@ -448,7 +418,7 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -448,7 +418,7 @@ suite('SettingsMerge - Ignored Settings', () => {
const remoteContent = stringify({ 'a': 2 }); const remoteContent = stringify({ 'a': 2 });
const actual = merge(localContent, remoteContent, baseContent, ['a'], [], formattingOptions); const actual = merge(localContent, remoteContent, baseContent, ['a'], [], formattingOptions);
assert.equal(actual.localContent, null); assert.equal(actual.localContent, null);
assert.equal(actual.remoteContent, localContent); assert.equal(actual.remoteContent, null);
assert.equal(actual.conflictsSettings.length, 0); assert.equal(actual.conflictsSettings.length, 0);
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
...@@ -458,7 +428,7 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -458,7 +428,7 @@ suite('SettingsMerge - Ignored Settings', () => {
const remoteContent = stringify({ 'a': 1 }); const remoteContent = stringify({ 'a': 1 });
const actual = merge(localContent, remoteContent, null, ['a'], [], formattingOptions); const actual = merge(localContent, remoteContent, null, ['a'], [], formattingOptions);
assert.equal(actual.localContent, null); assert.equal(actual.localContent, null);
assert.equal(actual.remoteContent, localContent); assert.equal(actual.remoteContent, null);
assert.equal(actual.conflictsSettings.length, 0); assert.equal(actual.conflictsSettings.length, 0);
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
...@@ -468,7 +438,7 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -468,7 +438,7 @@ suite('SettingsMerge - Ignored Settings', () => {
const remoteContent = stringify({ 'a': 1, 'b': 2 }); const remoteContent = stringify({ 'a': 1, 'b': 2 });
const actual = merge(localContent, remoteContent, localContent, ['a'], [], formattingOptions); const actual = merge(localContent, remoteContent, localContent, ['a'], [], formattingOptions);
assert.equal(actual.localContent, null); assert.equal(actual.localContent, null);
assert.equal(actual.remoteContent, localContent); assert.equal(actual.remoteContent, null);
assert.equal(actual.conflictsSettings.length, 0); assert.equal(actual.conflictsSettings.length, 0);
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
...@@ -478,7 +448,7 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -478,7 +448,7 @@ suite('SettingsMerge - Ignored Settings', () => {
const remoteContent = stringify({}); const remoteContent = stringify({});
const actual = merge(localContent, remoteContent, null, ['a'], [], formattingOptions); const actual = merge(localContent, remoteContent, null, ['a'], [], formattingOptions);
assert.equal(actual.localContent, null); assert.equal(actual.localContent, null);
assert.equal(actual.remoteContent, localContent); assert.equal(actual.remoteContent, null);
assert.equal(actual.conflictsSettings.length, 0); assert.equal(actual.conflictsSettings.length, 0);
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
...@@ -488,7 +458,7 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -488,7 +458,7 @@ suite('SettingsMerge - Ignored Settings', () => {
const remoteContent = stringify({}); const remoteContent = stringify({});
const actual = merge(localContent, remoteContent, localContent, ['a'], [], formattingOptions); const actual = merge(localContent, remoteContent, localContent, ['a'], [], formattingOptions);
assert.equal(actual.localContent, null); assert.equal(actual.localContent, null);
assert.equal(actual.remoteContent, localContent); assert.equal(actual.remoteContent, null);
assert.equal(actual.conflictsSettings.length, 0); assert.equal(actual.conflictsSettings.length, 0);
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
...@@ -512,18 +482,21 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -512,18 +482,21 @@ suite('SettingsMerge - Ignored Settings', () => {
'd': 4, 'd': 4,
'e': 6, 'e': 6,
}); });
const expectedContent = stringify({ const actual = merge(localContent, remoteContent, baseContent, ['a', 'e'], [], formattingOptions);
assert.equal(actual.localContent, stringify({
'a': 1, 'a': 1,
'b': 3, 'b': 3,
}); }));
const actual = merge(localContent, remoteContent, baseContent, ['a', 'e'], [], formattingOptions); assert.equal(actual.remoteContent, stringify({
assert.equal(actual.localContent, expectedContent); 'a': 3,
assert.equal(actual.remoteContent, expectedContent); 'b': 3,
'e': 6,
}));
assert.equal(actual.conflictsSettings.length, 0); assert.equal(actual.conflictsSettings.length, 0);
assert.ok(!actual.hasConflicts); assert.ok(!actual.hasConflicts);
}); });
/* test('ignored setting is not merged with other changes conflicts', async () => { test('ignored setting is not merged with other changes conflicts', async () => {
const baseContent = stringify({ const baseContent = stringify({
'a': 2, 'a': 2,
'b': 2, 'b': 2,
...@@ -547,24 +520,19 @@ suite('SettingsMerge - Ignored Settings', () => { ...@@ -547,24 +520,19 @@ suite('SettingsMerge - Ignored Settings', () => {
{ key: 'b', localValue: 4, remoteValue: 3 }, { key: 'b', localValue: 4, remoteValue: 3 },
]; ];
const actual = merge(localContent, remoteContent, baseContent, ['a', 'e'], [], formattingOptions); const actual = merge(localContent, remoteContent, baseContent, ['a', 'e'], [], formattingOptions);
assert.ok(actual.hasChanges); assert.equal(actual.localContent, stringify({
assert.ok(actual.hasChanges); 'a': 1,
assert.deepEqual(actual.conflicts, expectedConflicts); 'b': 4,
assert.equal(actual.mergeContent, 'd': 5,
`{ }));
"a": 1, assert.equal(actual.remoteContent, stringify({
<<<<<<< local 'a': 3,
"b": 4, 'b': 3,
======= 'e': 6,
"b": 3, }));
>>>>>>> remote assert.deepEqual(actual.conflictsSettings, expectedConflicts);
<<<<<<< local assert.ok(actual.hasConflicts);
"d": 5 });
=======
>>>>>>> remote
}`);
}); */
}); });
suite('SettingsMerge - Compute Remote Content', () => { suite('SettingsMerge - Compute Remote Content', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册