本文整理汇总了TypeScript中fp-ts/lib/Option.some函数的典型用法代码示例。如果您正苦于以下问题:TypeScript some函数的具体用法?TypeScript some怎么用?TypeScript some使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了some函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createDecoration
private async createDecoration(currentDecoration: Decoration, item: DecorationUpdateActionQuickPickItem): Promise<Option<Decoration>> {
this.telemetryReporter.logHighlightUpdated(item.actionId);
switch (item.actionId) {
case DecorationAction.TOGGLE_CASE_SENSITIVITY:
return some(currentDecoration.withCaseSensitivityToggled());
case DecorationAction.TOGGLE_WHOLE_MATCH:
return some(currentDecoration.withWholeMatchToggled());
case DecorationAction.UPDATE_PHRASE: {
const options = {
value: currentDecoration.pattern.phrase,
prompt: 'Enter a new pattern.'
};
const newPhraseOpt = await this.windowComponent.showInputBox(options);
return newPhraseOpt.map(newPhrase => currentDecoration.withPhrase(newPhrase));
}
case DecorationAction.UPDATE_COLOUR: {
const options = {
value: currentDecoration.colour,
prompt: 'Enter a new color.'
};
const newPhraseOpt = await this.windowComponent.showInputBox(options);
return newPhraseOpt.map(newColour => currentDecoration.withColour(newColour));
}
}
}
示例2: test
test('it deregisters a decoration id and their positions', () => {
const decorationId = registry.queryDecorationId('EDITOR_ID', range(1, 1));
assert.deepEqual(decorationId, some('DECORATION_ID'));
registry.deregister('DECORATION_ID');
const decorationId2 = registry.queryDecorationId('EDITOR_ID', range(1, 1));
assert.deepEqual(decorationId2, none);
});
示例3: test
test('it lets user to select which level they want to save a config', async () => {
const windowComponent = mock(WindowComponent);
when(windowComponent.showQuickPick(
[{
label: 'Global',
value: true
}, {
label: 'Workspace',
value: false
}],
{placeHolder: 'Select which scope of settings to save highlights to'}
)).thenResolve(some({label: 'Global', value: true}));
const picker = new ConfigTargetPicker(windowComponent);
assert.deepEqual(await picker.pick(), some(true));
});
示例4: test
test('it registers a pattern and returns registry information', () => {
const registry = createDecorationRegistry();
const pattern = createPattern('PATTERN');
assert.deepEqual(registry.issue(pattern), some({
id: 'UUID_1',
colour: pink,
pattern
}));
});
示例5: test
test('it lets user to pick a highlight pattern', async () => {
const windowComponent = mock(WindowComponent);
when(windowComponent.showQuickPick(
[
{label: 'TEXT_1', detail: 'String', decoration: decoration1},
{label: '/TEXT_2/i', detail: 'RegExp', decoration: decoration2}
],
{placeHolder: 'PLACEHOLDER_MESSAGE'}
)).thenResolve(some({
label: 'TEXT_1', detail: 'String', decoration: decoration1
}));
const decorationRegistry = mock(DecorationRegistry);
when(decorationRegistry.retrieveAll()).thenReturn([decoration1, decoration2]);
const picker = new DecorationPicker(decorationRegistry, windowComponent);
const decoration = await picker.pick('PLACEHOLDER_MESSAGE');
assert.deepEqual(decoration, some(decoration1));
});
示例6: test
test('it removes a decoration', () => {
const decorationRegistry = mock(DecorationRegistry);
when(decorationRegistry.inquireById('DECORATION_ID')).thenReturn(some(decoration));
const textDecorator = mock(TextDecorator);
const operator = new DecorationOperator(editors, decorationRegistry, textDecorator);
operator.removeDecoration('DECORATION_ID');
verify(decorationRegistry.revoke('DECORATION_ID'));
verify(textDecorator.undecorate(editors, ['DECORATION_ID']));
});
示例7: setup
setup(() => {
extensionConfig = mockMethods<vscode.WorkspaceConfiguration>(['get', 'update']);
when(extensionConfig.get('CONFIG_NAME')).thenReturn('CONFIG_VALUE');
const workspace = mockMethods<typeof vscode.workspace>(['getConfiguration']);
when(workspace.getConfiguration('textmarker')).thenReturn(extensionConfig);
const configTargetPicker = mock(ConfigurationTargetPicker);
when(configTargetPicker.pick()).thenResolve(some('CONFIG_TARGET'));
configStore = new ConfigStore(workspace, configTargetPicker);
});
示例8: suite
suite('When the cursor is on highlight', () => {
const editor = mockType<TextEditor>({id: 'EDITOR_ID', selectedText: 'SELECTED', selection: registeredRange});
const pattern = mock(StringPattern);
const oldDecoration = new Decoration('DECORATION_ID', pattern, 'pink');
const newDecoration = new Decoration('DECORATION_ID', pattern, 'yellow');
const decorationRegistry = mock(DecorationRegistry);
when(decorationRegistry.inquireById('DECORATION_ID')).thenReturn(some(oldDecoration));
let decorationOperator: DecorationOperator;
let decorationOperatorFactory: DecorationOperatorFactory;
setup(() => {
const deps = createDecorationOperator();
decorationOperator = deps.decorationOperator;
decorationOperatorFactory = deps.decorationOperatorFactory;
});
test('it updates decoration', async () => {
const patternVariationReader = mock(DecorationVariationReader);
when(patternVariationReader.read(oldDecoration)).thenResolve(some(newDecoration));
const command = new UpdateHighlightCommand(
decorationOperatorFactory,
decorationRegistry,
patternVariationReader,
textLocationRegistry
);
await command.execute(editor);
verify(decorationOperator.updateDecoration(oldDecoration, newDecoration));
});
test('it does nothing if a new pattern is not given by user', async () => {
const patternVariationReader = mock(DecorationVariationReader);
when(patternVariationReader.read(any())).thenResolve(none);
const command = new UpdateHighlightCommand(
decorationOperatorFactory,
decorationRegistry,
patternVariationReader,
textLocationRegistry
);
await command.execute(editor);
verify(decorationOperator.updateDecoration(any(), any()), {times: 0});
});
});