mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-02 08:15:56 +01:00
Add tests for contextMatchesRules and IOSupport.readKeybindingContexts
This commit is contained in:
committed by
Johannes Rieken
parent
2a6a00aafd
commit
53e7e0d8ae
@@ -13,10 +13,7 @@ import lifecycle = require('vs/base/common/lifecycle');
|
||||
import DOM = require('vs/base/browser/dom');
|
||||
import Keyboard = require('vs/base/browser/keyboardEvent');
|
||||
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import {KeybindingsUtils} from 'vs/platform/keybinding/common/keybindingsUtils';
|
||||
import strings = require('vs/base/common/strings');
|
||||
import Platform = require('vs/base/common/platform');
|
||||
import {IKeybindingService, IKeybindingScopeLocation, ICommandHandler, IKeybindingItem, IKeybindings, IKeybindingContextRule, IUserFriendlyKeybinding, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybindingService';
|
||||
import {IKeybindingService, IKeybindingScopeLocation, ICommandHandler, IKeybindingItem, IKeybindings, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybindingService';
|
||||
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {IMessageService} from 'vs/platform/message/common/message';
|
||||
import {IResolveResult, CommonKeybindingResolver} from 'vs/platform/keybinding/common/commonKeybindingResolver';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
import assert = require('assert');
|
||||
import {CommonKeybindingResolver} from 'vs/platform/keybinding/common/commonKeybindingResolver';
|
||||
import {CommonKeybindingResolver, IOSupport} from 'vs/platform/keybinding/common/commonKeybindingResolver';
|
||||
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import {KeybindingsUtils} from 'vs/platform/keybinding/common/keybindingsUtils';
|
||||
import Platform = require('vs/base/common/platform');
|
||||
@@ -305,7 +305,55 @@ suite('Keybinding Service', () => {
|
||||
testResolve({}, KeyMod.CtrlCmd | KeyCode.KEY_G, 'eleven');
|
||||
|
||||
testKey('sixth', []);
|
||||
});
|
||||
|
||||
test('contextMatchesRules', function () {
|
||||
function testExpression(expr:string, expected:boolean): void {
|
||||
let rules = IOSupport.readKeybindingContexts(expr);
|
||||
assert.equal(CommonKeybindingResolver.contextMatchesRules(context, rules), expected, expr);
|
||||
}
|
||||
let context = {
|
||||
'a': true,
|
||||
'b': false,
|
||||
'c': '5'
|
||||
};
|
||||
|
||||
testExpression('', true);
|
||||
|
||||
testExpression('a', true);
|
||||
testExpression('a == true', true == true);
|
||||
testExpression('a != true', true != true);
|
||||
testExpression('a == false', true == false);
|
||||
testExpression('a != false', true != false);
|
||||
testExpression('a == 5', true == <any>'5');
|
||||
testExpression('a != 5', true != <any>'5');
|
||||
testExpression('!a', !true);
|
||||
|
||||
testExpression('b', false);
|
||||
testExpression('b == true', false == true);
|
||||
testExpression('b != true', false != true);
|
||||
testExpression('b == false', false == false);
|
||||
testExpression('b != false', false != false);
|
||||
testExpression('b == 5', false == <any>'5');
|
||||
testExpression('b != 5', false != <any>'5');
|
||||
testExpression('!b', !false);
|
||||
|
||||
// testExpression('c', <any>'5');
|
||||
testExpression('c == true', <any>'5' == true);
|
||||
testExpression('c != true', <any>'5' != true);
|
||||
testExpression('c == false', <any>'5' == false);
|
||||
testExpression('c != false', <any>'5' != false);
|
||||
testExpression('c == 5', '5' == '5');
|
||||
testExpression('c != 5', '5' != '5');
|
||||
// testExpression('!c', !'5');
|
||||
|
||||
// testExpression('z', undefined);
|
||||
testExpression('z == true', undefined == true);
|
||||
testExpression('z != true', undefined != true);
|
||||
// testExpression('z == false', undefined == false);
|
||||
testExpression('z != false', undefined != false);
|
||||
testExpression('z == 5', undefined == <any>'5');
|
||||
testExpression('z != 5', undefined != <any>'5');
|
||||
testExpression('!z', !undefined);
|
||||
});
|
||||
});
|
||||
|
||||
20
test/all.js
20
test/all.js
@@ -178,16 +178,18 @@ function main() {
|
||||
});
|
||||
|
||||
// replace the default unexpected error handler to be useful during tests
|
||||
loader('vs/base/common/errors').setUnexpectedErrorHandler(function (err) {
|
||||
try {
|
||||
throw new Error('oops');
|
||||
} catch (e) {
|
||||
unexpectedErrors.push((err && err.message ? err.message : err) + '\n' + e.stack);
|
||||
}
|
||||
});
|
||||
loader(['vs/base/common/errors'], function(errors) {
|
||||
errors.setUnexpectedErrorHandler(function (err) {
|
||||
try {
|
||||
throw new Error('oops');
|
||||
} catch (e) {
|
||||
unexpectedErrors.push((err && err.message ? err.message : err) + '\n' + e.stack);
|
||||
}
|
||||
});
|
||||
|
||||
// fire up mocha
|
||||
run();
|
||||
// fire up mocha
|
||||
run();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user