mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-03 08:31:02 +01:00
Add tests for durationWithUnitRegexp functionality
Added tests for durationWithUnitRegexp to validate matching of complete durations with units and ensure non-matching cases are correctly identified. Signed-off-by: ADITYA TIWARI <142050150+ADITYATIWARI342005@users.noreply.github.com>
This commit is contained in:
parent
bf76fde0c8
commit
137f846527
@ -11,7 +11,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { analyzeCompletion, computeStartCompletePosition, ContextKind } from './hybrid';
|
import { analyzeCompletion, computeStartCompletePosition, ContextKind, durationWithUnitRegexp } from './hybrid';
|
||||||
import { createEditorState, mockedMetricsTerms, mockPrometheusServer } from '../test/utils-test';
|
import { createEditorState, mockedMetricsTerms, mockPrometheusServer } from '../test/utils-test';
|
||||||
import { Completion, CompletionContext } from '@codemirror/autocomplete';
|
import { Completion, CompletionContext } from '@codemirror/autocomplete';
|
||||||
import {
|
import {
|
||||||
@ -642,6 +642,32 @@ describe('analyzeCompletion test', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('durationWithUnitRegexp test', () => {
|
||||||
|
it('should match complete durations with units', () => {
|
||||||
|
const testCases = [
|
||||||
|
{ input: '5m', expected: true },
|
||||||
|
{ input: '30s', expected: true },
|
||||||
|
{ input: '1h', expected: true },
|
||||||
|
{ input: '500ms', expected: true },
|
||||||
|
{ input: '2d', expected: true },
|
||||||
|
{ input: '1w', expected: true },
|
||||||
|
{ input: '1y', expected: true },
|
||||||
|
];
|
||||||
|
|
||||||
|
testCases.forEach(({ input, expected }) => {
|
||||||
|
expect(durationWithUnitRegexp.test(input)).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not match durations without units or partial units', () => {
|
||||||
|
const testCases = ['5', '30', '100', '5m5', 'm', 'd'];
|
||||||
|
|
||||||
|
testCases.forEach((input) => {
|
||||||
|
expect(durationWithUnitRegexp.test(input)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('computeStartCompletePosition test', () => {
|
describe('computeStartCompletePosition test', () => {
|
||||||
const testCases = [
|
const testCases = [
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user