本文整理匯總了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});
});
});