From 910e6144d577e29a70ce982a64f37636ece7b429 Mon Sep 17 00:00:00 2001 From: Zabil Cheriya Maliackal Date: Thu, 10 Oct 2024 17:39:06 +0100 Subject: [PATCH] Simplify logic to exclude empty strings Signed-off-by: Zabil Cheriya Maliackal --- e2e/specs/parameters.spec | 4 ++-- e2e/tests/parameter.ts | 8 +++----- gauge-ts/src/processors/params/PrimitiveParser.ts | 9 ++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec index a748d97..f20f0f2 100644 --- a/e2e/specs/parameters.spec +++ b/e2e/specs/parameters.spec @@ -6,5 +6,5 @@ ## Custom Parameters in steps -* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" -* This step checks if strings with numbers for example "3 % 4" is correct +* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" +* Check strings with numbers for example "3 % 4" is correct diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts index 4c7f1b2..924d28e 100644 --- a/e2e/tests/parameter.ts +++ b/e2e/tests/parameter.ts @@ -8,16 +8,14 @@ export default class Parameter { assert.strictEqual(original.trim(), expected); } - @Step("This step uses a custom parameter of type Person and value ") + @Step("Convert custom parameter of type Person and value ") public async validatePerson(person: Person) { assert.strictEqual(person.name, "John"); assert.strictEqual(person.age, 30); assert.ok(person.isAdult()); } - @Step( - "This step checks if strings with numbers for example is correct", - ) - async setFilter(value: string) { + @Step("Check strings with numbers for example is correct") + async checkStringConversion(value: string) { assert.strictEqual(value, "3 % 4"); } } diff --git a/gauge-ts/src/processors/params/PrimitiveParser.ts b/gauge-ts/src/processors/params/PrimitiveParser.ts index fee797e..cc19c71 100644 --- a/gauge-ts/src/processors/params/PrimitiveParser.ts +++ b/gauge-ts/src/processors/params/PrimitiveParser.ts @@ -27,12 +27,11 @@ export class PrimitiveParser implements ParameterParser { } private convertToNumber(value: string): number | undefined { - const trimmedValue = value.trim(); - if (/^-?\d+(\.\d+)?$/.test(trimmedValue)) { - const num = Number.parseFloat(trimmedValue); - return Number.isFinite(num) ? num : undefined; + if (value.trim() === "") { + return undefined; } - return undefined; + const num = Number(value); + return Number.isFinite(num) ? num : undefined; } private convertToBoolean(value: string): boolean | undefined {