-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow variable names with underscores (#162208)
Closes #162205 ## Summary With this PR, users will be able to define variables with names containing underscores (`_`) like the below picture. ![image](https://github.com/elastic/kibana/assets/721858/d6aa0b4c-0c12-4fe7-ab3f-da0aa5cc8862) ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
db42331
commit 92db0d3
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/plugins/console/public/application/components/variables/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { isValidVariableName } from './utils'; | ||
|
||
describe('utils', () => { | ||
describe('isValidVariableName', () => { | ||
it('returns `false` to `null`', () => { | ||
// @ts-ignore passing a wrong type intentionally | ||
expect(isValidVariableName(null)).toBe(false); | ||
}); | ||
|
||
it('returns `false` to empty string', () => { | ||
expect(isValidVariableName('')).toBe(false); | ||
}); | ||
|
||
it('returns `false` to space string', () => { | ||
expect(isValidVariableName(' ')).toBe(false); | ||
}); | ||
|
||
it('returns `false` to integer zero', () => { | ||
// @ts-ignore passing a wrong type intentionally | ||
expect(isValidVariableName(0)).toBe(false); | ||
}); | ||
|
||
it('returns `false` to float zero', () => { | ||
// @ts-ignore passing a wrong type intentionally | ||
expect(isValidVariableName(0.0)).toBe(false); | ||
}); | ||
|
||
it('returns `true` to string zero', () => { | ||
expect(isValidVariableName('0')).toBe(true); | ||
}); | ||
|
||
it('returns `true` to allowed styles', () => { | ||
for (const name of ['camelCase', 'snake_case', 'PascalCase', 'MACRO_CASE']) { | ||
expect(isValidVariableName(name)).toBe(true); | ||
} | ||
}); | ||
|
||
it('returns `false` to disallowed styles', () => { | ||
for (const name of ['kebab-case', 'COBOL-CASE', 'dot.notation', 'bracket[notation]']) { | ||
expect(isValidVariableName(name)).toBe(false); | ||
} | ||
}); | ||
|
||
it('returns `true` to underscores prefix & suffix', () => { | ||
expect(isValidVariableName('__name__')).toBe(true); | ||
}); | ||
|
||
it('returns `true` to numbers prefix & suffix', () => { | ||
expect(isValidVariableName('00name00')).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters