mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 02:48:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ConfigurationModel, merge } from 'vs/platform/configuration/common/configuration';
|
||||
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
||||
suite('Configuration', () => {
|
||||
|
||||
suiteSetup(() => {
|
||||
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
|
||||
'id': 'a',
|
||||
'order': 1,
|
||||
'title': 'a',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'a': {
|
||||
'description': 'a',
|
||||
'type': 'boolean',
|
||||
'default': true,
|
||||
'overridable': true
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('simple merge', () => {
|
||||
let base = { 'a': 1, 'b': 2 };
|
||||
merge(base, { 'a': 3, 'c': 4 }, true);
|
||||
assert.deepEqual(base, { 'a': 3, 'b': 2, 'c': 4 });
|
||||
base = { 'a': 1, 'b': 2 };
|
||||
merge(base, { 'a': 3, 'c': 4 }, false);
|
||||
assert.deepEqual(base, { 'a': 1, 'b': 2, 'c': 4 });
|
||||
});
|
||||
|
||||
test('Recursive merge', () => {
|
||||
const base = { 'a': { 'b': 1 } };
|
||||
merge(base, { 'a': { 'b': 2 } }, true);
|
||||
assert.deepEqual(base, { 'a': { 'b': 2 } });
|
||||
});
|
||||
|
||||
test('simple merge using configuration', () => {
|
||||
let base = new ConfigurationModel<any>({ 'a': 1, 'b': 2 });
|
||||
let add = new ConfigurationModel<any>({ 'a': 3, 'c': 4 });
|
||||
let result = base.merge(add);
|
||||
assert.deepEqual(result.contents, { 'a': 3, 'b': 2, 'c': 4 });
|
||||
});
|
||||
|
||||
test('Recursive merge using config models', () => {
|
||||
let base = new ConfigurationModel({ 'a': { 'b': 1 } });
|
||||
let add = new ConfigurationModel({ 'a': { 'b': 2 } });
|
||||
let result = base.merge(add);
|
||||
assert.deepEqual(result.contents, { 'a': { 'b': 2 } });
|
||||
});
|
||||
|
||||
test('Test contents while getting an existing property', () => {
|
||||
let testObject = new ConfigurationModel({ 'a': 1 });
|
||||
assert.deepEqual(testObject.getContentsFor('a'), 1);
|
||||
|
||||
testObject = new ConfigurationModel<any>({ 'a': { 'b': 1 } });
|
||||
assert.deepEqual(testObject.getContentsFor('a'), { 'b': 1 });
|
||||
});
|
||||
|
||||
test('Test contents are undefined for non existing properties', () => {
|
||||
const testObject = new ConfigurationModel({ awesome: true });
|
||||
|
||||
assert.deepEqual(testObject.getContentsFor('unknownproperty'), undefined);
|
||||
});
|
||||
|
||||
test('Test override gives all content merged with overrides', () => {
|
||||
const testObject = new ConfigurationModel<any>({ 'a': 1, 'c': 1 }, [], [{ identifiers: ['b'], contents: { 'a': 2 } }]);
|
||||
|
||||
assert.deepEqual(testObject.override('b').contents, { 'a': 2, 'c': 1 });
|
||||
});
|
||||
});
|
||||
148
src/vs/platform/configuration/test/common/model.test.ts
Normal file
148
src/vs/platform/configuration/test/common/model.test.ts
Normal file
@@ -0,0 +1,148 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { CustomConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/model';
|
||||
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
||||
suite('Configuration', () => {
|
||||
|
||||
suiteSetup(() => {
|
||||
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
|
||||
'id': 'a',
|
||||
'order': 1,
|
||||
'title': 'a',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'a': {
|
||||
'description': 'a',
|
||||
'type': 'boolean',
|
||||
'default': true,
|
||||
'overridable': true
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('simple merge using models', () => {
|
||||
let base = new CustomConfigurationModel(JSON.stringify({ 'a': 1, 'b': 2 }));
|
||||
let add = new CustomConfigurationModel(JSON.stringify({ 'a': 3, 'c': 4 }));
|
||||
let result = base.merge(add);
|
||||
assert.deepEqual(result.contents, { 'a': 3, 'b': 2, 'c': 4 });
|
||||
});
|
||||
|
||||
test('simple merge with an undefined contents', () => {
|
||||
let base = new CustomConfigurationModel(JSON.stringify({ 'a': 1, 'b': 2 }));
|
||||
let add = new CustomConfigurationModel(null);
|
||||
let result = base.merge(add);
|
||||
assert.deepEqual(result.contents, { 'a': 1, 'b': 2 });
|
||||
|
||||
base = new CustomConfigurationModel(null);
|
||||
add = new CustomConfigurationModel(JSON.stringify({ 'a': 1, 'b': 2 }));
|
||||
result = base.merge(add);
|
||||
assert.deepEqual(result.contents, { 'a': 1, 'b': 2 });
|
||||
|
||||
base = new CustomConfigurationModel(null);
|
||||
add = new CustomConfigurationModel(null);
|
||||
result = base.merge(add);
|
||||
assert.deepEqual(result.contents, {});
|
||||
});
|
||||
|
||||
test('Recursive merge using config models', () => {
|
||||
let base = new CustomConfigurationModel(JSON.stringify({ 'a': { 'b': 1 } }));
|
||||
let add = new CustomConfigurationModel(JSON.stringify({ 'a': { 'b': 2 } }));
|
||||
let result = base.merge(add);
|
||||
assert.deepEqual(result.contents, { 'a': { 'b': 2 } });
|
||||
});
|
||||
|
||||
test('Test contents while getting an existing property', () => {
|
||||
let testObject = new CustomConfigurationModel(JSON.stringify({ 'a': 1 }));
|
||||
assert.deepEqual(testObject.getContentsFor('a'), 1);
|
||||
|
||||
testObject = new CustomConfigurationModel(JSON.stringify({ 'a': { 'b': 1 } }));
|
||||
assert.deepEqual(testObject.getContentsFor('a'), { 'b': 1 });
|
||||
});
|
||||
|
||||
test('Test contents are undefined for non existing properties', () => {
|
||||
const testObject = new CustomConfigurationModel(JSON.stringify({
|
||||
awesome: true
|
||||
}));
|
||||
|
||||
assert.deepEqual(testObject.getContentsFor('unknownproperty'), undefined);
|
||||
});
|
||||
|
||||
test('Test contents are undefined for undefined config', () => {
|
||||
const testObject = new CustomConfigurationModel(null);
|
||||
|
||||
assert.deepEqual(testObject.getContentsFor('unknownproperty'), undefined);
|
||||
});
|
||||
|
||||
test('Test configWithOverrides gives all content merged with overrides', () => {
|
||||
const testObject = new CustomConfigurationModel(JSON.stringify({ 'a': 1, 'c': 1, '[b]': { 'a': 2 } }));
|
||||
|
||||
assert.deepEqual(testObject.override('b').contents, { 'a': 2, 'c': 1, '[b]': { 'a': 2 } });
|
||||
});
|
||||
|
||||
test('Test configWithOverrides gives empty contents', () => {
|
||||
const testObject = new CustomConfigurationModel(null);
|
||||
|
||||
assert.deepEqual(testObject.override('b').contents, {});
|
||||
});
|
||||
|
||||
test('Test update with empty data', () => {
|
||||
const testObject = new CustomConfigurationModel();
|
||||
testObject.update('');
|
||||
|
||||
assert.deepEqual(testObject.contents, {});
|
||||
assert.deepEqual(testObject.keys, []);
|
||||
|
||||
testObject.update(null);
|
||||
|
||||
assert.deepEqual(testObject.contents, {});
|
||||
assert.deepEqual(testObject.keys, []);
|
||||
|
||||
testObject.update(undefined);
|
||||
|
||||
assert.deepEqual(testObject.contents, {});
|
||||
assert.deepEqual(testObject.keys, []);
|
||||
});
|
||||
|
||||
test('Test registering the same property again', () => {
|
||||
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
|
||||
'id': 'a',
|
||||
'order': 1,
|
||||
'title': 'a',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'a': {
|
||||
'description': 'a',
|
||||
'type': 'boolean',
|
||||
'default': false,
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(true, new DefaultConfigurationModel().getContentsFor('a'));
|
||||
});
|
||||
|
||||
test('Test registering the language property', () => {
|
||||
Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({
|
||||
'id': '[a]',
|
||||
'order': 1,
|
||||
'title': 'a',
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'[a]': {
|
||||
'description': 'a',
|
||||
'type': 'boolean',
|
||||
'default': false,
|
||||
}
|
||||
}
|
||||
});
|
||||
assert.equal(undefined, new DefaultConfigurationModel().getContentsFor('[a]'));
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { TrieMap } from 'vs/base/common/map';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { EventEmitter } from 'vs/base/common/eventEmitter';
|
||||
import { getConfigurationKeys } from 'vs/platform/configuration/common/model';
|
||||
import { IConfigurationOverrides, IConfigurationService, getConfigurationValue, IConfigurationValue, IConfigurationKeys, IConfigurationValues, IConfigurationData, Configuration, ConfigurationModel } from 'vs/platform/configuration/common/configuration';
|
||||
|
||||
export class TestConfigurationService extends EventEmitter implements IConfigurationService {
|
||||
public _serviceBrand: any;
|
||||
|
||||
private configuration = Object.create(null);
|
||||
|
||||
private configurationByRoot: TrieMap<any> = new TrieMap<any>();
|
||||
|
||||
public reloadConfiguration<T>(section?: string): TPromise<T> {
|
||||
return TPromise.as(this.getConfiguration());
|
||||
}
|
||||
|
||||
public getConfiguration(section?: string, overrides?: IConfigurationOverrides): any {
|
||||
if (overrides && overrides.resource) {
|
||||
const configForResource = this.configurationByRoot.findSubstr(overrides.resource.fsPath);
|
||||
return configForResource || this.configuration;
|
||||
}
|
||||
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
public getConfigurationData(): IConfigurationData<any> {
|
||||
return new Configuration(new ConfigurationModel(), new ConfigurationModel(this.configuration)).toData();
|
||||
}
|
||||
|
||||
public setUserConfiguration(key: any, value: any, root?: URI): Thenable<void> {
|
||||
if (root) {
|
||||
const configForRoot = this.configurationByRoot.lookUp(root.fsPath) || Object.create(null);
|
||||
configForRoot[key] = value;
|
||||
this.configurationByRoot.insert(root.fsPath, configForRoot);
|
||||
} else {
|
||||
this.configuration[key] = value;
|
||||
}
|
||||
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
public onDidUpdateConfiguration() {
|
||||
return { dispose() { } };
|
||||
}
|
||||
|
||||
public lookup<C>(key: string, overrides?: IConfigurationOverrides): IConfigurationValue<C> {
|
||||
const config = this.getConfiguration(undefined, overrides);
|
||||
|
||||
return {
|
||||
value: getConfigurationValue<C>(config, key),
|
||||
default: getConfigurationValue<C>(config, key),
|
||||
user: getConfigurationValue<C>(config, key),
|
||||
workspace: null,
|
||||
folder: null
|
||||
};
|
||||
}
|
||||
|
||||
public keys(): IConfigurationKeys {
|
||||
return {
|
||||
default: getConfigurationKeys(),
|
||||
user: Object.keys(this.configuration),
|
||||
workspace: [],
|
||||
folder: []
|
||||
};
|
||||
}
|
||||
|
||||
public values(): IConfigurationValues {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user